19 package org.sleuthkit.autopsy.modules.interestingitems;
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;
37 @SuppressWarnings(
"PMD.SingularField")
38 final class FilesIdentifierIngestJobSettingsPanel extends IngestModuleIngestJobSettingsPanel implements Observer {
41 "FilesIdentifierIngestJobSettingsPanel.updateError=Error updating interesting files sets settings file.",
42 "FilesIdentifierIngestJobSettingsPanel.getError=Error getting interesting files sets from settings file."
45 private final FilesSetsTableModel tableModel;
50 private TreeMap<String, FilesSet> filesSetSnapshot;
59 static FilesIdentifierIngestJobSettingsPanel makePanel(FilesIdentifierIngestJobSettings settings) {
60 FilesIdentifierIngestJobSettingsPanel panel =
new FilesIdentifierIngestJobSettingsPanel(settings);
66 FilesSetsManager.getInstance().addObserver(panel);
75 private FilesIdentifierIngestJobSettingsPanel(FilesIdentifierIngestJobSettings settings) {
85 List<FilesSetRow> filesSetRows =
new ArrayList<>();
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<>();
92 for (FilesSet set : this.filesSetSnapshot.values()) {
93 filesSetRows.add(
new FilesSetRow(set, settings.interestingFilesSetIsEnabled(set.getName())));
97 this.tableModel =
new FilesSetsTableModel(filesSetRows);
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);
108 for (
int i = 0; i < this.filesSetTable.getColumnCount(); i++) {
109 column = this.filesSetTable.getColumnModel().getColumn(i);
111 column.setPreferredWidth(((
int) (width * 0.07)));
113 column.setPreferredWidth(((
int) (width * 0.92)));
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());
126 disabledInterestingFilesSets.add(rowModel.getFilesSet().getName());
129 return new FilesIdentifierIngestJobSettings(enabledInterestingFilesSets, disabledInterestingFilesSets);
133 public void update(Observable o, Object arg
136 FilesIdentifierIngestJobSettings settings = (FilesIdentifierIngestJobSettings) this.getSettings();
139 List<FilesSetRow> rowModels =
new ArrayList<>();
140 TreeMap<String, FilesSet> newFilesSetSnapshot;
142 newFilesSetSnapshot =
new TreeMap<>(FilesSetsManager.getInstance().getInterestingFilesSets());
143 }
catch (FilesSetsManager.FilesSetsManagerException ex) {
144 MessageNotifyUtil.Message.error(Bundle.FilesIdentifierIngestJobSettingsPanel_updateError());
147 for (FilesSet set : newFilesSetSnapshot.values()) {
148 if (this.filesSetSnapshot.keySet().contains(set.getName())) {
150 rowModels.add(
new FilesSetRow(set, settings.interestingFilesSetIsEnabled(set.getName())));
153 rowModels.add(
new FilesSetRow(set,
true));
156 this.tableModel.resetTableData(rowModels);
159 this.filesSetSnapshot = newFilesSetSnapshot;
179 this.filesSetRows = filesSetRows;
188 void resetTableData(List<FilesSetRow> filesSetRows) {
189 this.filesSetRows = filesSetRows;
190 this.fireTableDataChanged();
195 return this.filesSetRows.size();
205 if (columnIndex == 0) {
206 return this.filesSetRows.get(rowIndex).isEnabled();
208 return this.filesSetRows.get(rowIndex).getFilesSet().getName();
214 return (columnIndex == 0);
218 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
219 if (columnIndex == 0) {
220 this.filesSetRows.get(rowIndex).setEnabled((Boolean) aValue);
226 return getValueAt(0, c).getClass();
240 this.enabled = enabled;
247 boolean isEnabled() {
251 void setEnabled(
boolean enabled) {
252 this.enabled = enabled;
261 @SuppressWarnings(
"unchecked")
263 private
void initComponents() {
265 filesSetScrollPane =
new javax.swing.JScrollPane();
266 filesSetTable =
new javax.swing.JTable();
268 setBorder(javax.swing.BorderFactory.createTitledBorder(
org.openide.util.NbBundle.getMessage(FilesIdentifierIngestJobSettingsPanel.class,
"FilesIdentifierIngestJobSettingsPanel.border.title")));
270 filesSetTable.setBackground(
new java.awt.Color(240, 240, 240));
271 filesSetTable.setModel(
new javax.swing.table.DefaultTableModel(
279 filesSetTable.setShowHorizontalLines(
false);
280 filesSetTable.setShowVerticalLines(
false);
281 filesSetScrollPane.setViewportView(filesSetTable);
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()
289 .addComponent(filesSetScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
292 layout.setVerticalGroup(
293 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
294 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
296 .addComponent(filesSetScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
302 private javax.swing.JScrollPane filesSetScrollPane;
303 private javax.swing.JTable filesSetTable;
Class<?> getColumnClass(int c)
Object getValueAt(int rowIndex, int columnIndex)
boolean isCellEditable(int rowIndex, int columnIndex)
List< FilesSetRow > filesSetRows
void setValueAt(Object aValue, int rowIndex, int columnIndex)