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

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.