From 2b528fd792fe5a8d6ec3bc904fdffac14f4b11a3 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Tue, 27 Jul 2021 11:38:59 -0400 Subject: [PATCH 1/5] 5316 hide file search by attributes instead of disposing of it. --- .../org/sleuthkit/autopsy/filesearch/FileSearchAction.java | 6 ++++-- .../org/sleuthkit/autopsy/filesearch/FileSearchDialog.java | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java index fb66a4b6d7..334c6d1a56 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java @@ -31,9 +31,11 @@ final class FileSearchAction extends CallableSystemAction implements FileSearchP private static final long serialVersionUID = 1L; private static FileSearchAction instance = null; + private static final FileSearchDialog searchDialog = new FileSearchDialog(); FileSearchAction() { super(); + searchDialog.setVisible(false); setEnabled(Case.isCaseOpen()); Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> { if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) { @@ -51,12 +53,12 @@ final class FileSearchAction extends CallableSystemAction implements FileSearchP @Override public void actionPerformed(ActionEvent e) { - new FileSearchDialog().setVisible(true); + searchDialog.setVisible(true); } @Override public void performAction() { - new FileSearchDialog().setVisible(true); + searchDialog.setVisible(true); } @Override diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java index 0ef884aaa5..de5642496e 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java @@ -27,12 +27,12 @@ import org.openide.windows.WindowManager; * File search dialog */ @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives -class FileSearchDialog extends javax.swing.JDialog { +final class FileSearchDialog extends javax.swing.JDialog { /** * Creates new form FileSearchDialog */ - public FileSearchDialog() { + FileSearchDialog() { super(WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(FileSearchDialog.class, "FileSearchDialog.frame.msg"), true); initComponents(); @@ -43,7 +43,7 @@ class FileSearchDialog extends javax.swing.JDialog { @Override public void actionPerformed(ActionEvent e) { - dispose(); + setVisible(false); } }); } From e058d70f5ffb0713110d2fec281fd87096d0a356 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Tue, 27 Jul 2021 11:57:21 -0400 Subject: [PATCH 2/5] 5316 initialize filesearch dialog on EDT --- .../autopsy/filesearch/FileSearchAction.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java index 334c6d1a56..da89cea697 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2017 Basis Technology Corp. + * Copyright 2011-2021 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,11 +31,10 @@ final class FileSearchAction extends CallableSystemAction implements FileSearchP private static final long serialVersionUID = 1L; private static FileSearchAction instance = null; - private static final FileSearchDialog searchDialog = new FileSearchDialog(); + private static FileSearchDialog searchDialog; FileSearchAction() { super(); - searchDialog.setVisible(false); setEnabled(Case.isCaseOpen()); Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> { if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) { @@ -53,11 +52,18 @@ final class FileSearchAction extends CallableSystemAction implements FileSearchP @Override public void actionPerformed(ActionEvent e) { + if (searchDialog == null) { + searchDialog = new FileSearchDialog(); + + } searchDialog.setVisible(true); } @Override public void performAction() { + if (searchDialog == null) { + searchDialog = new FileSearchDialog(); + } searchDialog.setVisible(true); } From fd2fd11468f84b69a8763bde5d3ed3277ccd17a5 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Tue, 27 Jul 2021 15:46:34 -0400 Subject: [PATCH 3/5] 5316 fix reseting of case dependent filters when case changes --- .../autopsy/filesearch/DataSourceFilter.java | 15 ++++- .../autopsy/filesearch/DataSourcePanel.form | 2 +- .../autopsy/filesearch/DataSourcePanel.java | 29 ++++++++- .../autopsy/filesearch/FileSearchAction.java | 9 ++- .../autopsy/filesearch/FileSearchDialog.java | 17 ++++-- .../autopsy/filesearch/FileSearchPanel.java | 61 +++++++++++-------- .../autopsy/filesearch/MimeTypeFilter.java | 7 +++ .../autopsy/filesearch/MimeTypePanel.java | 14 +++++ 8 files changed, 117 insertions(+), 37 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourceFilter.java b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourceFilter.java index 4ef41b78d8..249b2690b6 100755 --- a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourceFilter.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourceFilter.java @@ -28,6 +28,7 @@ class DataSourceFilter extends AbstractFileSearchFilter { /** * Construct DataSourceFilter with the DataSourcePanel + * * @param component A DataSourcePanel */ public DataSourceFilter(DataSourcePanel component) { @@ -35,7 +36,8 @@ class DataSourceFilter extends AbstractFileSearchFilter { } /** - * Default constructor to construct a new DataSourceFilter with a new DataSourcePanel + * Default constructor to construct a new DataSourceFilter with a new + * DataSourcePanel */ public DataSourceFilter() { this(new DataSourcePanel()); @@ -46,6 +48,13 @@ class DataSourceFilter extends AbstractFileSearchFilter { return this.getComponent().isSelected(); } + /** + * Reset the data source filter to be up to date with the current case. + */ + void resetDataSourceFilter() { + this.getComponent().resetDataSourcePanel(); + } + @Override public String getPredicate() throws FilterValidationException { String predicate = ""; @@ -64,11 +73,11 @@ class DataSourceFilter extends AbstractFileSearchFilter { } @Override - @Messages ({ + @Messages({ "DataSourceFilter.errorMessage.emptyDataSource=At least one data source must be selected." }) public boolean isValid() { - if(this.getComponent().getDataSourcesSelected().isEmpty()){ + if (this.getComponent().getDataSourcesSelected().isEmpty()) { setLastError(Bundle.DataSourceFilter_errorMessage_emptyDataSource()); return false; } diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.form b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.form index 283454c4c3..0a3fc40c78 100755 --- a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.form +++ b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.form @@ -65,7 +65,7 @@ - + diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.java b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.java index 28fae71c5b..baeb6df5cb 100755 --- a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.logging.Level; +import javax.swing.DefaultListModel; import javax.swing.event.ListSelectionEvent; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; @@ -91,6 +92,32 @@ public class DataSourcePanel extends javax.swing.JPanel { return dsList; } + /** + * Reset the data source panel to be up to date with the current case. + * + */ + void resetDataSourcePanel() { + ((DefaultListModel) dataSourceList.getModel()).removeAllElements(); + dataSourceMap.clear(); + for (String dataSource : getDataSourceArray()) { + ((DefaultListModel) dataSourceList.getModel()).addElement(dataSource); + } + this.dataSourceList.setEnabled(false); + dataSourceCheckBox.setSelected(false); + dataSourceNoteLabel.setEnabled(false); + if (this.dataSourceList.getModel().getSize() > 1) { + this.dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> { + firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null); + }); + } else { + /* + * Disable data source filtering since there aren't multiple data + * sources to choose from. + */ + this.dataSourceCheckBox.setEnabled(false); + } + } + /** * Get a set of data source object ids that are selected. * @@ -145,7 +172,7 @@ public class DataSourcePanel extends javax.swing.JPanel { setMinimumSize(new java.awt.Dimension(150, 150)); setPreferredSize(new java.awt.Dimension(150, 150)); - dataSourceList.setModel(new javax.swing.AbstractListModel() { + dataSourceList.setModel(new DefaultListModel() { List strings = getDataSourceArray(); public int getSize() { return strings.size(); } public String getElementAt(int idx) { return strings.get(idx); } diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java index da89cea697..c814496ee4 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java @@ -32,6 +32,7 @@ final class FileSearchAction extends CallableSystemAction implements FileSearchP private static final long serialVersionUID = 1L; private static FileSearchAction instance = null; private static FileSearchDialog searchDialog; + private static boolean shouldReset = false; FileSearchAction() { super(); @@ -39,6 +40,7 @@ final class FileSearchAction extends CallableSystemAction implements FileSearchP Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> { if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) { setEnabled(evt.getNewValue() != null); + shouldReset = evt.getNewValue() != null; } }); } @@ -54,7 +56,9 @@ final class FileSearchAction extends CallableSystemAction implements FileSearchP public void actionPerformed(ActionEvent e) { if (searchDialog == null) { searchDialog = new FileSearchDialog(); - + } else if (shouldReset) { + searchDialog.resetCaseDependentFilters(); + shouldReset = false; } searchDialog.setVisible(true); } @@ -63,6 +67,9 @@ final class FileSearchAction extends CallableSystemAction implements FileSearchP public void performAction() { if (searchDialog == null) { searchDialog = new FileSearchDialog(); + } else if (shouldReset) { + searchDialog.resetCaseDependentFilters(); + shouldReset = false; } searchDialog.setVisible(true); } diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java index de5642496e..01217f7008 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java @@ -1,15 +1,15 @@ /* * Autopsy Forensic Browser - * + * * Copyright 2011-2018 Basis Technology Corp. * Contact: carrier sleuthkit org - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -48,6 +48,14 @@ final class FileSearchDialog extends javax.swing.JDialog { }); } + /** + * Reset the filters which are populated with options based on the contents + * of the current case. + */ + void resetCaseDependentFilters() { + fileSearchPanel1.resetCaseDependentFilters(); + } + /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always @@ -79,4 +87,3 @@ final class FileSearchDialog extends javax.swing.JDialog { private org.sleuthkit.autopsy.filesearch.FileSearchPanel fileSearchPanel1; // End of variables declaration//GEN-END:variables } - diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java index 4801227416..9e41160382 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java @@ -1,15 +1,15 @@ /* * Autopsy Forensic Browser - * + * * Copyright 2011-2019 Basis Technology Corp. * Contact: carrier sleuthkit org - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -58,6 +58,8 @@ class FileSearchPanel extends javax.swing.JPanel { private final List filters = new ArrayList<>(); private static int resultWindowCount = 0; //keep track of result windows so they get unique names + private static final MimeTypeFilter mimeTypeFilter = new MimeTypeFilter(); + private static final DataSourceFilter dataSourceFilter = new DataSourceFilter(); private static final String EMPTY_WHERE_CLAUSE = NbBundle.getMessage(DateSearchFilter.class, "FileSearchPanel.emptyWhereClause.text"); enum EVENT { @@ -77,39 +79,37 @@ class FileSearchPanel extends javax.swing.JPanel { * This method is called from within the constructor to initialize the form. */ private void customizeComponents() { - + JLabel label = new JLabel(NbBundle.getMessage(this.getClass(), "FileSearchPanel.custComp.label.text")); label.setAlignmentX(Component.LEFT_ALIGNMENT); label.setBorder(new EmptyBorder(0, 0, 10, 0)); - + JPanel panel1 = new JPanel(); - panel1.setLayout(new GridLayout(1,2)); + panel1.setLayout(new GridLayout(1, 2)); panel1.add(new JLabel("")); JPanel panel2 = new JPanel(); - panel2.setLayout(new GridLayout(1,2, 20, 0)); + panel2.setLayout(new GridLayout(1, 2, 20, 0)); JPanel panel3 = new JPanel(); - panel3.setLayout(new GridLayout(1,2, 20, 0)); + panel3.setLayout(new GridLayout(1, 2, 20, 0)); JPanel panel4 = new JPanel(); - panel4.setLayout(new GridLayout(1,2, 20, 0)); + panel4.setLayout(new GridLayout(1, 2, 20, 0)); JPanel panel5 = new JPanel(); - panel5.setLayout(new GridLayout(1,2, 20, 0)); + panel5.setLayout(new GridLayout(1, 2, 20, 0)); // Create and add filter areas - NameSearchFilter nameFilter = new NameSearchFilter(); + NameSearchFilter nameFilter = new NameSearchFilter(); SizeSearchFilter sizeFilter = new SizeSearchFilter(); DateSearchFilter dateFilter = new DateSearchFilter(); KnownStatusSearchFilter knowStatusFilter = new KnownStatusSearchFilter(); HashSearchFilter hashFilter = new HashSearchFilter(); - MimeTypeFilter mimeTypeFilter = new MimeTypeFilter(); - DataSourceFilter dataSourceFilter = new DataSourceFilter(); - - panel2.add(new FilterArea(NbBundle.getMessage(this.getClass(), "FileSearchPanel.filterTitle.name"),nameFilter)); - - panel3.add(new FilterArea(NbBundle.getMessage(this.getClass(), "FileSearchPanel.filterTitle.metadata"),sizeFilter)); - - panel2.add(new FilterArea(NbBundle.getMessage(this.getClass(), "FileSearchPanel.filterTitle.metadata"), dateFilter)); + + panel2.add(new FilterArea(NbBundle.getMessage(this.getClass(), "FileSearchPanel.filterTitle.name"), nameFilter)); + + panel3.add(new FilterArea(NbBundle.getMessage(this.getClass(), "FileSearchPanel.filterTitle.metadata"), sizeFilter)); + + panel2.add(new FilterArea(NbBundle.getMessage(this.getClass(), "FileSearchPanel.filterTitle.metadata"), dateFilter)); panel3.add(new FilterArea(NbBundle.getMessage(this.getClass(), "FileSearchPanel.filterTitle.knownStatus"), knowStatusFilter)); - + panel5.add(new FilterArea(NbBundle.getMessage(this.getClass(), "HashSearchPanel.md5CheckBox.text"), hashFilter)); panel5.add(new JLabel("")); panel4.add(new FilterArea(NbBundle.getMessage(this.getClass(), "FileSearchPanel.filterTitle.metadata"), mimeTypeFilter)); @@ -119,7 +119,7 @@ class FileSearchPanel extends javax.swing.JPanel { filterPanel.add(panel3); filterPanel.add(panel4); filterPanel.add(panel5); - + filters.add(nameFilter); filters.add(sizeFilter); filters.add(dateFilter); @@ -127,7 +127,7 @@ class FileSearchPanel extends javax.swing.JPanel { filters.add(hashFilter); filters.add(mimeTypeFilter); filters.add(dataSourceFilter); - + for (FileSearchFilter filter : this.getFilters()) { filter.addPropertyChangeListener(new PropertyChangeListener() { @Override @@ -141,7 +141,7 @@ class FileSearchPanel extends javax.swing.JPanel { public void actionPerformed(ActionEvent e) { search(); } - }); + }); searchButton.setEnabled(isValidSearch()); } @@ -200,10 +200,10 @@ class FileSearchPanel extends javax.swing.JPanel { if (contentList.isEmpty()) { Node emptyNode = new TableFilterNode(new EmptyNode(Bundle.FileSearchPanel_emptyNode_display_text()), true); searchResultWin = DataResultTopComponent.createInstance(title, pathText, - emptyNode, 0); + emptyNode, 0); } else { searchResultWin = DataResultTopComponent.createInstance(title, pathText, - tableFilterNode, contentList.size()); + tableFilterNode, contentList.size()); } searchResultWin.requestActive(); // make it the active top component @@ -287,6 +287,15 @@ class FileSearchPanel extends javax.swing.JPanel { return enabledFilters; } + + /** + * Reset the filters which are populated with options based on the contents + * of the current case. + */ + void resetCaseDependentFilters() { + dataSourceFilter.resetDataSourceFilter(); + mimeTypeFilter.resetMimeTypeFilter(); + } void addListenerToAll(ActionListener l) { searchButton.addActionListener(l); diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypeFilter.java b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypeFilter.java index 89c071bfcc..8c477eb0b0 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypeFilter.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypeFilter.java @@ -53,4 +53,11 @@ class MimeTypeFilter extends AbstractFileSearchFilter { } return true; } + + /** + * Reset the mime type filter to be up to date with the current case. + */ + void resetMimeTypeFilter() { + this.getComponent().resetMimeTypePanel(); + } } diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java index 41f52825d7..f794ba8696 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java @@ -21,6 +21,7 @@ package org.sleuthkit.autopsy.filesearch; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; +import javax.swing.DefaultListModel; import javax.swing.event.ListSelectionEvent; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector; @@ -146,4 +147,17 @@ public class MimeTypePanel extends javax.swing.JPanel { private javax.swing.JList mimeTypeList; private javax.swing.JLabel noteLabel; // End of variables declaration//GEN-END:variables + + /** + * Reset the mime type panel to be up to date with the current case. + */ + void resetMimeTypePanel() { + ((DefaultListModel) mimeTypeList.getModel()).removeAllElements(); + for (String dataSource : getMimeTypeArray()) { + ((DefaultListModel) mimeTypeList.getModel()).addElement(dataSource); + } + this.mimeTypeList.setEnabled(false); + mimeTypeCheckBox.setSelected(false); + noteLabel.setEnabled(false); + } } From 62426c7e7d671418f53b979f77b5c05c331c2827 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Tue, 27 Jul 2021 15:56:57 -0400 Subject: [PATCH 4/5] 5316 fix listmodel type --- Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.form | 2 +- Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.form b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.form index 9b4044bc32..c93f84331f 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.form +++ b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.form @@ -65,7 +65,7 @@ - + diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java index f794ba8696..6d1cb66435 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java @@ -88,7 +88,7 @@ public class MimeTypePanel extends javax.swing.JPanel { setMinimumSize(new java.awt.Dimension(150, 150)); setPreferredSize(new java.awt.Dimension(150, 150)); - mimeTypeList.setModel(new javax.swing.AbstractListModel() { + mimeTypeList.setModel(new DefaultListModel() { String[] strings = getMimeTypeArray(); public int getSize() { return strings.length; } public String getElementAt(int i) { return strings[i]; } From 7809c2a839b0e5b76e0fe4a0cd9332bb43d54f04 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Fri, 30 Jul 2021 15:10:49 -0400 Subject: [PATCH 5/5] 5316 fix list models to support reseting --- .../autopsy/filesearch/DataSourceFilter.java | 6 +- .../autopsy/filesearch/DataSourcePanel.form | 2 +- .../autopsy/filesearch/DataSourcePanel.java | 63 +++++++++---------- .../autopsy/filesearch/FileSearchAction.java | 13 ++-- .../autopsy/filesearch/FileSearchPanel.java | 6 +- .../autopsy/filesearch/MimeTypeFilter.java | 31 ++++++--- .../autopsy/filesearch/MimeTypePanel.form | 2 +- .../autopsy/filesearch/MimeTypePanel.java | 28 +++++---- 8 files changed, 76 insertions(+), 75 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourceFilter.java b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourceFilter.java index 249b2690b6..fd0a232dcf 100755 --- a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourceFilter.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourceFilter.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2018 Basis Technology Corp. + * Copyright 2018-2021 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,7 +31,7 @@ class DataSourceFilter extends AbstractFileSearchFilter { * * @param component A DataSourcePanel */ - public DataSourceFilter(DataSourcePanel component) { + DataSourceFilter(DataSourcePanel component) { super(component); } @@ -39,7 +39,7 @@ class DataSourceFilter extends AbstractFileSearchFilter { * Default constructor to construct a new DataSourceFilter with a new * DataSourcePanel */ - public DataSourceFilter() { + DataSourceFilter() { this(new DataSourcePanel()); } diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.form b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.form index 0a3fc40c78..7a2e4eb458 100755 --- a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.form +++ b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.form @@ -65,7 +65,7 @@ - + diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.java b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.java index baeb6df5cb..7b19d4d5c8 100755 --- a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.java @@ -29,6 +29,7 @@ import java.util.Set; import java.util.logging.Level; import javax.swing.DefaultListModel; import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.coreutils.Logger; @@ -51,17 +52,38 @@ public class DataSourcePanel extends javax.swing.JPanel { */ public DataSourcePanel() { initComponents(); - if (this.dataSourceList.getModel().getSize() > 1) { - this.dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> { + resetDataSourcePanel(); + } + + /** + * Reset the data source panel to be up to date with the current case. + * + */ + final void resetDataSourcePanel() { + dataSourceList.clearSelection(); + //remove all list selection listeners + for (ListSelectionListener listener : dataSourceList.getListSelectionListeners()){ + dataSourceList.removeListSelectionListener(listener); + } + ((DefaultListModel) dataSourceList.getModel()).clear(); + List strings = getDataSourceArray(); + for (String dataSource : strings) { + ((DefaultListModel) dataSourceList.getModel()).addElement(dataSource); + } + dataSourceList.setEnabled(false); + dataSourceCheckBox.setSelected(false); + dataSourceNoteLabel.setEnabled(false); + if (dataSourceList.getModel().getSize() > 1) { + dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> { firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null); }); + dataSourceCheckBox.setEnabled(true); } else { /* * Disable data source filtering since there aren't multiple data * sources to choose from. */ this.dataSourceCheckBox.setEnabled(false); - this.dataSourceList.setEnabled(false); } } @@ -92,32 +114,6 @@ public class DataSourcePanel extends javax.swing.JPanel { return dsList; } - /** - * Reset the data source panel to be up to date with the current case. - * - */ - void resetDataSourcePanel() { - ((DefaultListModel) dataSourceList.getModel()).removeAllElements(); - dataSourceMap.clear(); - for (String dataSource : getDataSourceArray()) { - ((DefaultListModel) dataSourceList.getModel()).addElement(dataSource); - } - this.dataSourceList.setEnabled(false); - dataSourceCheckBox.setSelected(false); - dataSourceNoteLabel.setEnabled(false); - if (this.dataSourceList.getModel().getSize() > 1) { - this.dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> { - firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null); - }); - } else { - /* - * Disable data source filtering since there aren't multiple data - * sources to choose from. - */ - this.dataSourceCheckBox.setEnabled(false); - } - } - /** * Get a set of data source object ids that are selected. * @@ -125,9 +121,10 @@ public class DataSourcePanel extends javax.swing.JPanel { */ Set getDataSourcesSelected() { Set dataSourceObjIdSet = new HashSet<>(); + List dataSources = dataSourceList.getSelectedValuesList(); for (Long key : dataSourceMap.keySet()) { String value = dataSourceMap.get(key); - for (String dataSource : this.dataSourceList.getSelectedValuesList()) { + for (String dataSource : dataSources) { if (value.equals(dataSource)) { dataSourceObjIdSet.add(key); } @@ -172,11 +169,7 @@ public class DataSourcePanel extends javax.swing.JPanel { setMinimumSize(new java.awt.Dimension(150, 150)); setPreferredSize(new java.awt.Dimension(150, 150)); - dataSourceList.setModel(new DefaultListModel() { - List strings = getDataSourceArray(); - public int getSize() { return strings.size(); } - public String getElementAt(int idx) { return strings.get(idx); } - }); + dataSourceList.setModel(new DefaultListModel()); dataSourceList.setEnabled(false); dataSourceList.setMinimumSize(new java.awt.Dimension(0, 200)); jScrollPane1.setViewportView(dataSourceList); diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java index c814496ee4..fb78ee8e74 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchAction.java @@ -32,7 +32,6 @@ final class FileSearchAction extends CallableSystemAction implements FileSearchP private static final long serialVersionUID = 1L; private static FileSearchAction instance = null; private static FileSearchDialog searchDialog; - private static boolean shouldReset = false; FileSearchAction() { super(); @@ -40,7 +39,9 @@ final class FileSearchAction extends CallableSystemAction implements FileSearchP Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> { if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) { setEnabled(evt.getNewValue() != null); - shouldReset = evt.getNewValue() != null; + if (searchDialog != null && evt.getNewValue() != null){ + searchDialog.resetCaseDependentFilters(); + } } }); } @@ -56,10 +57,7 @@ final class FileSearchAction extends CallableSystemAction implements FileSearchP public void actionPerformed(ActionEvent e) { if (searchDialog == null) { searchDialog = new FileSearchDialog(); - } else if (shouldReset) { - searchDialog.resetCaseDependentFilters(); - shouldReset = false; - } + } searchDialog.setVisible(true); } @@ -67,9 +65,6 @@ final class FileSearchAction extends CallableSystemAction implements FileSearchP public void performAction() { if (searchDialog == null) { searchDialog = new FileSearchDialog(); - } else if (shouldReset) { - searchDialog.resetCaseDependentFilters(); - shouldReset = false; } searchDialog.setVisible(true); } diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java index 9e41160382..2c95574bce 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java @@ -58,8 +58,8 @@ class FileSearchPanel extends javax.swing.JPanel { private final List filters = new ArrayList<>(); private static int resultWindowCount = 0; //keep track of result windows so they get unique names - private static final MimeTypeFilter mimeTypeFilter = new MimeTypeFilter(); - private static final DataSourceFilter dataSourceFilter = new DataSourceFilter(); + private static MimeTypeFilter mimeTypeFilter = new MimeTypeFilter(); + private static DataSourceFilter dataSourceFilter = new DataSourceFilter(); private static final String EMPTY_WHERE_CLAUSE = NbBundle.getMessage(DateSearchFilter.class, "FileSearchPanel.emptyWhereClause.text"); enum EVENT { @@ -72,7 +72,6 @@ class FileSearchPanel extends javax.swing.JPanel { FileSearchPanel() { initComponents(); customizeComponents(); - } /** @@ -159,7 +158,6 @@ class FileSearchPanel extends javax.swing.JPanel { } } } - errorLabel.setText(""); return enabled; } diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypeFilter.java b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypeFilter.java index 8c477eb0b0..1ad68cdf43 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypeFilter.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypeFilter.java @@ -1,7 +1,20 @@ /* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. + * Autopsy Forensic Browser + * + * Copyright 2021 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.sleuthkit.autopsy.filesearch; @@ -13,11 +26,11 @@ import org.openide.util.NbBundle.Messages; */ class MimeTypeFilter extends AbstractFileSearchFilter { - public MimeTypeFilter(MimeTypePanel component) { + MimeTypeFilter(MimeTypePanel component) { super(component); } - public MimeTypeFilter() { + MimeTypeFilter() { this(new MimeTypePanel()); } @@ -43,21 +56,21 @@ class MimeTypeFilter extends AbstractFileSearchFilter { } @Override - @Messages ({ + @Messages({ "MimeTypeFilter.errorMessage.emptyMimeType=At least one MIME type must be selected." }) public boolean isValid() { - if(this.getComponent().getMimeTypesSelected().isEmpty()){ + if (this.getComponent().getMimeTypesSelected().isEmpty()) { setLastError(Bundle.MimeTypeFilter_errorMessage_emptyMimeType()); return false; } return true; } - + /** * Reset the mime type filter to be up to date with the current case. */ void resetMimeTypeFilter() { - this.getComponent().resetMimeTypePanel(); + this.getComponent().resetMimeTypePanel(); } } diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.form b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.form index c93f84331f..e76d6c8cb3 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.form +++ b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.form @@ -65,7 +65,7 @@ - + diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java index 6d1cb66435..676ef4188d 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.logging.Level; import javax.swing.DefaultListModel; import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector; @@ -30,7 +31,7 @@ import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector; * Enter MIME types for search. */ @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives -public class MimeTypePanel extends javax.swing.JPanel { +public final class MimeTypePanel extends javax.swing.JPanel { private static final Logger logger = Logger.getLogger(MimeTypePanel.class.getName()); private static final long serialVersionUID = 1L; @@ -40,10 +41,7 @@ public class MimeTypePanel extends javax.swing.JPanel { */ public MimeTypePanel() { initComponents(); - setComponentsEnabled(); - this.mimeTypeList.addListSelectionListener((ListSelectionEvent e) -> { - firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null); - }); + resetMimeTypePanel(); } private String[] getMimeTypeArray() { @@ -66,7 +64,7 @@ public class MimeTypePanel extends javax.swing.JPanel { } void setComponentsEnabled() { - boolean enabled = this.isSelected(); + boolean enabled = isSelected(); this.mimeTypeList.setEnabled(enabled); this.noteLabel.setEnabled(enabled); } @@ -88,11 +86,7 @@ public class MimeTypePanel extends javax.swing.JPanel { setMinimumSize(new java.awt.Dimension(150, 150)); setPreferredSize(new java.awt.Dimension(150, 150)); - mimeTypeList.setModel(new DefaultListModel() { - String[] strings = getMimeTypeArray(); - public int getSize() { return strings.length; } - public String getElementAt(int i) { return strings[i]; } - }); + mimeTypeList.setModel(new DefaultListModel()); mimeTypeList.setMinimumSize(new java.awt.Dimension(0, 200)); jScrollPane1.setViewportView(mimeTypeList); @@ -152,11 +146,19 @@ public class MimeTypePanel extends javax.swing.JPanel { * Reset the mime type panel to be up to date with the current case. */ void resetMimeTypePanel() { - ((DefaultListModel) mimeTypeList.getModel()).removeAllElements(); + //remove all list selection listeners + for (ListSelectionListener listener : mimeTypeList.getListSelectionListeners()) { + mimeTypeList.removeListSelectionListener(listener); + } + mimeTypeList.clearSelection(); + ((DefaultListModel) mimeTypeList.getModel()).clear(); for (String dataSource : getMimeTypeArray()) { ((DefaultListModel) mimeTypeList.getModel()).addElement(dataSource); } - this.mimeTypeList.setEnabled(false); + mimeTypeList.addListSelectionListener((ListSelectionEvent e) -> { + firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null); + }); + mimeTypeList.setEnabled(false); mimeTypeCheckBox.setSelected(false); noteLabel.setEnabled(false); }