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

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.