Autopsy  4.4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
GlobalListsManagementPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 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.ActionListener;
23 import java.awt.event.KeyEvent;
24 import java.beans.PropertyChangeEvent;
25 import java.beans.PropertyChangeListener;
26 import java.io.File;
27 import java.util.ArrayList;
28 import java.util.List;
29 import javax.swing.JFileChooser;
30 import javax.swing.JOptionPane;
31 import javax.swing.event.ListSelectionEvent;
32 import javax.swing.event.ListSelectionListener;
33 import javax.swing.filechooser.FileNameExtensionFilter;
34 import javax.swing.table.AbstractTableModel;
35 import org.netbeans.spi.options.OptionsPanelController;
36 import org.openide.util.NbBundle;
39 
43 class GlobalListsManagementPanel extends javax.swing.JPanel implements OptionsPanel {
44 
45  private static final long serialVersionUID = 1L;
46  private final KeywordListTableModel tableModel;
47  private final org.sleuthkit.autopsy.keywordsearch.GlobalListSettingsPanel globalListSettingsPanel;
48 
49  GlobalListsManagementPanel(org.sleuthkit.autopsy.keywordsearch.GlobalListSettingsPanel gsp) {
50  this.globalListSettingsPanel = gsp;
51  tableModel = new KeywordListTableModel();
52  initComponents();
53  customizeComponents();
54  }
55 
56  private void customizeComponents() {
57  listsTable.setAutoscrolls(true);
58  listsTable.setTableHeader(null);
59  listsTable.setShowHorizontalLines(false);
60  listsTable.setShowVerticalLines(false);
61  exportButton.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.exportToFile"));
62  copyListButton.setToolTipText(NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.customizeComponents.saveCurrentWIthNewNameToolTip"));
63  listsTable.getParent().setBackground(listsTable.getBackground());
64 
65  listsTable.setCellSelectionEnabled(false);
66  listsTable.setRowSelectionAllowed(true);
67  tableModel.resync();
68  setButtonStates();
69 
70  listsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
71  @Override
72  public void valueChanged(ListSelectionEvent e) {
73  globalListSettingsPanel.setFocusOnKeywordTextBox();
74  setButtonStates();
75  }
76  });
77 
78  IngestManager.getInstance().addIngestJobEventListener(new PropertyChangeListener() {
79  @Override
80  public void propertyChange(PropertyChangeEvent evt) {
81  Object source = evt.getSource();
82  if (source instanceof String && ((String) source).equals("LOCAL")) { //NON-NLS
83  EventQueue.invokeLater(() -> {
84  globalListSettingsPanel.setFocusOnKeywordTextBox();
85  setButtonStates();
86  });
87  }
88  }
89  });
90  }
91 
92  void addDeleteButtonActionPerformed(ActionListener l) {
93  deleteListButton.addActionListener(l);
94  }
95 
96  void addRenameButtonActionPerformed(ActionListener l) {
97  renameListButton.addActionListener(l);
98  }
99 
100  void addCopyButtonActionPerformed(ActionListener l) {
101  copyListButton.addActionListener(l);
102  }
103 
108  private void newKeywordListAction() {
109  XmlKeywordSearchList writer = XmlKeywordSearchList.getCurrent();
110  String listName = "";
111 
112  listName = (String) JOptionPane.showInputDialog(null, NbBundle.getMessage(this.getClass(), "KeywordSearch.newKwListTitle"),
113  NbBundle.getMessage(this.getClass(), "KeywordSearch.newKeywordListMsg"), JOptionPane.PLAIN_MESSAGE, null, null, listName);
114 
115  if (listName == null || listName.trim().isEmpty()) {
116  return;
117  }
118  boolean shouldAdd = false;
119  if (writer.listExists(listName)) {
120  if (writer.getList(listName).isEditable()) {
121  boolean replace = KeywordSearchUtil.displayConfirmDialog(
122  NbBundle.getMessage(this.getClass(), "KeywordSearch.newKeywordListMsg"),
123  NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.newKeywordListDescription", listName),
124  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
125  if (replace) {
126  shouldAdd = true;
127  }
128  } else {
129  boolean replace = KeywordSearchUtil.displayConfirmDialog(
130  NbBundle.getMessage(this.getClass(), "KeywordSearch.newKeywordListMsg"),
131  NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.newKeywordListDescription2", listName),
132  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
133  if (replace) {
134  shouldAdd = true;
135  }
136  }
137  } else {
138  shouldAdd = true;
139  }
140  if (shouldAdd) {
141  writer.addList(listName, new ArrayList<>());
142  }
143 
144  tableModel.resync();
145 
146  //This loop selects the recently ADDED keywordslist in the JTable
147  for (int i = 0; i < listsTable.getRowCount(); i++) {
148  if (listsTable.getValueAt(i, 0).equals(listName)) {
149  listsTable.getSelectionModel().addSelectionInterval(i, i);
150  }
151  }
152  }
153 
157  void setButtonStates() {
158  boolean isIngestRunning = IngestManager.getInstance().isIngestRunning();
159  boolean isListSelected = !listsTable.getSelectionModel().isSelectionEmpty();
160  boolean canEditList = isListSelected && !isIngestRunning;
161  boolean multiSelection = false; //can't rename or copy when multiple lists selected
162  if (isListSelected) {
163  multiSelection = (listsTable.getSelectionModel().getMaxSelectionIndex() != listsTable.getSelectionModel().getMinSelectionIndex());
164  }
165  // items that only need ingest to not be running
166  importButton.setEnabled(!isIngestRunning);
167  // items that need an unlocked list w/out ingest running
168  deleteListButton.setEnabled(canEditList);
169  renameListButton.setEnabled(canEditList);
170  renameListButton.setEnabled(canEditList && !multiSelection);
171  // items that only need a selected list
172  copyListButton.setEnabled(isListSelected);
173  copyListButton.setEnabled(isListSelected && !multiSelection);
174  exportButton.setEnabled(isListSelected);
175  }
176 
182  @SuppressWarnings("unchecked")
183  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
184  private void initComponents() {
185 
186  jScrollPane1 = new javax.swing.JScrollPane();
187  listsTable = new javax.swing.JTable();
188  newListButton = new javax.swing.JButton();
189  importButton = new javax.swing.JButton();
190  keywordListsLabel = new javax.swing.JLabel();
191  exportButton = new javax.swing.JButton();
192  copyListButton = new javax.swing.JButton();
193  deleteListButton = new javax.swing.JButton();
194  renameListButton = new javax.swing.JButton();
195 
196  setMinimumSize(new java.awt.Dimension(250, 0));
197 
198  listsTable.setModel(tableModel);
199  listsTable.setMaximumSize(new java.awt.Dimension(30000, 30000));
200  listsTable.setShowHorizontalLines(false);
201  listsTable.setShowVerticalLines(false);
202  listsTable.getTableHeader().setReorderingAllowed(false);
203  listsTable.addKeyListener(new java.awt.event.KeyAdapter() {
204  public void keyPressed(java.awt.event.KeyEvent evt) {
205  listsTableKeyPressed(evt);
206  }
207  });
208  jScrollPane1.setViewportView(listsTable);
209 
210  newListButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/add16.png"))); // NOI18N
211  newListButton.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.newListButton.text")); // NOI18N
212  newListButton.setIconTextGap(2);
213  newListButton.setMargin(new java.awt.Insets(2, 6, 2, 6));
214  newListButton.setMaximumSize(new java.awt.Dimension(111, 25));
215  newListButton.setMinimumSize(new java.awt.Dimension(111, 25));
216  newListButton.setPreferredSize(new java.awt.Dimension(111, 25));
217  newListButton.addActionListener(new java.awt.event.ActionListener() {
218  public void actionPerformed(java.awt.event.ActionEvent evt) {
219  newListButtonActionPerformed(evt);
220  }
221  });
222 
223  importButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/import16.png"))); // NOI18N
224  importButton.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.importButton.text")); // NOI18N
225  importButton.setIconTextGap(2);
226  importButton.setMargin(new java.awt.Insets(2, 6, 2, 6));
227  importButton.setMaximumSize(new java.awt.Dimension(111, 25));
228  importButton.setMinimumSize(new java.awt.Dimension(111, 25));
229  importButton.setPreferredSize(new java.awt.Dimension(111, 25));
230  importButton.addActionListener(new java.awt.event.ActionListener() {
231  public void actionPerformed(java.awt.event.ActionEvent evt) {
232  importButtonActionPerformed(evt);
233  }
234  });
235 
236  keywordListsLabel.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.keywordListsLabel.text")); // NOI18N
237 
238  exportButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/export16.png"))); // NOI18N
239  exportButton.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.exportButton.text")); // NOI18N
240  exportButton.setIconTextGap(2);
241  exportButton.setMargin(new java.awt.Insets(2, 6, 2, 6));
242  exportButton.setMaximumSize(new java.awt.Dimension(111, 25));
243  exportButton.setMinimumSize(new java.awt.Dimension(111, 25));
244  exportButton.setPreferredSize(new java.awt.Dimension(111, 25));
245  exportButton.addActionListener(new java.awt.event.ActionListener() {
246  public void actionPerformed(java.awt.event.ActionEvent evt) {
247  exportButtonActionPerformed(evt);
248  }
249  });
250 
251  copyListButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/new16.png"))); // NOI18N
252  copyListButton.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.copyListButton.text")); // NOI18N
253  copyListButton.setIconTextGap(2);
254  copyListButton.setMargin(new java.awt.Insets(2, 6, 2, 6));
255  copyListButton.setMaximumSize(new java.awt.Dimension(111, 25));
256  copyListButton.setMinimumSize(new java.awt.Dimension(111, 25));
257  copyListButton.setPreferredSize(new java.awt.Dimension(111, 25));
258  copyListButton.addActionListener(new java.awt.event.ActionListener() {
259  public void actionPerformed(java.awt.event.ActionEvent evt) {
260  copyListButtonActionPerformed(evt);
261  }
262  });
263 
264  deleteListButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/delete16.png"))); // NOI18N
265  deleteListButton.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.deleteListButton.text")); // NOI18N
266  deleteListButton.setIconTextGap(2);
267  deleteListButton.setMargin(new java.awt.Insets(2, 6, 2, 6));
268  deleteListButton.setMaximumSize(new java.awt.Dimension(111, 25));
269  deleteListButton.setMinimumSize(new java.awt.Dimension(111, 25));
270  deleteListButton.setPreferredSize(new java.awt.Dimension(111, 25));
271  deleteListButton.addActionListener(new java.awt.event.ActionListener() {
272  public void actionPerformed(java.awt.event.ActionEvent evt) {
273  deleteListButtonActionPerformed(evt);
274  }
275  });
276 
277  renameListButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/edit16.png"))); // NOI18N
278  renameListButton.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.renameListButton.text")); // NOI18N
279  renameListButton.setIconTextGap(2);
280  renameListButton.setMargin(new java.awt.Insets(2, 6, 2, 6));
281  renameListButton.setMaximumSize(new java.awt.Dimension(111, 25));
282  renameListButton.setMinimumSize(new java.awt.Dimension(111, 25));
283  renameListButton.setPreferredSize(new java.awt.Dimension(111, 25));
284  renameListButton.addActionListener(new java.awt.event.ActionListener() {
285  public void actionPerformed(java.awt.event.ActionEvent evt) {
286  renameListButtonActionPerformed(evt);
287  }
288  });
289 
290  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
291  this.setLayout(layout);
292  layout.setHorizontalGroup(
293  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
294  .addGroup(layout.createSequentialGroup()
295  .addGap(10, 10, 10)
296  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
297  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)
298  .addGroup(layout.createSequentialGroup()
299  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
300  .addComponent(newListButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
301  .addComponent(copyListButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
302  .addGap(6, 6, 6)
303  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
304  .addComponent(importButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
305  .addComponent(renameListButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
306  .addGap(6, 6, 6)
307  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
308  .addComponent(exportButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
309  .addComponent(deleteListButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
310  .addGap(0, 0, Short.MAX_VALUE))
311  .addComponent(keywordListsLabel))
312  .addGap(6, 6, 6))
313  );
314 
315  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {copyListButton, deleteListButton, exportButton, importButton, newListButton, renameListButton});
316 
317  layout.setVerticalGroup(
318  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
319  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
320  .addGap(22, 22, 22)
321  .addComponent(keywordListsLabel)
322  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
323  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)
324  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
325  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
326  .addComponent(newListButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
327  .addComponent(renameListButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
328  .addComponent(deleteListButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
329  .addGap(6, 6, 6)
330  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
331  .addComponent(importButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
332  .addComponent(exportButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
333  .addComponent(copyListButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
334  .addGap(6, 6, 6))
335  );
336 
337  layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {copyListButton, deleteListButton, exportButton, importButton, newListButton, renameListButton});
338 
339  }// </editor-fold>//GEN-END:initComponents
340 
341  private void newListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newListButtonActionPerformed
342  newKeywordListAction();
343  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
344  globalListSettingsPanel.setFocusOnKeywordTextBox();
345  }//GEN-LAST:event_newListButtonActionPerformed
346 
347  private void importButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importButtonActionPerformed
348 
349  JFileChooser chooser = new JFileChooser();
350  final String[] AUTOPSY_EXTENSIONS = new String[]{"xml"}; //NON-NLS
351  final String[] ENCASE_EXTENSIONS = new String[]{"txt"}; //NON-NLS
352  FileNameExtensionFilter autopsyFilter = new FileNameExtensionFilter(
353  NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.fileExtensionFilterLbl"), AUTOPSY_EXTENSIONS);
354  FileNameExtensionFilter encaseFilter = new FileNameExtensionFilter(
355  NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.fileExtensionFilterLb2"), ENCASE_EXTENSIONS);
356  chooser.addChoosableFileFilter(autopsyFilter);
357  chooser.addChoosableFileFilter(encaseFilter);
358  chooser.setAcceptAllFileFilterUsed(false);
359  chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
360 
361  String listName = null;
362  int returnVal = chooser.showOpenDialog(this);
363  if (returnVal == JFileChooser.APPROVE_OPTION) {
364  File selFile = chooser.getSelectedFile();
365  if (selFile == null) {
366  return;
367  }
368 
369  //force append extension if not given
370  String fileAbs = selFile.getAbsolutePath();
371 
372  final KeywordSearchList reader;
373 
374  if (KeywordSearchUtil.isXMLList(fileAbs)) {
375  reader = new XmlKeywordSearchList(fileAbs);
376  } else {
377  reader = new EnCaseKeywordSearchList(fileAbs);
378  }
379 
380  if (!reader.load()) {
381  KeywordSearchUtil.displayDialog(
382  NbBundle.getMessage(this.getClass(), "KeywordSearch.listImportFeatureTitle"), NbBundle.getMessage(this.getClass(), "KeywordSearch.importListFileDialogMsg", fileAbs), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
383  return;
384  }
385 
386  List<KeywordList> toImport = reader.getListsL();
387  List<KeywordList> toImportConfirmed = new ArrayList<>();
388 
389  final XmlKeywordSearchList writer = XmlKeywordSearchList.getCurrent();
390 
391  for (KeywordList list : toImport) {
392  //check name collisions
393  listName = list.getName();
394  if (writer.listExists(listName)) {
395  String[] options;
396  if (toImport.size() == 1) { //only give them cancel and yes buttons for single list imports
397  options = new String[]{NbBundle.getMessage(this.getClass(), "KeywordSearch.yesOwMsg"),
398  NbBundle.getMessage(this.getClass(), "KeywordSearch.cancelImportMsg")};
399  } else {
400  options = new String[]{NbBundle.getMessage(this.getClass(), "KeywordSearch.yesOwMsg"),
401  NbBundle.getMessage(this.getClass(), "KeywordSearch.noSkipMsg"),
402  NbBundle.getMessage(this.getClass(), "KeywordSearch.cancelImportMsg")};
403  }
404  int choice = JOptionPane.showOptionDialog(this,
405  NbBundle.getMessage(this.getClass(), "KeywordSearch.overwriteListPrompt", listName),
406  NbBundle.getMessage(this.getClass(), "KeywordSearch.importOwConflict"),
407  JOptionPane.YES_NO_CANCEL_OPTION,
408  JOptionPane.QUESTION_MESSAGE,
409  null,
410  options,
411  options[0]);
412  if (choice == JOptionPane.OK_OPTION) {
413  toImportConfirmed.add(list);
414  } else if (choice == JOptionPane.CANCEL_OPTION) {
415  break;
416  }
417 
418  } else {
419  //no conflict
420  toImportConfirmed.add(list);
421  }
422 
423  }
424 
425  if (toImportConfirmed.isEmpty()) {
426  return;
427  }
428 
429  if (!writer.writeLists(toImportConfirmed)) {
430  KeywordSearchUtil.displayDialog(
431  NbBundle.getMessage(this.getClass(), "KeywordSearch.listImportFeatureTitle"), NbBundle.getMessage(this.getClass(), "KeywordSearch.kwListFailImportMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
432  }
433 
434  }
435  tableModel.resync();
436 
437  //This loop selects the recently IMPORTED keywordslist in the JTable
438  if (listName != null) {
439  for (int i = 0; i < listsTable.getRowCount(); i++) {
440  if (listsTable.getValueAt(i, 0).equals(listName)) {
441  listsTable.getSelectionModel().addSelectionInterval(i, i);
442  }
443  }
444  }
445  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
446  }//GEN-LAST:event_importButtonActionPerformed
447  private void listsTableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_listsTableKeyPressed
448  if (evt.getKeyCode() == KeyEvent.VK_DELETE && !IngestManager.getInstance().isIngestRunning() && !listsTable.getSelectionModel().isSelectionEmpty()) {
449  if (KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.title"), NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.body"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
450  deleteSelected();
451  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
452  } else {
453  return;
454  }
455  }
456  tableModel.resync();
457  }//GEN-LAST:event_listsTableKeyPressed
458 
459  private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed
460 
461  final String FEATURE_NAME = NbBundle.getMessage(this.getClass(),
462  "KeywordSearchEditListPanel.exportButtonAction.featureName.text");
463 
464  JFileChooser chooser = new JFileChooser();
465  final String EXTENSION = "xml"; //NON-NLS
466  FileNameExtensionFilter filter = new FileNameExtensionFilter(
467  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.fileFilterLabel"), EXTENSION);
468  chooser.setFileFilter(filter);
469  String listName = listsTable.getValueAt(listsTable.getSelectedRow(), 0).toString();
470 
471  chooser.setSelectedFile(new File(listName));
472  chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
473 
474  int returnVal = chooser.showSaveDialog(this);
475  if (returnVal == JFileChooser.APPROVE_OPTION) {
476  File selFile = chooser.getSelectedFile();
477  if (selFile == null) {
478  return;
479  }
480 
481  //force append extension if not given
482  String fileAbs = selFile.getAbsolutePath();
483  if (!fileAbs.endsWith("." + EXTENSION)) {
484  fileAbs = fileAbs + "." + EXTENSION;
485  selFile = new File(fileAbs);
486  }
487 
488  boolean shouldWrite = true;
489  if (selFile.exists()) {
490  shouldWrite = KeywordSearchUtil.displayConfirmDialog(FEATURE_NAME,
491  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.fileExistPrompt",
492  selFile.getName()), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
493  }
494  if (!shouldWrite) {
495  return;
496  }
497 
498  XmlKeywordSearchList reader = XmlKeywordSearchList.getCurrent();
499 
500  List<KeywordList> toWrite = new ArrayList<>();
501 
502  for (int index : listsTable.getSelectedRows()) {
503  toWrite.add(reader.getList(listsTable.getValueAt(index, 0).toString()));
504  }
505 
506  final XmlKeywordSearchList exporter = new XmlKeywordSearchList(fileAbs);
507  boolean written = exporter.saveLists(toWrite);
508  if (written) {
509  KeywordSearchUtil.displayDialog(FEATURE_NAME,
510  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.kwListExportedMsg"),
511  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
512  }
513  }
514  }//GEN-LAST:event_exportButtonActionPerformed
515 
516  private void copyListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copyListButtonActionPerformed
517  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
518  }//GEN-LAST:event_copyListButtonActionPerformed
519 
520  private void deleteListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteListButtonActionPerformed
521  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
522  }//GEN-LAST:event_deleteListButtonActionPerformed
523 
524  private void renameListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_renameListButtonActionPerformed
525  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
526  }//GEN-LAST:event_renameListButtonActionPerformed
527 
528  // Variables declaration - do not modify//GEN-BEGIN:variables
529  private javax.swing.JButton copyListButton;
530  private javax.swing.JButton deleteListButton;
531  private javax.swing.JButton exportButton;
532  private javax.swing.JButton importButton;
533  private javax.swing.JScrollPane jScrollPane1;
534  private javax.swing.JLabel keywordListsLabel;
535  private javax.swing.JTable listsTable;
536  private javax.swing.JButton newListButton;
537  private javax.swing.JButton renameListButton;
538  // End of variables declaration//GEN-END:variables
539 
540  @Override
541  public void store() {
542  // Implemented by parent panel
543  }
544 
545  @Override
546  public void load() {
547  listsTable.clearSelection();
548  }
549 
550  void resync() {
551  tableModel.resync();
552  }
553 
554  void deleteSelected() {
555  int[] selected = listsTable.getSelectedRows();
556  if (selected.length == 0) {
557  return;
558  }
559  tableModel.deleteSelected(selected);
560  }
561 
562  private class KeywordListTableModel extends AbstractTableModel {
563 
564  private static final long serialVersionUID = 1L;
565 
566  private final XmlKeywordSearchList listsHandle = XmlKeywordSearchList.getCurrent();
567 
568  @Override
569  public int getColumnCount() {
570  return 1;
571  }
572 
573  @Override
574  public int getRowCount() {
575  return listsHandle.getNumberLists(false);
576  }
577 
578  @Override
579  public String getColumnName(int column) {
580  return NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.getColName.text");
581  }
582 
583  @Override
584  public Object getValueAt(int rowIndex, int columnIndex) {
585  return listsHandle.getListNames(false).get(rowIndex);
586  }
587 
588  @Override
589  public boolean isCellEditable(int rowIndex, int columnIndex) {
590  return false;
591  }
592 
593  @Override
594  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
595  throw new UnsupportedOperationException(
596  NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.setValueAt.exception.msg"));
597  }
598 
599  @Override
600  public Class<?> getColumnClass(int c) {
601  return getValueAt(0, c).getClass();
602  }
603 
604  //delete selected from handle, events are fired from the handle
605  void deleteSelected(int[] selected) {
606  List<String> toDel = new ArrayList<>();
607  for (int i : selected) {
608  toDel.add(getValueAt(i, 0).toString());
609  }
610  for (String del : toDel) {
611  listsHandle.deleteList(del);
612  }
613  }
614 
615  //resync model from handle, then update table
616  void resync() {
617  fireTableDataChanged();
618  }
619  }
620 
621  void addListSelectionListener(ListSelectionListener l) {
622  listsTable.getSelectionModel().addListSelectionListener(l);
623  }
624 }

Copyright © 2012-2016 Basis Technology. Generated on: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.