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

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.