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

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.