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

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