19 package org.sleuthkit.autopsy.modules.interestingitems;
21 import java.awt.Component;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.Observable;
25 import java.util.Observer;
26 import java.util.TreeMap;
27 import javax.swing.JLabel;
28 import javax.swing.JTable;
29 import javax.swing.table.AbstractTableModel;
30 import javax.swing.table.DefaultTableCellRenderer;
31 import javax.swing.table.TableColumn;
32 import org.openide.util.NbBundle.Messages;
40 @SuppressWarnings(
"PMD.SingularField")
41 final class FilesIdentifierIngestJobSettingsPanel extends IngestModuleIngestJobSettingsPanel implements Observer {
44 "FilesIdentifierIngestJobSettingsPanel.updateError=Error updating interesting files sets settings file.",
45 "FilesIdentifierIngestJobSettingsPanel.getError=Error getting interesting files sets from settings file."
48 private final FilesSetsTableModel tableModel;
53 private TreeMap<String, FilesSet> filesSetSnapshot;
62 static FilesIdentifierIngestJobSettingsPanel makePanel(FilesIdentifierIngestJobSettings settings) {
63 FilesIdentifierIngestJobSettingsPanel panel =
new FilesIdentifierIngestJobSettingsPanel(settings);
69 FilesSetsManager.getInstance().addObserver(panel);
78 private FilesIdentifierIngestJobSettingsPanel(FilesIdentifierIngestJobSettings settings) {
88 List<FilesSetRow> filesSetRows =
new ArrayList<>();
90 this.filesSetSnapshot =
new TreeMap<>(FilesSetsManager.getInstance().getInterestingFilesSets());
91 }
catch (FilesSetsManager.FilesSetsManagerException ex) {
92 MessageNotifyUtil.Message.error(Bundle.FilesIdentifierIngestJobSettingsPanel_getError());
93 this.filesSetSnapshot =
new TreeMap<>();
95 for (FilesSet set : this.filesSetSnapshot.values()) {
96 filesSetRows.add(
new FilesSetRow(set, settings.interestingFilesSetIsEnabled(set.getName())));
100 this.tableModel =
new FilesSetsTableModel(filesSetRows);
105 this.filesSetTable.setModel(tableModel);
106 this.filesSetTable.setTableHeader(null);
107 this.filesSetTable.setRowSelectionAllowed(
false);
108 final int width = this.filesSetScrollPane.getPreferredSize().width;
109 this.filesSetTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
111 for (
int i = 0; i < this.filesSetTable.getColumnCount(); i++) {
112 column = this.filesSetTable.getColumnModel().getColumn(i);
114 column.setPreferredWidth(((
int) (width * 0.07)));
116 column.setCellRenderer(
new FileSetsTableCellRenderer());
117 column.setPreferredWidth(((
int) (width * 0.92)));
123 public IngestModuleIngestJobSettings getSettings() {
124 List<String> enabledInterestingFilesSets =
new ArrayList<>();
125 List<String> disabledInterestingFilesSets =
new ArrayList<>();
126 for (FilesSetRow rowModel : this.tableModel.filesSetRows) {
127 if (rowModel.isEnabled()) {
128 enabledInterestingFilesSets.add(rowModel.getFilesSet().getName());
130 disabledInterestingFilesSets.add(rowModel.getFilesSet().getName());
133 return new FilesIdentifierIngestJobSettings(enabledInterestingFilesSets, disabledInterestingFilesSets);
137 public void update(Observable o, Object arg
140 FilesIdentifierIngestJobSettings settings = (FilesIdentifierIngestJobSettings) this.getSettings();
143 List<FilesSetRow> rowModels =
new ArrayList<>();
144 TreeMap<String, FilesSet> newFilesSetSnapshot;
146 newFilesSetSnapshot =
new TreeMap<>(FilesSetsManager.getInstance().getInterestingFilesSets());
147 }
catch (FilesSetsManager.FilesSetsManagerException ex) {
148 MessageNotifyUtil.Message.error(Bundle.FilesIdentifierIngestJobSettingsPanel_updateError());
151 for (FilesSet set : newFilesSetSnapshot.values()) {
152 if (this.filesSetSnapshot.keySet().contains(set.getName())) {
154 rowModels.add(
new FilesSetRow(set, settings.interestingFilesSetIsEnabled(set.getName())));
157 rowModels.add(
new FilesSetRow(set,
true));
160 this.tableModel.resetTableData(rowModels);
163 this.filesSetSnapshot = newFilesSetSnapshot;
171 private static final long serialVersionUID = 1L;
175 JTable table, Object value,
176 boolean isSelected,
boolean hasFocus,
177 int row,
int column) {
178 JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
179 label.setToolTipText(label.getText());
201 this.filesSetRows = filesSetRows;
210 void resetTableData(List<FilesSetRow> filesSetRows) {
211 this.filesSetRows = filesSetRows;
212 this.fireTableDataChanged();
217 return this.filesSetRows.size();
227 if (columnIndex == 0) {
228 return this.filesSetRows.get(rowIndex).isEnabled();
230 return this.filesSetRows.get(rowIndex).getFilesSet().getName();
236 return (columnIndex == 0);
240 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
241 if (columnIndex == 0) {
242 this.filesSetRows.get(rowIndex).setEnabled((Boolean) aValue);
248 return getValueAt(0, c).getClass();
262 this.enabled = enabled;
269 boolean isEnabled() {
273 void setEnabled(
boolean enabled) {
274 this.enabled = enabled;
283 @SuppressWarnings(
"unchecked")
285 private
void initComponents() {
287 filesSetScrollPane =
new javax.swing.JScrollPane();
288 filesSetTable =
new javax.swing.JTable();
290 setBorder(javax.swing.BorderFactory.createTitledBorder(
org.openide.util.NbBundle.getMessage(FilesIdentifierIngestJobSettingsPanel.class,
"FilesIdentifierIngestJobSettingsPanel.border.title")));
292 filesSetTable.setBackground(
new java.awt.Color(240, 240, 240));
293 filesSetTable.setModel(
new javax.swing.table.DefaultTableModel(
301 filesSetTable.setShowHorizontalLines(
false);
302 filesSetTable.setShowVerticalLines(
false);
303 filesSetScrollPane.setViewportView(filesSetTable);
305 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
306 this.setLayout(layout);
307 layout.setHorizontalGroup(
308 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
309 .addGroup(layout.createSequentialGroup()
311 .addComponent(filesSetScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
314 layout.setVerticalGroup(
315 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
316 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
318 .addComponent(filesSetScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
324 private javax.swing.JScrollPane filesSetScrollPane;
325 private javax.swing.JTable filesSetTable;
Class<?> getColumnClass(int c)
Object getValueAt(int rowIndex, int columnIndex)
boolean isCellEditable(int rowIndex, int columnIndex)
List< FilesSetRow > filesSetRows
Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
void setValueAt(Object aValue, int rowIndex, int columnIndex)