Autopsy  4.10.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
FilesIdentifierIngestJobSettingsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-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.modules.interestingitems;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Observable;
24 import java.util.Observer;
25 import java.util.TreeMap;
26 import javax.swing.JTable;
27 import javax.swing.table.AbstractTableModel;
28 import javax.swing.table.TableColumn;
29 import org.openide.util.NbBundle.Messages;
33 
37 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
38 final class FilesIdentifierIngestJobSettingsPanel extends IngestModuleIngestJobSettingsPanel implements Observer {
39 
40  @Messages({
41  "FilesIdentifierIngestJobSettingsPanel.updateError=Error updating interesting files sets settings file.",
42  "FilesIdentifierIngestJobSettingsPanel.getError=Error getting interesting files sets from settings file."
43  })
44 
45  private final FilesSetsTableModel tableModel;
46 
47  // This map of interesting interesting files set names to files sets is used
48  // both to sort interesting files sets by name and to detect when a new
49  // files set is defined, so that the new set can be enabled by default.
50  private TreeMap<String, FilesSet> filesSetSnapshot;
51 
59  static FilesIdentifierIngestJobSettingsPanel makePanel(FilesIdentifierIngestJobSettings settings) {
60  FilesIdentifierIngestJobSettingsPanel panel = new FilesIdentifierIngestJobSettingsPanel(settings);
61 
62  // Observe the interesting item definitions manager for changes to the
63  // interesting file set definitions. This is used to keep this panel in
64  // synch with changes made using the global settings/option panel for
65  // this module.
66  FilesSetsManager.getInstance().addObserver(panel);
67 
68  return panel;
69  }
70 
75  private FilesIdentifierIngestJobSettingsPanel(FilesIdentifierIngestJobSettings settings) {
76  initComponents();
77 
78  /*
79  * Make a table row object for each interesting files set, bundling the
80  * set with an enabled flag. The files sets are loaded into a tree map
81  * so they are sorted by name. The keys set also serves as a cache of
82  * set names so that new sets can be easily detected in the override of
83  * Observer.update().
84  */
85  List<FilesSetRow> filesSetRows = new ArrayList<>();
86  try {
87  this.filesSetSnapshot = new TreeMap<>(FilesSetsManager.getInstance().getInterestingFilesSets());
88  } catch (FilesSetsManager.FilesSetsManagerException ex) {
89  MessageNotifyUtil.Message.error(Bundle.FilesIdentifierIngestJobSettingsPanel_getError());
90  this.filesSetSnapshot = new TreeMap<>();
91  }
92  for (FilesSet set : this.filesSetSnapshot.values()) {
93  filesSetRows.add(new FilesSetRow(set, settings.interestingFilesSetIsEnabled(set.getName())));
94  }
95 
96  // Make a table model to manage the row objects.
97  this.tableModel = new FilesSetsTableModel(filesSetRows);
98 
99  // Set up the table component that presents the table model that allows
100  // users to enable and disable interesting files set definitions for an
101  // ingest job.
102  this.filesSetTable.setModel(tableModel);
103  this.filesSetTable.setTableHeader(null);
104  this.filesSetTable.setRowSelectionAllowed(false);
105  final int width = this.filesSetScrollPane.getPreferredSize().width;
106  this.filesSetTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
107  TableColumn column;
108  for (int i = 0; i < this.filesSetTable.getColumnCount(); i++) {
109  column = this.filesSetTable.getColumnModel().getColumn(i);
110  if (i == 0) {
111  column.setPreferredWidth(((int) (width * 0.07)));
112  } else {
113  column.setPreferredWidth(((int) (width * 0.92)));
114  }
115  }
116  }
117 
118  @Override
119  public IngestModuleIngestJobSettings getSettings() {
120  List<String> enabledInterestingFilesSets = new ArrayList<>();
121  List<String> disabledInterestingFilesSets = new ArrayList<>();
122  for (FilesSetRow rowModel : this.tableModel.filesSetRows) {
123  if (rowModel.isEnabled()) {
124  enabledInterestingFilesSets.add(rowModel.getFilesSet().getName());
125  } else {
126  disabledInterestingFilesSets.add(rowModel.getFilesSet().getName());
127  }
128  }
129  return new FilesIdentifierIngestJobSettings(enabledInterestingFilesSets, disabledInterestingFilesSets);
130  }
131 
132  @Override
133  public void update(Observable o, Object arg
134  ) {
135  // Get the user's current enabled/disabled settings.
136  FilesIdentifierIngestJobSettings settings = (FilesIdentifierIngestJobSettings) this.getSettings();
137 
138  // Refresh the view of the interesting files set definitions.
139  List<FilesSetRow> rowModels = new ArrayList<>();
140  TreeMap<String, FilesSet> newFilesSetSnapshot;
141  try {
142  newFilesSetSnapshot = new TreeMap<>(FilesSetsManager.getInstance().getInterestingFilesSets());
143  } catch (FilesSetsManager.FilesSetsManagerException ex) {
144  MessageNotifyUtil.Message.error(Bundle.FilesIdentifierIngestJobSettingsPanel_updateError());
145  return;
146  }
147  for (FilesSet set : newFilesSetSnapshot.values()) {
148  if (this.filesSetSnapshot.keySet().contains(set.getName())) {
149  // Preserve the current enabled/diabled state of the set.
150  rowModels.add(new FilesSetRow(set, settings.interestingFilesSetIsEnabled(set.getName())));
151  } else {
152  // New sets are enabled by default.
153  rowModels.add(new FilesSetRow(set, true));
154  }
155  }
156  this.tableModel.resetTableData(rowModels);
157 
158  // Cache the snapshot so it will be avaialble for the next update.
159  this.filesSetSnapshot = newFilesSetSnapshot;
160  }
161 
166  private final static class FilesSetsTableModel extends AbstractTableModel {
167 
168  private List<FilesSetRow> filesSetRows;
169 
178  FilesSetsTableModel(List<FilesSetRow> filesSetRows) {
179  this.filesSetRows = filesSetRows;
180  }
181 
188  void resetTableData(List<FilesSetRow> filesSetRows) {
189  this.filesSetRows = filesSetRows;
190  this.fireTableDataChanged();
191  }
192 
193  @Override
194  public int getRowCount() {
195  return this.filesSetRows.size();
196  }
197 
198  @Override
199  public int getColumnCount() {
200  return 2;
201  }
202 
203  @Override
204  public Object getValueAt(int rowIndex, int columnIndex) {
205  if (columnIndex == 0) {
206  return this.filesSetRows.get(rowIndex).isEnabled();
207  } else {
208  return this.filesSetRows.get(rowIndex).getFilesSet().getName();
209  }
210  }
211 
212  @Override
213  public boolean isCellEditable(int rowIndex, int columnIndex) {
214  return (columnIndex == 0);
215  }
216 
217  @Override
218  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
219  if (columnIndex == 0) {
220  this.filesSetRows.get(rowIndex).setEnabled((Boolean) aValue);
221  }
222  }
223 
224  @Override
225  public Class<?> getColumnClass(int c) {
226  return getValueAt(0, c).getClass();
227  }
228  }
229 
233  private final static class FilesSetRow {
234 
235  private final FilesSet set;
236  private boolean enabled;
237 
238  FilesSetRow(FilesSet set, boolean enabled) {
239  this.set = set;
240  this.enabled = enabled;
241  }
242 
243  FilesSet getFilesSet() {
244  return this.set;
245  }
246 
247  boolean isEnabled() {
248  return this.enabled;
249  }
250 
251  void setEnabled(boolean enabled) {
252  this.enabled = enabled;
253  }
254  }
255 
261  @SuppressWarnings("unchecked")
262  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
263  private void initComponents() {
264 
265  filesSetScrollPane = new javax.swing.JScrollPane();
266  filesSetTable = new javax.swing.JTable();
267 
268  setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(FilesIdentifierIngestJobSettingsPanel.class, "FilesIdentifierIngestJobSettingsPanel.border.title"))); // NOI18N
269 
270  filesSetTable.setBackground(new java.awt.Color(240, 240, 240));
271  filesSetTable.setModel(new javax.swing.table.DefaultTableModel(
272  new Object [][] {
273 
274  },
275  new String [] {
276 
277  }
278  ));
279  filesSetTable.setShowHorizontalLines(false);
280  filesSetTable.setShowVerticalLines(false);
281  filesSetScrollPane.setViewportView(filesSetTable);
282 
283  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
284  this.setLayout(layout);
285  layout.setHorizontalGroup(
286  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
287  .addGroup(layout.createSequentialGroup()
288  .addContainerGap()
289  .addComponent(filesSetScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
290  .addContainerGap())
291  );
292  layout.setVerticalGroup(
293  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
294  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
295  .addContainerGap()
296  .addComponent(filesSetScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
297  .addContainerGap())
298  );
299  }// </editor-fold>//GEN-END:initComponents
300 
301  // Variables declaration - do not modify//GEN-BEGIN:variables
302  private javax.swing.JScrollPane filesSetScrollPane;
303  private javax.swing.JTable filesSetTable;
304  // End of variables declaration//GEN-END:variables
305 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.