diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourceFilter.java b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourceFilter.java index 4ef41b78d8..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"); @@ -28,16 +28,18 @@ class DataSourceFilter extends AbstractFileSearchFilter { /** * Construct DataSourceFilter with the DataSourcePanel + * * @param component A DataSourcePanel */ - public DataSourceFilter(DataSourcePanel component) { + DataSourceFilter(DataSourcePanel component) { super(component); } /** - * Default constructor to construct a new DataSourceFilter with a new DataSourcePanel + * Default constructor to construct a new DataSourceFilter with a new + * DataSourcePanel */ - public DataSourceFilter() { + 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..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 28fae71c5b..7b19d4d5c8 100755 --- a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.java @@ -27,7 +27,9 @@ 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 javax.swing.event.ListSelectionListener; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.coreutils.Logger; @@ -50,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); } } @@ -98,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); } @@ -145,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 javax.swing.AbstractListModel() { - 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 fb66a4b6d7..fb78ee8e74 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,6 +31,7 @@ final class FileSearchAction extends CallableSystemAction implements FileSearchP private static final long serialVersionUID = 1L; private static FileSearchAction instance = null; + private static FileSearchDialog searchDialog; FileSearchAction() { super(); @@ -38,6 +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); + if (searchDialog != null && evt.getNewValue() != null){ + searchDialog.resetCaseDependentFilters(); + } } }); } @@ -51,12 +55,18 @@ final class FileSearchAction extends CallableSystemAction implements FileSearchP @Override public void actionPerformed(ActionEvent e) { - new FileSearchDialog().setVisible(true); + if (searchDialog == null) { + searchDialog = new FileSearchDialog(); + } + searchDialog.setVisible(true); } @Override public void performAction() { - new FileSearchDialog().setVisible(true); + if (searchDialog == null) { + searchDialog = new FileSearchDialog(); + } + 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..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. @@ -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,11 +43,19 @@ class FileSearchDialog extends javax.swing.JDialog { @Override public void actionPerformed(ActionEvent e) { - dispose(); + setVisible(false); } }); } + /** + * 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 @@ 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 62f6332c83..4775041b1f 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2019 Basis Technology Corp. + * Copyright 2011-2021 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -40,8 +40,6 @@ import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; import org.openide.nodes.Node; import org.openide.util.NbBundle; -import org.openide.windows.TopComponent; -import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.corecomponents.DataResultTopComponent; @@ -64,6 +62,8 @@ class FileSearchPanel extends javax.swing.JPanel { private static final long serialVersionUID = 1L; private final List filters = new ArrayList<>(); private static int resultWindowCount = 0; //keep track of result windows so they get unique names + 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"); private static SwingWorker searchWorker = null; @@ -77,7 +77,6 @@ class FileSearchPanel extends javax.swing.JPanel { FileSearchPanel() { initComponents(); customizeComponents(); - } /** @@ -107,8 +106,6 @@ class FileSearchPanel extends javax.swing.JPanel { 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)); @@ -166,7 +163,6 @@ class FileSearchPanel extends javax.swing.JPanel { } } } - errorLabel.setText(""); return enabled; } @@ -187,7 +183,7 @@ class FileSearchPanel extends javax.swing.JPanel { if (this.isValidSearch()) { // try to get the number of matches first Case currentCase = Case.getCurrentCaseThrows(); // get the most updated case - Node emptyNode = new TableFilterNode(new EmptyNode(Bundle.FileSearchPanel_searchingNode_display_text()), true); + Node emptyNode = new TableFilterNode(new EmptyNode(Bundle.FileSearchPanel_searchingNode_display_text()), true); String title = NbBundle.getMessage(this.getClass(), "FileSearchPanel.search.results.title", ++resultWindowCount); String pathText = Bundle.FileSearchPanel_searchingPath_text(); final DataResultTopComponent searchResultWin = DataResultTopComponent.createInstance(title, pathText, @@ -338,6 +334,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..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,14 +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(); + } } diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.form b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.form index 9b4044bc32..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 41f52825d7..676ef4188d 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/MimeTypePanel.java @@ -21,7 +21,9 @@ 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 javax.swing.event.ListSelectionListener; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector; @@ -29,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; @@ -39,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() { @@ -65,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); } @@ -87,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 javax.swing.AbstractListModel() { - 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); @@ -146,4 +141,25 @@ 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() { + //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); + } + mimeTypeList.addListSelectionListener((ListSelectionEvent e) -> { + firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null); + }); + mimeTypeList.setEnabled(false); + mimeTypeCheckBox.setSelected(false); + noteLabel.setEnabled(false); + } }