Merge pull request #7164 from wschaeferB/5316-PreserveSettingsBetweenSearches

5316 preserve settings between searches
This commit is contained in:
Richard Cordovano 2021-08-04 14:24:14 -04:00 committed by GitHub
commit 2395e9c054
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 141 additions and 54 deletions

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2018 Basis Technology Corp.
* Copyright 2018-2021 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -28,16 +28,18 @@ class DataSourceFilter extends AbstractFileSearchFilter<DataSourcePanel> {
/**
* 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<DataSourcePanel> {
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 = "";

View File

@ -65,7 +65,7 @@
<Component class="javax.swing.JList" name="dataSourceList">
<Properties>
<Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="new javax.swing.AbstractListModel&lt;String&gt;() {&#xa; List&lt;String&gt; strings = getDataSourceArray();&#xa; public int getSize() { return strings.size(); }&#xa; public String getElementAt(int idx) { return strings.get(idx); }&#xa;}" type="code"/>
<Connection code="new DefaultListModel&lt;String&gt;()" type="code"/>
</Property>
<Property name="enabled" type="boolean" value="false"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">

View File

@ -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<String>) dataSourceList.getModel()).clear();
List<String> strings = getDataSourceArray();
for (String dataSource : strings) {
((DefaultListModel<String>) 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<Long> getDataSourcesSelected() {
Set<Long> dataSourceObjIdSet = new HashSet<>();
List<String> 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<String>() {
List<String> strings = getDataSourceArray();
public int getSize() { return strings.size(); }
public String getElementAt(int idx) { return strings.get(idx); }
});
dataSourceList.setModel(new DefaultListModel<String>());
dataSourceList.setEnabled(false);
dataSourceList.setMinimumSize(new java.awt.Dimension(0, 200));
jScrollPane1.setViewportView(dataSourceList);

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2017 Basis Technology Corp.
* Copyright 2011-2021 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> 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

View File

@ -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
}

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2019 Basis Technology Corp.
* Copyright 2011-2021 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> 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<FileSearchFilter> 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<TableFilterNode, Void> 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;
}
@ -339,6 +335,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);
for (FileSearchFilter fsf : getFilters()) {

View File

@ -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 <at> sleuthkit <dot> 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<MimeTypePanel> {
public MimeTypeFilter(MimeTypePanel component) {
MimeTypeFilter(MimeTypePanel component) {
super(component);
}
public MimeTypeFilter() {
MimeTypeFilter() {
this(new MimeTypePanel());
}
@ -53,4 +66,11 @@ class MimeTypeFilter extends AbstractFileSearchFilter<MimeTypePanel> {
}
return true;
}
/**
* Reset the mime type filter to be up to date with the current case.
*/
void resetMimeTypeFilter() {
this.getComponent().resetMimeTypePanel();
}
}

View File

@ -65,7 +65,7 @@
<Component class="javax.swing.JList" name="mimeTypeList">
<Properties>
<Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="new javax.swing.AbstractListModel&lt;String&gt;() {&#xa; String[] strings = getMimeTypeArray();&#xa; public int getSize() { return strings.length; }&#xa; public String getElementAt(int i) { return strings[i]; }&#xa;}" type="code"/>
<Connection code="new DefaultListModel&lt;String&gt;()" type="code"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 200]"/>

View File

@ -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>() {
String[] strings = getMimeTypeArray();
public int getSize() { return strings.length; }
public String getElementAt(int i) { return strings[i]; }
});
mimeTypeList.setModel(new DefaultListModel<String>());
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<String> 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<String>) mimeTypeList.getModel()).clear();
for (String dataSource : getMimeTypeArray()) {
((DefaultListModel<String>) mimeTypeList.getModel()).addElement(dataSource);
}
mimeTypeList.addListSelectionListener((ListSelectionEvent e) -> {
firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
});
mimeTypeList.setEnabled(false);
mimeTypeCheckBox.setSelected(false);
noteLabel.setEnabled(false);
}
}