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

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