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-2016 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.event.KeyEvent;
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.List;
25 import javax.swing.JFileChooser;
26 import javax.swing.JOptionPane;
27 import javax.swing.event.ListSelectionEvent;
28 import javax.swing.event.ListSelectionListener;
29 import javax.swing.filechooser.FileNameExtensionFilter;
30 import javax.swing.table.AbstractTableModel;
31 import org.netbeans.spi.options.OptionsPanelController;
32 import org.openide.util.NbBundle;
35 
39 class GlobalListsManagementPanel extends javax.swing.JPanel implements OptionsPanel {
40 
41  private static final long serialVersionUID = 1L;
42 
43  private final Logger logger = Logger.getLogger(GlobalListsManagementPanel.class.getName());
44  private final KeywordListTableModel tableModel;
45  private final org.sleuthkit.autopsy.keywordsearch.GlobalListSettingsPanel globalListSettingsPanel;
46 
47  GlobalListsManagementPanel(org.sleuthkit.autopsy.keywordsearch.GlobalListSettingsPanel gsp) {
48  this.globalListSettingsPanel = gsp;
49  tableModel = new KeywordListTableModel();
50  initComponents();
51  customizeComponents();
52  }
53 
54  private void customizeComponents() {
55  listsTable.setAutoscrolls(true);
56  listsTable.setTableHeader(null);
57  listsTable.setShowHorizontalLines(false);
58  listsTable.setShowVerticalLines(false);
59 
60  listsTable.getParent().setBackground(listsTable.getBackground());
61 
62  listsTable.setCellSelectionEnabled(false);
63  listsTable.setRowSelectionAllowed(true);
64  tableModel.resync();
65 
66  listsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
67  @Override
68  public void valueChanged(ListSelectionEvent e) {
69  globalListSettingsPanel.setFocusOnKeywordTextBox();
70  }
71  });
72  /*
73  * XmlKeywordSearchList.getCurrent().addPropertyChangeListener(new
74  * PropertyChangeListener() {
75  *
76  * @Override public void propertyChange(PropertyChangeEvent evt) { if
77  * (evt.getPropertyName().equals(XmlKeywordSearchList.ListsEvt.LIST_ADDED.toString()))
78  * { tableModel.resync(); for(int i = 0; i<listsTable.getRowCount();
79  * i++) { String name = (String) listsTable.getValueAt(i, 0);
80  * if(((String) evt.getNewValue()).equals(name)) {
81  * listsTable.getSelectionModel().setSelectionInterval(i, i); } } } else
82  * if
83  * (evt.getPropertyName().equals(XmlKeywordSearchList.ListsEvt.LIST_DELETED.toString()))
84  * { tableModel.resync(); if(listsTable.getRowCount() > 0) {
85  * listsTable.getSelectionModel().setSelectionInterval(0, 0); } else {
86  * listsTable.getSelectionModel().clearSelection(); } } } });
87  */
88  }
89 
95  @SuppressWarnings("unchecked")
96  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
97  private void initComponents() {
98 
99  jScrollPane1 = new javax.swing.JScrollPane();
100  listsTable = new javax.swing.JTable();
101  newListButton = new javax.swing.JButton();
102  importButton = new javax.swing.JButton();
103  keywordListsLabel = new javax.swing.JLabel();
104 
105  setMinimumSize(new java.awt.Dimension(250, 0));
106 
107  listsTable.setModel(tableModel);
108  listsTable.setMaximumSize(new java.awt.Dimension(30000, 30000));
109  listsTable.setShowHorizontalLines(false);
110  listsTable.setShowVerticalLines(false);
111  listsTable.getTableHeader().setReorderingAllowed(false);
112  listsTable.addKeyListener(new java.awt.event.KeyAdapter() {
113  public void keyPressed(java.awt.event.KeyEvent evt) {
114  listsTableKeyPressed(evt);
115  }
116  });
117  jScrollPane1.setViewportView(listsTable);
118 
119  newListButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/new16.png"))); // NOI18N
120  newListButton.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.newListButton.text")); // NOI18N
121  newListButton.addActionListener(new java.awt.event.ActionListener() {
122  public void actionPerformed(java.awt.event.ActionEvent evt) {
123  newListButtonActionPerformed(evt);
124  }
125  });
126 
127  importButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/import16.png"))); // NOI18N
128  importButton.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.importButton.text")); // NOI18N
129  importButton.addActionListener(new java.awt.event.ActionListener() {
130  public void actionPerformed(java.awt.event.ActionEvent evt) {
131  importButtonActionPerformed(evt);
132  }
133  });
134 
135  keywordListsLabel.setText(org.openide.util.NbBundle.getMessage(GlobalListsManagementPanel.class, "GlobalListsManagementPanel.keywordListsLabel.text")); // NOI18N
136 
137  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
138  this.setLayout(layout);
139  layout.setHorizontalGroup(
140  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
141  .addGroup(layout.createSequentialGroup()
142  .addContainerGap()
143  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
144  .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
145  .addGroup(layout.createSequentialGroup()
146  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
147  .addComponent(keywordListsLabel)
148  .addGroup(layout.createSequentialGroup()
149  .addComponent(newListButton, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
150  .addGap(18, 18, 18)
151  .addComponent(importButton, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)))
152  .addGap(0, 0, Short.MAX_VALUE)))
153  .addContainerGap())
154  );
155  layout.setVerticalGroup(
156  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
157  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
158  .addContainerGap()
159  .addComponent(keywordListsLabel)
160  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
161  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 355, Short.MAX_VALUE)
162  .addGap(5, 5, 5)
163  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
164  .addComponent(newListButton)
165  .addComponent(importButton))
166  .addContainerGap())
167  );
168  }// </editor-fold>//GEN-END:initComponents
169 
170  private void newListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newListButtonActionPerformed
171  XmlKeywordSearchList writer = XmlKeywordSearchList.getCurrent();
172  String listName = (String) JOptionPane.showInputDialog(null, NbBundle.getMessage(this.getClass(), "KeywordSearch.newKwListTitle"),
173  NbBundle.getMessage(this.getClass(), "KeywordSearch.newKeywordListMsg"), JOptionPane.PLAIN_MESSAGE, null, null, "");
174  if (listName == null || listName.trim().equals("")) {
175  return;
176  }
177  boolean shouldAdd = false;
178  if (writer.listExists(listName)) {
179  if (writer.getList(listName).isEditable()) {
180  boolean replace = KeywordSearchUtil.displayConfirmDialog(
181  NbBundle.getMessage(this.getClass(), "KeywordSearch.newKeywordListMsg"),
182  NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.newKeywordListDescription", listName),
183  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
184  if (replace) {
185  shouldAdd = true;
186  }
187  } else {
188  boolean replace = KeywordSearchUtil.displayConfirmDialog(
189  NbBundle.getMessage(this.getClass(), "KeywordSearch.newKeywordListMsg"),
190  NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.newKeywordListDescription2", listName),
191  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
192  if (replace) {
193  shouldAdd = true;
194  }
195  }
196  } else {
197  shouldAdd = true;
198  }
199  if (shouldAdd) {
200  writer.addList(listName, new ArrayList<Keyword>());
201  }
202  tableModel.resync();
203 
204  //This loop selects the recently ADDED keywordslist in the JTable
205  for (int i = 0; i < listsTable.getRowCount(); i++) {
206  if (listsTable.getValueAt(i, 0).equals(listName)) {
207  listsTable.getSelectionModel().addSelectionInterval(i, i);
208  }
209  }
210  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
211  globalListSettingsPanel.setFocusOnKeywordTextBox();
212  }//GEN-LAST:event_newListButtonActionPerformed
213 
214  private void importButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importButtonActionPerformed
215 
216  JFileChooser chooser = new JFileChooser();
217  final String[] AUTOPSY_EXTENSIONS = new String[]{"xml"}; //NON-NLS
218  final String[] ENCASE_EXTENSIONS = new String[]{"txt"}; //NON-NLS
219  FileNameExtensionFilter autopsyFilter = new FileNameExtensionFilter(
220  NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.fileExtensionFilterLbl"), AUTOPSY_EXTENSIONS);
221  FileNameExtensionFilter encaseFilter = new FileNameExtensionFilter(
222  NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.fileExtensionFilterLb2"), ENCASE_EXTENSIONS);
223  chooser.addChoosableFileFilter(autopsyFilter);
224  chooser.addChoosableFileFilter(encaseFilter);
225  chooser.setAcceptAllFileFilterUsed(false);
226  chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
227 
228  String listName = null;
229  int returnVal = chooser.showOpenDialog(this);
230  if (returnVal == JFileChooser.APPROVE_OPTION) {
231  File selFile = chooser.getSelectedFile();
232  if (selFile == null) {
233  return;
234  }
235 
236  //force append extension if not given
237  String fileAbs = selFile.getAbsolutePath();
238 
239  final KeywordSearchList reader;
240 
241  if (KeywordSearchUtil.isXMLList(fileAbs)) {
242  reader = new XmlKeywordSearchList(fileAbs);
243  } else {
244  reader = new EnCaseKeywordSearchList(fileAbs);
245  }
246 
247  if (!reader.load()) {
248  KeywordSearchUtil.displayDialog(
249  NbBundle.getMessage(this.getClass(), "KeywordSearch.listImportFeatureTitle"), NbBundle.getMessage(this.getClass(), "KeywordSearch.importListFileDialogMsg", fileAbs), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
250  return;
251  }
252 
253  List<KeywordList> toImport = reader.getListsL();
254  List<KeywordList> toImportConfirmed = new ArrayList<KeywordList>();
255 
256  final XmlKeywordSearchList writer = XmlKeywordSearchList.getCurrent();
257 
258  for (KeywordList list : toImport) {
259  //check name collisions
260  listName = list.getName();
261  if (writer.listExists(listName)) {
262  Object[] options = {NbBundle.getMessage(this.getClass(), "KeywordSearch.yesOwMsg"),
263  NbBundle.getMessage(this.getClass(), "KeywordSearch.noSkipMsg"),
264  NbBundle.getMessage(this.getClass(), "KeywordSearch.cancelImportMsg")};
265  int choice = JOptionPane.showOptionDialog(this,
266  NbBundle.getMessage(this.getClass(), "KeywordSearch.overwriteListPrompt", listName),
267  NbBundle.getMessage(this.getClass(), "KeywordSearch.importOwConflict"),
268  JOptionPane.YES_NO_CANCEL_OPTION,
269  JOptionPane.QUESTION_MESSAGE,
270  null,
271  options,
272  options[0]);
273  if (choice == JOptionPane.OK_OPTION) {
274  toImportConfirmed.add(list);
275  } else if (choice == JOptionPane.CANCEL_OPTION) {
276  break;
277  }
278 
279  } else {
280  //no conflict
281  toImportConfirmed.add(list);
282  }
283 
284  }
285 
286  if (toImportConfirmed.isEmpty()) {
287  return;
288  }
289 
290  if (!writer.writeLists(toImportConfirmed)) {
291  KeywordSearchUtil.displayDialog(
292  NbBundle.getMessage(this.getClass(), "KeywordSearch.listImportFeatureTitle"), NbBundle.getMessage(this.getClass(), "KeywordSearch.kwListFailImportMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
293  }
294 
295  }
296  tableModel.resync();
297 
298  //This loop selects the recently IMPORTED keywordslist in the JTable
299  if (listName != null) {
300  for (int i = 0; i < listsTable.getRowCount(); i++) {
301  if (listsTable.getValueAt(i, 0).equals(listName)) {
302  listsTable.getSelectionModel().addSelectionInterval(i, i);
303  }
304  }
305  }
306  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
307  }//GEN-LAST:event_importButtonActionPerformed
308  private void listsTableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_listsTableKeyPressed
309  if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
310  int[] selected = listsTable.getSelectedRows();
311  if (selected.length == 0) {
312  return;
313  } else if (KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.title"), NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.body"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
314  String listName = (String) listsTable.getModel().getValueAt(selected[0], 0);
315  XmlKeywordSearchList.getCurrent().deleteList(listName);
316  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
317  } else {
318  return;
319  }
320  }
321  tableModel.resync();
322  }//GEN-LAST:event_listsTableKeyPressed
323 
324  // Variables declaration - do not modify//GEN-BEGIN:variables
325  private javax.swing.JButton importButton;
326  private javax.swing.JScrollPane jScrollPane1;
327  private javax.swing.JLabel keywordListsLabel;
328  private javax.swing.JTable listsTable;
329  private javax.swing.JButton newListButton;
330  // End of variables declaration//GEN-END:variables
331 
332  @Override
333  public void store() {
334  // Implemented by parent panel
335  }
336 
337  @Override
338  public void load() {
339  listsTable.clearSelection();
340  }
341 
342  void resync() {
343  tableModel.resync();
344  }
345 
346  private class KeywordListTableModel extends AbstractTableModel {
347 
348  private final XmlKeywordSearchList listsHandle = XmlKeywordSearchList.getCurrent();
349 
350  @Override
351  public int getColumnCount() {
352  return 1;
353  }
354 
355  @Override
356  public int getRowCount() {
357  return listsHandle.getNumberLists(false);
358  }
359 
360  @Override
361  public String getColumnName(int column) {
362  return NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.getColName.text");
363  }
364 
365  @Override
366  public Object getValueAt(int rowIndex, int columnIndex) {
367  return listsHandle.getListNames(false).get(rowIndex);
368  }
369 
370  @Override
371  public boolean isCellEditable(int rowIndex, int columnIndex) {
372  return false;
373  }
374 
375  @Override
376  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
377  throw new UnsupportedOperationException(
378  NbBundle.getMessage(this.getClass(), "KeywordSearchListsManagementPanel.setValueAt.exception.msg"));
379  }
380 
381  @Override
382  public Class<?> getColumnClass(int c) {
383  return getValueAt(0, c).getClass();
384  }
385 
386  //delete selected from handle, events are fired from the handle
387  void deleteSelected(int[] selected) {
388  List<String> toDel = new ArrayList<>();
389  for (int i = 0; i < selected.length; i++) {
390  toDel.add((String) getValueAt(0, selected[i]));
391  }
392  for (String del : toDel) {
393  listsHandle.deleteList(del);
394  }
395  }
396 
397  //resync model from handle, then update table
398  void resync() {
399  fireTableDataChanged();
400  }
401  }
402 
403  void addListSelectionListener(ListSelectionListener l) {
404  listsTable.getSelectionModel().addListSelectionListener(l);
405  }
406 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

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