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

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