Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
GlobalEditListPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2015 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.keywordsearch;
20 
21 import java.awt.EventQueue;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.beans.PropertyChangeEvent;
25 import java.beans.PropertyChangeListener;
26 import java.io.File;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.List;
30 import java.util.logging.Level;
31 import org.openide.util.NbBundle;
33 import java.util.regex.Pattern;
34 import java.util.regex.PatternSyntaxException;
35 import javax.swing.JFileChooser;
36 import javax.swing.JMenuItem;
37 import javax.swing.JTable;
38 import javax.swing.ListSelectionModel;
39 import javax.swing.event.ListSelectionEvent;
40 import javax.swing.event.ListSelectionListener;
41 import javax.swing.filechooser.FileNameExtensionFilter;
42 import javax.swing.table.AbstractTableModel;
43 import javax.swing.table.TableColumn;
46 
50 class GlobalEditListPanel extends javax.swing.JPanel implements ListSelectionListener, OptionsPanel {
51 
52  private static final Logger logger = Logger.getLogger(GlobalEditListPanel.class.getName());
53  private KeywordTableModel tableModel;
54  private KeywordList currentKeywordList;
55 
59  GlobalEditListPanel() {
60  tableModel = new KeywordTableModel();
61  initComponents();
62  customizeComponents();
63  }
64 
65  private void customizeComponents() {
66  chRegex.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.kwReToolTip"));
67  addWordButton.setToolTipText((NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.addWordToolTip")));
68  addWordField.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.enterNewWordToolTip"));
69  exportButton.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.exportToFile"));
70  saveListButton.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.saveCurrentWIthNewNameToolTip"));
71  deleteWordButton.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.removeSelectedMsg"));
72 
73  keywordTable.setShowHorizontalLines(false);
74  keywordTable.setShowVerticalLines(false);
75  keywordTable.getParent().setBackground(keywordTable.getBackground());
76  final int width = jScrollPane1.getPreferredSize().width;
77  keywordTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
78  TableColumn column;
79  for (int i = 0; i < keywordTable.getColumnCount(); i++) {
80  column = keywordTable.getColumnModel().getColumn(i);
81  if (i == 0) {
82  column.setPreferredWidth(((int) (width * 0.90)));
83  } else {
84  column.setPreferredWidth(((int) (width * 0.10)));
85  //column.setCellRenderer(new CheckBoxRenderer());
86  }
87  }
88  keywordTable.setCellSelectionEnabled(false);
89  keywordTable.setRowSelectionAllowed(true);
90 
91  final ListSelectionModel lsm = keywordTable.getSelectionModel();
92  lsm.addListSelectionListener(new ListSelectionListener() {
93  @Override
94  public void valueChanged(ListSelectionEvent e) {
95  if (lsm.isSelectionEmpty() || currentKeywordList.isLocked() || IngestManager.getInstance().isIngestRunning()) {
96  deleteWordButton.setEnabled(false);
97  } else {
98  deleteWordButton.setEnabled(true);
99  }
100  }
101  });
102 
103  setButtonStates();
104 
105  addWordField.setComponentPopupMenu(rightClickMenu);
106  ActionListener actList = new ActionListener() {
107  @Override
108  public void actionPerformed(ActionEvent e) {
109  JMenuItem jmi = (JMenuItem) e.getSource();
110  if (jmi.equals(cutMenuItem)) {
111  addWordField.cut();
112  } else if (jmi.equals(copyMenuItem)) {
113  addWordField.copy();
114  } else if (jmi.equals(pasteMenuItem)) {
115  addWordField.paste();
116  } else if (jmi.equals(selectAllMenuItem)) {
117  addWordField.selectAll();
118  }
119  }
120  };
121  cutMenuItem.addActionListener(actList);
122  copyMenuItem.addActionListener(actList);
123  pasteMenuItem.addActionListener(actList);
124  selectAllMenuItem.addActionListener(actList);
125 
126  setButtonStates();
127 
128  IngestManager.getInstance().addIngestJobEventListener(new PropertyChangeListener() {
129  @Override
130  public void propertyChange(PropertyChangeEvent evt) {
131  Object source = evt.getSource();
132  if (source instanceof String && ((String) source).equals("LOCAL")) { //NON-NLS
133  EventQueue.invokeLater(new Runnable() {
134  @Override
135  public void run() {
136  setButtonStates();
137  }
138  });
139  }
140  }
141  });
142  }
143 
144  void setButtonStates() {
145  boolean isIngestRunning = IngestManager.getInstance().isIngestRunning();
146  boolean isListSelected = currentKeywordList != null;
147 
148  // items that only need a selected list
149  boolean canEditList = ((isListSelected == true) && (isIngestRunning == false));
150  ingestMessagesCheckbox.setEnabled(canEditList);
151  ingestMessagesCheckbox.setSelected(currentKeywordList != null && currentKeywordList.getIngestMessages());
152  listOptionsLabel.setEnabled(canEditList);
153  listOptionsSeparator.setEnabled(canEditList);
154 
155  // items that need an unlocked list w/out ingest running
156  boolean isListLocked = ((isListSelected == false) || (currentKeywordList.isLocked()));
157  boolean canAddWord = isListSelected && !isIngestRunning && !isListLocked;
158  addWordButton.setEnabled(canAddWord);
159  addWordField.setEnabled(canAddWord);
160  chRegex.setEnabled(canAddWord);
161  keywordOptionsLabel.setEnabled(canAddWord);
162  keywordOptionsSeparator.setEnabled(canAddWord);
163  deleteListButton.setEnabled(canAddWord);
164 
165  // items that need a non-empty list
166  if ((currentKeywordList == null) || (currentKeywordList.getKeywords().isEmpty())) {
167  saveListButton.setEnabled(false);
168  exportButton.setEnabled(false);
169  deleteWordButton.setEnabled(false);
170  } else {
171  saveListButton.setEnabled(true);
172  exportButton.setEnabled(true);
173  // We do not set deleteWordButton because it will be set by the list select model code when a word is selected.
174  }
175  }
176 
182  @SuppressWarnings("unchecked")
183  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
184  private void initComponents() {
185 
186  rightClickMenu = new javax.swing.JPopupMenu();
187  cutMenuItem = new javax.swing.JMenuItem();
188  copyMenuItem = new javax.swing.JMenuItem();
189  pasteMenuItem = new javax.swing.JMenuItem();
190  selectAllMenuItem = new javax.swing.JMenuItem();
191  listEditorPanel = new javax.swing.JPanel();
192  jScrollPane1 = new javax.swing.JScrollPane();
193  keywordTable = new javax.swing.JTable();
194  addKeywordPanel = new javax.swing.JPanel();
195  addWordButton = new javax.swing.JButton();
196  addWordField = new javax.swing.JTextField();
197  chRegex = new javax.swing.JCheckBox();
198  deleteWordButton = new javax.swing.JButton();
199  ingestMessagesCheckbox = new javax.swing.JCheckBox();
200  keywordsLabel = new javax.swing.JLabel();
201  keywordOptionsLabel = new javax.swing.JLabel();
202  listOptionsLabel = new javax.swing.JLabel();
203  keywordOptionsSeparator = new javax.swing.JSeparator();
204  listOptionsSeparator = new javax.swing.JSeparator();
205  deleteListButton = new javax.swing.JButton();
206  saveListButton = new javax.swing.JButton();
207  exportButton = new javax.swing.JButton();
208 
209  cutMenuItem.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.cutMenuItem.text")); // NOI18N
210  rightClickMenu.add(cutMenuItem);
211 
212  copyMenuItem.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.copyMenuItem.text")); // NOI18N
213  rightClickMenu.add(copyMenuItem);
214 
215  pasteMenuItem.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.pasteMenuItem.text")); // NOI18N
216  rightClickMenu.add(pasteMenuItem);
217 
218  selectAllMenuItem.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.selectAllMenuItem.text")); // NOI18N
219  rightClickMenu.add(selectAllMenuItem);
220 
221  jScrollPane1.setPreferredSize(new java.awt.Dimension(340, 300));
222 
223  keywordTable.setModel(tableModel);
224  keywordTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
225  keywordTable.setShowHorizontalLines(false);
226  keywordTable.setShowVerticalLines(false);
227  keywordTable.getTableHeader().setReorderingAllowed(false);
228  jScrollPane1.setViewportView(keywordTable);
229 
230  addWordButton.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.addWordButton.text")); // NOI18N
231  addWordButton.addActionListener(new java.awt.event.ActionListener() {
232  public void actionPerformed(java.awt.event.ActionEvent evt) {
233  addWordButtonActionPerformed(evt);
234  }
235  });
236 
237  addWordField.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.addWordField.text")); // NOI18N
238  addWordField.addActionListener(new java.awt.event.ActionListener() {
239  public void actionPerformed(java.awt.event.ActionEvent evt) {
240  addWordFieldActionPerformed(evt);
241  }
242  });
243 
244  chRegex.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.chRegex.text")); // NOI18N
245 
246  deleteWordButton.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.deleteWordButton.text")); // NOI18N
247  deleteWordButton.addActionListener(new java.awt.event.ActionListener() {
248  public void actionPerformed(java.awt.event.ActionEvent evt) {
249  deleteWordButtonActionPerformed(evt);
250  }
251  });
252 
253  javax.swing.GroupLayout addKeywordPanelLayout = new javax.swing.GroupLayout(addKeywordPanel);
254  addKeywordPanel.setLayout(addKeywordPanelLayout);
255  addKeywordPanelLayout.setHorizontalGroup(
256  addKeywordPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
257  .addGroup(addKeywordPanelLayout.createSequentialGroup()
258  .addGroup(addKeywordPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
259  .addGroup(addKeywordPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
260  .addGroup(addKeywordPanelLayout.createSequentialGroup()
261  .addComponent(addWordField, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
262  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
263  .addComponent(addWordButton))
264  .addComponent(deleteWordButton))
265  .addComponent(chRegex, javax.swing.GroupLayout.Alignment.LEADING))
266  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
267  );
268  addKeywordPanelLayout.setVerticalGroup(
269  addKeywordPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
270  .addGroup(addKeywordPanelLayout.createSequentialGroup()
271  .addGap(0, 0, 0)
272  .addGroup(addKeywordPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
273  .addComponent(addWordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
274  .addComponent(addWordButton))
275  .addGap(7, 7, 7)
276  .addComponent(chRegex)
277  .addGap(7, 7, 7)
278  .addComponent(deleteWordButton)
279  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
280  );
281 
282  ingestMessagesCheckbox.setSelected(true);
283  ingestMessagesCheckbox.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.ingestMessagesCheckbox.text")); // NOI18N
284  ingestMessagesCheckbox.setToolTipText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.ingestMessagesCheckbox.toolTipText")); // NOI18N
285  ingestMessagesCheckbox.addActionListener(new java.awt.event.ActionListener() {
286  public void actionPerformed(java.awt.event.ActionEvent evt) {
287  ingestMessagesCheckboxActionPerformed(evt);
288  }
289  });
290 
291  keywordsLabel.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.keywordsLabel.text")); // NOI18N
292 
293  keywordOptionsLabel.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.keywordOptionsLabel.text")); // NOI18N
294 
295  listOptionsLabel.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.listOptionsLabel.text")); // NOI18N
296 
297  deleteListButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/delete16.png"))); // NOI18N NON-NLS
298  deleteListButton.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.deleteListButton.text")); // NOI18N
299 
300  saveListButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/save16.png"))); // NOI18N NON-NLS
301  saveListButton.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.saveListButton.text")); // NOI18N
302 
303  exportButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/export16.png"))); // NOI18N NON-NLS
304  exportButton.setText(org.openide.util.NbBundle.getMessage(GlobalEditListPanel.class, "KeywordSearchEditListPanel.exportButton.text")); // NOI18N
305  exportButton.addActionListener(new java.awt.event.ActionListener() {
306  public void actionPerformed(java.awt.event.ActionEvent evt) {
307  exportButtonActionPerformed(evt);
308  }
309  });
310 
311  javax.swing.GroupLayout listEditorPanelLayout = new javax.swing.GroupLayout(listEditorPanel);
312  listEditorPanel.setLayout(listEditorPanelLayout);
313  listEditorPanelLayout.setHorizontalGroup(
314  listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
315  .addGroup(listEditorPanelLayout.createSequentialGroup()
316  .addContainerGap()
317  .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
318  .addGroup(listEditorPanelLayout.createSequentialGroup()
319  .addGap(10, 10, 10)
320  .addComponent(addKeywordPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
321  .addGroup(listEditorPanelLayout.createSequentialGroup()
322  .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
323  .addGroup(listEditorPanelLayout.createSequentialGroup()
324  .addComponent(listOptionsLabel)
325  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
326  .addComponent(listOptionsSeparator))
327  .addGroup(listEditorPanelLayout.createSequentialGroup()
328  .addComponent(keywordOptionsLabel)
329  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
330  .addComponent(keywordOptionsSeparator))
331  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
332  .addGroup(listEditorPanelLayout.createSequentialGroup()
333  .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
334  .addComponent(keywordsLabel)
335  .addGroup(listEditorPanelLayout.createSequentialGroup()
336  .addGap(10, 10, 10)
337  .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
338  .addComponent(ingestMessagesCheckbox)
339  .addGroup(listEditorPanelLayout.createSequentialGroup()
340  .addComponent(exportButton)
341  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
342  .addComponent(saveListButton)
343  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
344  .addComponent(deleteListButton)))))
345  .addGap(0, 0, Short.MAX_VALUE)))
346  .addContainerGap())))
347  );
348  listEditorPanelLayout.setVerticalGroup(
349  listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
350  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, listEditorPanelLayout.createSequentialGroup()
351  .addContainerGap()
352  .addComponent(keywordsLabel)
353  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
354  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
355  .addGap(10, 10, 10)
356  .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
357  .addGroup(listEditorPanelLayout.createSequentialGroup()
358  .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
359  .addComponent(keywordOptionsSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
360  .addComponent(keywordOptionsLabel))
361  .addGap(7, 7, 7)
362  .addComponent(addKeywordPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
363  .addGap(0, 0, 0)
364  .addComponent(listOptionsLabel))
365  .addGroup(listEditorPanelLayout.createSequentialGroup()
366  .addGap(123, 123, 123)
367  .addComponent(listOptionsSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)))
368  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
369  .addComponent(ingestMessagesCheckbox)
370  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
371  .addGroup(listEditorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
372  .addComponent(exportButton)
373  .addComponent(saveListButton)
374  .addComponent(deleteListButton))
375  .addContainerGap())
376  );
377 
378  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
379  this.setLayout(layout);
380  layout.setHorizontalGroup(
381  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
382  .addComponent(listEditorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
383  );
384  layout.setVerticalGroup(
385  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
386  .addGroup(layout.createSequentialGroup()
387  .addComponent(listEditorPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
388  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
389  );
390  }// </editor-fold>//GEN-END:initComponents
391 
392  private void addWordButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addWordButtonActionPerformed
393  String newWord = addWordField.getText().trim();
394  boolean isLiteral = !chRegex.isSelected();
395  final Keyword keyword = new Keyword(newWord, isLiteral);
396 
397  if (newWord.equals("")) {
398  return;
399  } else if (currentKeywordList.hasKeyword(keyword)) {
400  KeywordSearchUtil.displayDialog(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.newKwTitle"),
401  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.addWordButtonAction.kwAlreadyExistsMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
402  return;
403  }
404 
405  //check if valid
406  boolean valid = true;
407  try {
408  Pattern.compile(newWord);
409  } catch (PatternSyntaxException ex1) {
410  valid = false;
411  } catch (IllegalArgumentException ex2) {
412  valid = false;
413  }
414  if (!valid) {
415  KeywordSearchUtil.displayDialog(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.newKwTitle"),
416  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.invalidKwMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
417  return;
418  }
419 
420  //add & reset checkbox
421  tableModel.addKeyword(keyword);
422  XmlKeywordSearchList.getCurrent().addList(currentKeywordList);
423  chRegex.setSelected(false);
424  addWordField.setText("");
425 
426  setButtonStates();
427  }//GEN-LAST:event_addWordButtonActionPerformed
428 
429  private void deleteWordButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteWordButtonActionPerformed
430  if (KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.removeKwMsg"), NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.deleteWordButtonActionPerformed.delConfirmMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
431 
432  tableModel.deleteSelected(keywordTable.getSelectedRows());
433  XmlKeywordSearchList.getCurrent().addList(currentKeywordList);
434  setButtonStates();
435  }
436  }//GEN-LAST:event_deleteWordButtonActionPerformed
437 
438  private void addWordFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addWordFieldActionPerformed
439  addWordButtonActionPerformed(evt);
440  }//GEN-LAST:event_addWordFieldActionPerformed
441 
442  private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed
443 
444  final String FEATURE_NAME = NbBundle.getMessage(this.getClass(),
445  "KeywordSearchEditListPanel.exportButtonAction.featureName.text");
446 
447  JFileChooser chooser = new JFileChooser();
448  final String EXTENSION = "xml"; //NON-NLS
449  FileNameExtensionFilter filter = new FileNameExtensionFilter(
450  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.fileFilterLabel"), EXTENSION);
451  chooser.setFileFilter(filter);
452  chooser.setSelectedFile(new File(currentKeywordList.getName()));
453  chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
454 
455  int returnVal = chooser.showSaveDialog(this);
456  if (returnVal == JFileChooser.APPROVE_OPTION) {
457  File selFile = chooser.getSelectedFile();
458  if (selFile == null) {
459  return;
460  }
461 
462  //force append extension if not given
463  String fileAbs = selFile.getAbsolutePath();
464  if (!fileAbs.endsWith("." + EXTENSION)) {
465  fileAbs = fileAbs + "." + EXTENSION;
466  selFile = new File(fileAbs);
467  }
468 
469  boolean shouldWrite = true;
470  if (selFile.exists()) {
471  shouldWrite = KeywordSearchUtil.displayConfirmDialog(FEATURE_NAME,
472  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.fileExistPrompt",
473  selFile.getName()), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
474  }
475  if (!shouldWrite) {
476  return;
477  }
478 
479  XmlKeywordSearchList reader = XmlKeywordSearchList.getCurrent();
480 
481  List<KeywordList> toWrite = new ArrayList<>();
482  toWrite.add(reader.getList(currentKeywordList.getName()));
483  final XmlKeywordSearchList exporter = new XmlKeywordSearchList(fileAbs);
484  boolean written = exporter.saveLists(toWrite);
485  if (written) {
486  KeywordSearchUtil.displayDialog(FEATURE_NAME,
487  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.kwListExportedMsg"),
488  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
489  }
490  }
491  }//GEN-LAST:event_exportButtonActionPerformed
492 
493  private void ingestMessagesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ingestMessagesCheckboxActionPerformed
494  currentKeywordList.setIngestMessages(ingestMessagesCheckbox.isSelected());
495  XmlKeywordSearchList updater = XmlKeywordSearchList.getCurrent();
496  updater.addList(currentKeywordList);
497  }//GEN-LAST:event_ingestMessagesCheckboxActionPerformed
498  // Variables declaration - do not modify//GEN-BEGIN:variables
499  private javax.swing.JPanel addKeywordPanel;
500  private javax.swing.JButton addWordButton;
501  private javax.swing.JTextField addWordField;
502  private javax.swing.JCheckBox chRegex;
503  private javax.swing.JMenuItem copyMenuItem;
504  private javax.swing.JMenuItem cutMenuItem;
505  private javax.swing.JButton deleteListButton;
506  private javax.swing.JButton deleteWordButton;
507  private javax.swing.JButton exportButton;
508  private javax.swing.JCheckBox ingestMessagesCheckbox;
509  private javax.swing.JScrollPane jScrollPane1;
510  private javax.swing.JLabel keywordOptionsLabel;
511  private javax.swing.JSeparator keywordOptionsSeparator;
512  private javax.swing.JTable keywordTable;
513  private javax.swing.JLabel keywordsLabel;
514  private javax.swing.JPanel listEditorPanel;
515  private javax.swing.JLabel listOptionsLabel;
516  private javax.swing.JSeparator listOptionsSeparator;
517  private javax.swing.JMenuItem pasteMenuItem;
518  private javax.swing.JPopupMenu rightClickMenu;
519  private javax.swing.JButton saveListButton;
520  private javax.swing.JMenuItem selectAllMenuItem;
521  // End of variables declaration//GEN-END:variables
522 
523  @Override
524  public void valueChanged(ListSelectionEvent e) {
525  //respond to list selection changes in KeywordSearchListManagementPanel
526  ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
527  if (!listSelectionModel.isSelectionEmpty()) {
528  int index = listSelectionModel.getMinSelectionIndex();
529 
530  listSelectionModel.setSelectionInterval(index, index);
531  XmlKeywordSearchList loader = XmlKeywordSearchList.getCurrent();
532 
533  currentKeywordList = loader.getListsL(false).get(index);
534  tableModel.resync();
535  setButtonStates();
536  } else {
537  currentKeywordList = null;
538  tableModel.resync();
539  setButtonStates();
540  }
541  }
542 
543  @Override
544  public void store() {
545  // Implemented by parent panel
546  }
547 
548  @Override
549  public void load() {
550  // Implemented by parent panel
551  }
552 
553  KeywordList getCurrentKeywordList() {
554  return currentKeywordList;
555  }
556 
557  void setCurrentKeywordList(KeywordList list) {
558  currentKeywordList = list;
559  }
560 
561  void addDeleteButtonActionPerformed(ActionListener l) {
562  deleteListButton.addActionListener(l);
563  }
564 
565  void addSaveButtonActionPerformed(ActionListener l) {
566  saveListButton.addActionListener(l);
567  }
568 
569  private class KeywordTableModel extends AbstractTableModel {
570 
571  @Override
572  public int getColumnCount() {
573  return 2;
574  }
575 
576  @Override
577  public int getRowCount() {
578  return currentKeywordList == null ? 0 : currentKeywordList.getKeywords().size();
579  }
580 
581  @Override
582  public String getColumnName(int column) {
583  String colName = null;
584 
585  switch (column) {
586  case 0:
587  colName = NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.kwColName");
588  break;
589  case 1:
590  colName = NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.regExColName");
591  break;
592  default:
593  ;
594 
595  }
596  return colName;
597  }
598 
599  @Override
600  public Object getValueAt(int rowIndex, int columnIndex) {
601  Object ret = null;
602  if (currentKeywordList == null) {
603  return "";
604  }
605  Keyword word = currentKeywordList.getKeywords().get(rowIndex);
606  switch (columnIndex) {
607  case 0:
608  ret = (Object) word.getQuery();
609  break;
610  case 1:
611  ret = (Object) !word.isLiteral();
612  break;
613  default:
614  logger.log(Level.SEVERE, "Invalid table column index: {0}", columnIndex); //NON-NLS
615  break;
616  }
617  return ret;
618  }
619 
620  @Override
621  public boolean isCellEditable(int rowIndex, int columnIndex) {
622  return false;
623  }
624 
625  @Override
626  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
627  }
628 
629  @Override
630  public Class<?> getColumnClass(int c) {
631  return getValueAt(0, c).getClass();
632  }
633 
634  void addKeyword(Keyword keyword) {
635  if (!currentKeywordList.hasKeyword(keyword)) {
636  currentKeywordList.getKeywords().add(keyword);
637  }
638  fireTableDataChanged();
639  }
640 
641  void resync() {
642  fireTableDataChanged();
643  }
644 
645  //delete selected from handle, events are fired from the handle
646  void deleteSelected(int[] selected) {
647  List<Keyword> words = currentKeywordList.getKeywords();
648  Arrays.sort(selected);
649  for (int arrayi = selected.length - 1; arrayi >= 0; arrayi--) {
650  words.remove(selected[arrayi]);
651  }
652  resync();
653  }
654  }
655 }

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.