Autopsy  4.6.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(this, 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.addActionListener(new java.awt.event.ActionListener() {
221  public void actionPerformed(java.awt.event.ActionEvent evt) {
222  newListButtonActionPerformed(evt);
223  }
224  });
225 
226  importButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/import16.png"))); // NOI18N
227  importButton.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.importButton.text")); // NOI18N
228  importButton.setIconTextGap(2);
229  importButton.setMargin(new java.awt.Insets(2, 6, 2, 6));
230  importButton.setMaximumSize(new java.awt.Dimension(111, 25));
231  importButton.setMinimumSize(new java.awt.Dimension(111, 25));
232  importButton.addActionListener(new java.awt.event.ActionListener() {
233  public void actionPerformed(java.awt.event.ActionEvent evt) {
234  importButtonActionPerformed(evt);
235  }
236  });
237 
238  keywordListsLabel.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.keywordListsLabel.text")); // NOI18N
239 
240  exportButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/export16.png"))); // NOI18N
241  exportButton.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.exportButton.text")); // NOI18N
242  exportButton.setIconTextGap(2);
243  exportButton.setMargin(new java.awt.Insets(2, 6, 2, 6));
244  exportButton.setMaximumSize(new java.awt.Dimension(111, 25));
245  exportButton.setMinimumSize(new java.awt.Dimension(111, 25));
246  exportButton.addActionListener(new java.awt.event.ActionListener() {
247  public void actionPerformed(java.awt.event.ActionEvent evt) {
248  exportButtonActionPerformed(evt);
249  }
250  });
251 
252  copyListButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/new16.png"))); // NOI18N
253  copyListButton.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.copyListButton.text")); // NOI18N
254  copyListButton.setIconTextGap(2);
255  copyListButton.setMargin(new java.awt.Insets(2, 6, 2, 6));
256  copyListButton.setMaximumSize(new java.awt.Dimension(111, 25));
257  copyListButton.setMinimumSize(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.addActionListener(new java.awt.event.ActionListener() {
271  public void actionPerformed(java.awt.event.ActionEvent evt) {
272  deleteListButtonActionPerformed(evt);
273  }
274  });
275 
276  renameListButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/edit16.png"))); // NOI18N
277  renameListButton.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.renameListButton.text")); // NOI18N
278  renameListButton.setIconTextGap(2);
279  renameListButton.setMargin(new java.awt.Insets(2, 6, 2, 6));
280  renameListButton.setMaximumSize(new java.awt.Dimension(111, 25));
281  renameListButton.setMinimumSize(new java.awt.Dimension(111, 25));
282  renameListButton.addActionListener(new java.awt.event.ActionListener() {
283  public void actionPerformed(java.awt.event.ActionEvent evt) {
284  renameListButtonActionPerformed(evt);
285  }
286  });
287 
288  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
289  this.setLayout(layout);
290  layout.setHorizontalGroup(
291  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
292  .addGroup(layout.createSequentialGroup()
293  .addGap(10, 10, 10)
294  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
295  .addGroup(layout.createSequentialGroup()
296  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
297  .addComponent(newListButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
298  .addComponent(copyListButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
299  .addGap(6, 6, 6)
300  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
301  .addComponent(importButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
302  .addComponent(renameListButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
303  .addGap(6, 6, 6)
304  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
305  .addComponent(exportButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
306  .addComponent(deleteListButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
307  .addComponent(keywordListsLabel)
308  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
309  .addGap(12, 12, Short.MAX_VALUE))
310  );
311 
312  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {copyListButton, deleteListButton, exportButton, importButton, newListButton, renameListButton});
313 
314  layout.setVerticalGroup(
315  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
316  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
317  .addGap(22, 22, 22)
318  .addComponent(keywordListsLabel)
319  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
320  .addComponent(jScrollPane1)
321  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
322  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
323  .addComponent(newListButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
324  .addComponent(renameListButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
325  .addComponent(deleteListButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
326  .addGap(6, 6, 6)
327  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
328  .addComponent(importButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
329  .addComponent(exportButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
330  .addComponent(copyListButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
331  .addGap(6, 6, 6))
332  );
333 
334  layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {copyListButton, deleteListButton, exportButton, importButton, newListButton, renameListButton});
335 
336  }// </editor-fold>//GEN-END:initComponents
337 
338  private void newListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newListButtonActionPerformed
339  newKeywordListAction();
340  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
341  globalListSettingsPanel.setFocusOnKeywordTextBox();
342  }//GEN-LAST:event_newListButtonActionPerformed
343 
344  private void importButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importButtonActionPerformed
345  String lastBaseDirectory = Paths.get(PlatformUtil.getUserConfigDirectory(), "KeywordList").toString();
346  if (ModuleSettings.settingExists(ModuleSettings.MAIN_SETTINGS, LAST_KEYWORD_LIST_PATH_KEY)) {
347  lastBaseDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_KEYWORD_LIST_PATH_KEY);
348  }
349  File importFolder = new File(lastBaseDirectory);
350  JFileChooser chooser = new JFileChooser();
351  chooser.setCurrentDirectory(importFolder);
352  final String[] AUTOPSY_EXTENSIONS = new String[]{"xml"}; //NON-NLS
353  final String[] ENCASE_EXTENSIONS = new String[]{"txt"}; //NON-NLS
354  FileNameExtensionFilter autopsyFilter = new FileNameExtensionFilter(
355  NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.fileExtensionFilterLbl"), AUTOPSY_EXTENSIONS);
356  FileNameExtensionFilter encaseFilter = new FileNameExtensionFilter(
357  NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.fileExtensionFilterLb2"), ENCASE_EXTENSIONS);
358  chooser.addChoosableFileFilter(autopsyFilter);
359  chooser.addChoosableFileFilter(encaseFilter);
360  chooser.setAcceptAllFileFilterUsed(false);
361  chooser.setMultiSelectionEnabled(true);
362  chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
363 
364  String listName = null;
365  int returnVal = chooser.showOpenDialog(this);
366  if (returnVal == JFileChooser.APPROVE_OPTION) {
367  File[] selFiles = chooser.getSelectedFiles();
368 
369  for (File file : selFiles) {
370  if (file == null) {
371  continue;
372  }
373 
374  //force append extension if not given
375  String fileAbs = file.getAbsolutePath();
376  final KeywordSearchList reader;
377 
378  if (KeywordSearchUtil.isXMLList(fileAbs)) {
379  reader = new XmlKeywordSearchList(fileAbs);
380  } else {
381  reader = new EnCaseKeywordSearchList(fileAbs);
382  }
383 
384  if (!reader.load()) {
385  KeywordSearchUtil.displayDialog(
386  NbBundle.getMessage(this.getClass(), "KeywordSearch.listImportFeatureTitle"), NbBundle.getMessage(this.getClass(), "KeywordSearch.importListFileDialogMsg", fileAbs), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
387  return;
388  }
389 
390  List<KeywordList> toImport = reader.getListsL();
391  List<KeywordList> toImportConfirmed = new ArrayList<>();
392 
393  final XmlKeywordSearchList writer = XmlKeywordSearchList.getCurrent();
394 
395  for (KeywordList list : toImport) {
396  //check name collisions
397  listName = list.getName();
398  if (writer.listExists(listName)) {
399  String[] options;
400  if (toImport.size() == 1) { //only give them cancel and yes buttons for single list imports
401  options = new String[]{NbBundle.getMessage(this.getClass(), "KeywordSearch.yesOwMsg"),
402  NbBundle.getMessage(this.getClass(), "KeywordSearch.cancelImportMsg")};
403  } else {
404  options = new String[]{NbBundle.getMessage(this.getClass(), "KeywordSearch.yesOwMsg"),
405  NbBundle.getMessage(this.getClass(), "KeywordSearch.noSkipMsg"),
406  NbBundle.getMessage(this.getClass(), "KeywordSearch.cancelImportMsg")};
407  }
408  int choice = JOptionPane.showOptionDialog(this,
409  NbBundle.getMessage(this.getClass(), "KeywordSearch.overwriteListPrompt", listName),
410  NbBundle.getMessage(this.getClass(), "KeywordSearch.importOwConflict"),
411  JOptionPane.YES_NO_CANCEL_OPTION,
412  JOptionPane.QUESTION_MESSAGE,
413  null,
414  options,
415  options[0]);
416  if (choice == JOptionPane.OK_OPTION) {
417  toImportConfirmed.add(list);
418  } else if (choice == JOptionPane.CANCEL_OPTION) {
419  break;
420  }
421 
422  } else {
423  //no conflict
424  toImportConfirmed.add(list);
425  }
426 
427  }
428 
429  if (toImportConfirmed.isEmpty()) {
430  return;
431  }
432 
433  if (!writer.writeLists(toImportConfirmed)) {
434  KeywordSearchUtil.displayDialog(
435  NbBundle.getMessage(this.getClass(), "KeywordSearch.listImportFeatureTitle"), NbBundle.getMessage(this.getClass(), "KeywordSearch.kwListFailImportMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
436  }
437  ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_KEYWORD_LIST_PATH_KEY, file.getParent());
438  }
439  }
440  tableModel.resync();
441 
442  //This loop selects the recently IMPORTED keywordslist in the JTable
443  if (listName != null) {
444  for (int i = 0; i < listsTable.getRowCount(); i++) {
445  if (listsTable.getValueAt(i, 0).equals(listName)) {
446  listsTable.getSelectionModel().addSelectionInterval(i, i);
447  }
448  }
449  }
450  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
451  }//GEN-LAST:event_importButtonActionPerformed
452  private void listsTableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_listsTableKeyPressed
453  if (evt.getKeyCode() == KeyEvent.VK_DELETE && !IngestManager.getInstance().isIngestRunning() && !listsTable.getSelectionModel().isSelectionEmpty()) {
454  if (KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.title"), NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.body"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
455  deleteSelected();
456  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
457  } else {
458  return;
459  }
460  }
461  tableModel.resync();
462  }//GEN-LAST:event_listsTableKeyPressed
463 
464  private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed
465 
466  final String FEATURE_NAME = NbBundle.getMessage(this.getClass(),
467  "KeywordSearchEditListPanel.exportButtonAction.featureName.text");
468 
469  JFileChooser chooser = new JFileChooser();
470  final String EXTENSION = "xml"; //NON-NLS
471  FileNameExtensionFilter filter = new FileNameExtensionFilter(
472  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.fileFilterLabel"), EXTENSION);
473  chooser.setFileFilter(filter);
474  String listName = listsTable.getValueAt(listsTable.getSelectedRow(), 0).toString();
475 
476  chooser.setSelectedFile(new File(listName));
477  chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
478 
479  int returnVal = chooser.showSaveDialog(this);
480  if (returnVal == JFileChooser.APPROVE_OPTION) {
481  File selFile = chooser.getSelectedFile();
482  if (selFile == null) {
483  return;
484  }
485 
486  //force append extension if not given
487  String fileAbs = selFile.getAbsolutePath();
488  if (!fileAbs.endsWith("." + EXTENSION)) {
489  fileAbs = fileAbs + "." + EXTENSION;
490  selFile = new File(fileAbs);
491  }
492 
493  boolean shouldWrite = true;
494  if (selFile.exists()) {
495  shouldWrite = KeywordSearchUtil.displayConfirmDialog(FEATURE_NAME,
496  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.fileExistPrompt",
497  selFile.getName()), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
498  }
499  if (!shouldWrite) {
500  return;
501  }
502 
503  XmlKeywordSearchList reader = XmlKeywordSearchList.getCurrent();
504 
505  List<KeywordList> toWrite = new ArrayList<>();
506 
507  for (int index : listsTable.getSelectedRows()) {
508  toWrite.add(reader.getList(listsTable.getValueAt(index, 0).toString()));
509  }
510 
511  final XmlKeywordSearchList exporter = new XmlKeywordSearchList(fileAbs);
512  boolean written = exporter.saveLists(toWrite);
513  if (written) {
514  KeywordSearchUtil.displayDialog(FEATURE_NAME,
515  NbBundle.getMessage(this.getClass(), "KeywordSearchEditListPanel.exportButtonActionPerformed.kwListExportedMsg"),
516  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
517  }
518  }
519  }//GEN-LAST:event_exportButtonActionPerformed
520 
521  private void copyListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copyListButtonActionPerformed
522  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
523  }//GEN-LAST:event_copyListButtonActionPerformed
524 
525  private void deleteListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteListButtonActionPerformed
526  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
527  }//GEN-LAST:event_deleteListButtonActionPerformed
528 
529  private void renameListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_renameListButtonActionPerformed
530  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
531  }//GEN-LAST:event_renameListButtonActionPerformed
532 
533  // Variables declaration - do not modify//GEN-BEGIN:variables
534  private javax.swing.JButton copyListButton;
535  private javax.swing.JButton deleteListButton;
536  private javax.swing.JButton exportButton;
537  private javax.swing.JButton importButton;
538  private javax.swing.JScrollPane jScrollPane1;
539  private javax.swing.JLabel keywordListsLabel;
540  private javax.swing.JTable listsTable;
541  private javax.swing.JButton newListButton;
542  private javax.swing.JButton renameListButton;
543  // End of variables declaration//GEN-END:variables
544 
545  @Override
546  public void store() {
547  // Implemented by parent panel
548  }
549 
550  @Override
551  public void load() {
552  listsTable.clearSelection();
553  }
554 
555  void resync() {
556  tableModel.resync();
557  }
558 
559  void deleteSelected() {
560  int[] selected = listsTable.getSelectedRows();
561  if (selected.length == 0) {
562  return;
563  }
564  tableModel.deleteSelected(selected);
565  }
566 
567  private class KeywordListTableModel extends AbstractTableModel {
568 
569  private static final long serialVersionUID = 1L;
570 
571  private final XmlKeywordSearchList listsHandle = XmlKeywordSearchList.getCurrent();
572 
573  @Override
574  public int getColumnCount() {
575  return 1;
576  }
577 
578  @Override
579  public int getRowCount() {
580  return listsHandle.getNumberLists(false);
581  }
582 
583  @Override
584  public String getColumnName(int column) {
585  return NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.getColName.text");
586  }
587 
588  @Override
589  public Object getValueAt(int rowIndex, int columnIndex) {
590  return listsHandle.getListNames(false).get(rowIndex);
591  }
592 
593  @Override
594  public boolean isCellEditable(int rowIndex, int columnIndex) {
595  return false;
596  }
597 
598  @Override
599  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
600  throw new UnsupportedOperationException(
601  NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.setValueAt.exception.msg"));
602  }
603 
604  @Override
605  public Class<?> getColumnClass(int c) {
606  return getValueAt(0, c).getClass();
607  }
608 
609  //delete selected from handle, events are fired from the handle
610  void deleteSelected(int[] selected) {
611  List<String> toDel = new ArrayList<>();
612  for (int i : selected) {
613  toDel.add(getValueAt(i, 0).toString());
614  }
615  for (String del : toDel) {
616  listsHandle.deleteList(del);
617  }
618  }
619 
620  //resync model from handle, then update table
621  void resync() {
622  fireTableDataChanged();
623  }
624  }
625 
626  void addListSelectionListener(ListSelectionListener l) {
627  listsTable.getSelectionModel().addListSelectionListener(l);
628  }
629 }

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