From c57cb7da8c4b14def3710d60a6ad6b3807d12ef9 Mon Sep 17 00:00:00 2001 From: Andrew Ziehl Date: Wed, 21 Mar 2018 15:21:44 -0700 Subject: [PATCH] Code cleanup, update UI to disable 'across data sources' radio button instead of disabling common files search altogether when open case has one datasource. --- .../commonfilesearch/CommonFilesPanel.form | 10 ++-- .../commonfilesearch/CommonFilesPanel.java | 50 +++++++++++++------ .../CommonFilesSearchAction.java | 26 +--------- 3 files changed, 42 insertions(+), 44 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.form b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.form index 7290350085..9b548bd529 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.form +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.form @@ -31,7 +31,7 @@ - + @@ -40,7 +40,7 @@ - + @@ -64,19 +64,19 @@ - + - + - + diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java index 8a3578aaf1..f6f2c33905 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesPanel.java @@ -18,6 +18,7 @@ */ package org.sleuthkit.autopsy.commonfilesearch; +import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import static java.awt.event.ItemEvent.SELECTED; import java.sql.ResultSet; @@ -78,8 +79,21 @@ public final class CommonFilesPanel extends javax.swing.JPanel { } this.dataSourcesList = new DataSourceComboBoxModel(dataSourcesNames); initComponents(); + updateUIButtons(); + } + private void updateUIButtons() { + boolean multipleDataSources = this.caseHasMultipleSources(); + allDataSourcesRadioButton.setEnabled(multipleDataSources); + allDataSourcesRadioButton.setSelected(false); + if(!multipleDataSources) { + withinDataSourceRadioButton.setSelected(true); + withinDataSourceSelected(true); + } } + private boolean caseHasMultipleSources(){ + return dataSourceMap.size() >= 2; + } private void buildDataSourceMap(Map dataSourceMap) throws TskCoreException, NoCurrentCaseException, SQLException { Case currentCase = Case.getOpenCase(); SleuthkitCase tskDb = currentCase.getSleuthkitCase(); @@ -233,7 +247,7 @@ public final class CommonFilesPanel extends javax.swing.JPanel { dataSourcesButtonGroup = new javax.swing.ButtonGroup(); searchButton = new javax.swing.JButton(); - allDatasourcesRadio = new javax.swing.JRadioButton(); + allDataSourcesRadioButton = new javax.swing.JRadioButton(); withinDataSourceRadioButton = new javax.swing.JRadioButton(); selectDataSourceComboBox = new javax.swing.JComboBox<>(); @@ -247,13 +261,13 @@ public final class CommonFilesPanel extends javax.swing.JPanel { } }); - dataSourcesButtonGroup.add(allDatasourcesRadio); - allDatasourcesRadio.setSelected(true); - org.openide.awt.Mnemonics.setLocalizedText(allDatasourcesRadio, org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.allDatasourcesRadio.text")); // NOI18N - allDatasourcesRadio.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); - allDatasourcesRadio.addActionListener(new java.awt.event.ActionListener() { + dataSourcesButtonGroup.add(allDataSourcesRadioButton); + allDataSourcesRadioButton.setSelected(true); + org.openide.awt.Mnemonics.setLocalizedText(allDataSourcesRadioButton, org.openide.util.NbBundle.getMessage(CommonFilesPanel.class, "CommonFilesPanel.allDataSourcesRadioButton.text")); // NOI18N + allDataSourcesRadioButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + allDataSourcesRadioButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - allDatasourcesRadioActionPerformed(evt); + allDataSourcesRadioButtonActionPerformed(evt); } }); @@ -284,13 +298,13 @@ public final class CommonFilesPanel extends javax.swing.JPanel { .addComponent(selectDataSourceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(searchButton) .addComponent(withinDataSourceRadioButton) - .addComponent(allDatasourcesRadio)) + .addComponent(allDataSourcesRadioButton)) .addContainerGap(26, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(allDatasourcesRadio) + .addComponent(allDataSourcesRadioButton) .addGap(2, 2, 2) .addComponent(withinDataSourceRadioButton, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) @@ -305,24 +319,30 @@ public final class CommonFilesPanel extends javax.swing.JPanel { search(); }//GEN-LAST:event_searchButtonActionPerformed - private void allDatasourcesRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allDatasourcesRadioActionPerformed - selectDataSourceComboBox.setEnabled(evt.getID() == SELECTED); + private void allDataSourcesRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allDataSourcesRadioButtonActionPerformed + selectDataSourceComboBox.setEnabled(!allDataSourcesRadioButton.isSelected()); singleDataSource = false; - }//GEN-LAST:event_allDatasourcesRadioActionPerformed + }//GEN-LAST:event_allDataSourcesRadioButtonActionPerformed private void selectDataSourceComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectDataSourceComboBoxActionPerformed selectedDataSource = selectDataSourceComboBox.getSelectedItem().toString(); }//GEN-LAST:event_selectDataSourceComboBoxActionPerformed private void withinDataSourceRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_withinDataSourceRadioButtonActionPerformed - selectDataSourceComboBox.setEnabled(evt.getID() != SELECTED); - singleDataSource = true; + withinDataSourceSelected(withinDataSourceRadioButton.isSelected()); }//GEN-LAST:event_withinDataSourceRadioButtonActionPerformed + private void withinDataSourceSelected(boolean selected) { + selectDataSourceComboBox.setEnabled(selected); + if(selectDataSourceComboBox.isEnabled()) { + selectDataSourceComboBox.setSelectedIndex(0); + singleDataSource = true; + } + } // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JRadioButton allDatasourcesRadio; + private javax.swing.JRadioButton allDataSourcesRadioButton; private javax.swing.ButtonGroup dataSourcesButtonGroup; private javax.swing.JButton searchButton; private javax.swing.JComboBox selectDataSourceComboBox; diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesSearchAction.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesSearchAction.java index bbbdb6d41b..9915720f35 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesSearchAction.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonFilesSearchAction.java @@ -19,17 +19,10 @@ package org.sleuthkit.autopsy.commonfilesearch; import java.awt.event.ActionEvent; -import java.beans.PropertyChangeEvent; -import java.util.EnumSet; -import java.util.logging.Level; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.util.actions.CallableSystemAction; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.datamodel.SleuthkitCase; -import org.sleuthkit.datamodel.TskCoreException; /** * Encapsulates a menu action which triggers the common files search dialog. @@ -43,23 +36,8 @@ final class CommonFilesSearchAction extends CallableSystemAction { CommonFilesSearchAction() { super(); - this.setEnabled(true); //this.caseHasMultipleSources()); -// Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> { -// if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) { -// this.setEnabled(evt.getNewValue() != null && this.caseHasMultipleSources()); -// } -// }); - } - - private boolean caseHasMultipleSources(){ - try { - Case currentCase = Case.getOpenCase(); - SleuthkitCase tskDb = currentCase.getSleuthkitCase(); - return tskDb.getDataSources().size() >= 2; - } catch (NoCurrentCaseException | TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Unable to count datasources.", ex); - } - return false; + this.setEnabled(true); + } public static synchronized CommonFilesSearchAction getDefault() {