From 20c73bd79d6e3a4a3864adf9424cff94df2ffbea Mon Sep 17 00:00:00 2001 From: adam-m Date: Tue, 14 May 2013 17:22:13 -0400 Subject: [PATCH] reset local files wizard component when selected again --- .../casemodule/AddImageVisualPanel1.java | 7 + .../casemodule/AddImageWizardPanel1.java | 122 +++++++++--------- .../casemodule/AddImageWizardPanel3.java | 2 +- .../autopsy/casemodule/ContentTypePanel.java | 5 + .../autopsy/casemodule/ImageFilePanel.java | 5 + .../autopsy/casemodule/LocalDiskPanel.java | 5 + .../autopsy/casemodule/LocalFilesPanel.java | 11 +- 7 files changed, 91 insertions(+), 66 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageVisualPanel1.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageVisualPanel1.java index 40582677f8..4fb2f60d71 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageVisualPanel1.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageVisualPanel1.java @@ -134,6 +134,13 @@ final class AddImageVisualPanel1 extends JPanel { return currentPanel.getContentType(); } + /** + * Reset the data sources panel selected + */ + public void reset() { + currentPanel.reset(); + } + /** * Sets the image path of the current panel. * @param s the image path to set diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel1.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel1.java index b0d14395cb..f84861f650 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel1.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel1.java @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.sleuthkit.autopsy.casemodule; import java.beans.PropertyChangeEvent; @@ -48,16 +47,16 @@ class AddImageWizardPanel1 implements WizardDescriptor.Panel, private boolean isNextEnable = false; private static final String PROP_LASTDATASOURCE_PATH = "LBL_LastDataSource_PATH"; private static final String PROP_LASTDATASOURCE_TYPE = "LBL_LastDataSource_TYPE"; - // paths to any set hash lookup databases (can be null) + // paths to any set hash lookup databases (can be null) private String NSRLPath, knownBadPath; - + /** * Get the visual component for the panel. In this template, the component * is kept separate. This can be more efficient: if the wizard is created * but never displayed, or not all panels are displayed, it is better to * create only those which really need to be visible. * - * @return component the UI component of this wizard panel + * @return component the UI component of this wizard panel */ @Override public AddImageVisualPanel1 getComponent() { @@ -67,12 +66,12 @@ class AddImageWizardPanel1 implements WizardDescriptor.Panel, component.addPropertyChangeListener(this); return component; } - + /** * Help for this panel. When the panel is active, this is used as the help * for the wizard dialog. * - * @return HelpCtx.DEFAULT_HELP the help for this panel + * @return HelpCtx.DEFAULT_HELP the help for this panel */ @Override public HelpCtx getHelp() { @@ -86,19 +85,20 @@ class AddImageWizardPanel1 implements WizardDescriptor.Panel, * Tests whether the panel is finished and it is safe to proceed to the next * one. If the panel is valid, the "Next" button will be enabled. * - * @return boolean true if all the fields are correctly filled, false otherwise + * @return boolean true if all the fields are correctly filled, false + * otherwise */ @Override public boolean isValid() { return isNextEnable; } - + /** * Move the keyboard focus to the next button */ void moveFocusToNext() { // set the focus to the next button of the wizard dialog if it's enabled - if(isNextEnable){ + if (isNextEnable) { Lookup.getDefault().lookup(AddImageAction.class).requestFocusButton("Next >"); } } @@ -106,19 +106,18 @@ class AddImageWizardPanel1 implements WizardDescriptor.Panel, /** * Enable the "Next" button and fireChangeEvent to update the GUI * - * @param isEnabled true if next button can be enabled, false otherwise + * @param isEnabled true if next button can be enabled, false otherwise */ - public void enableNextButton(boolean isEnabled){ + public void enableNextButton(boolean isEnabled) { isNextEnable = isEnabled; fireChangeEvent(); } - private final Set listeners = new HashSet(1); // or can use ChangeSupport in NB 6.0 /** * Adds a listener to changes of the panel's validity. * - * @param l the change listener to add + * @param l the change listener to add */ @Override public final void addChangeListener(ChangeListener l) { @@ -130,7 +129,7 @@ class AddImageWizardPanel1 implements WizardDescriptor.Panel, /** * Removes a listener to changes of the panel's validity. * - * @param l the change listener to move + * @param l the change listener to move */ @Override public final void removeChangeListener(ChangeListener l) { @@ -140,8 +139,8 @@ class AddImageWizardPanel1 implements WizardDescriptor.Panel, } /** - * This method is auto-generated. It seems that this method is used to listen - * to any change in this wizard panel. + * This method is auto-generated. It seems that this method is used to + * listen to any change in this wizard panel. */ protected final void fireChangeEvent() { Iterator it; @@ -153,75 +152,74 @@ class AddImageWizardPanel1 implements WizardDescriptor.Panel, it.next().stateChanged(ev); } } - // You can use a settings object to keep track of state. Normally the // settings object will be the WizardDescriptor, so you can use // WizardDescriptor.getProperty & putProperty to store information entered // by the user. - /** * Provides the wizard panel with the current data--either the default data * or already-modified settings, if the user used the previous and/or next * buttons. This method can be called multiple times on one instance of - * WizardDescriptor.Panel. - *s - * @param settings the setting to be read from + * WizardDescriptor.Panel. s + * + * @param settings the setting to be read from */ @Override public void readSettings(WizardDescriptor settings) { - AddImageVisualPanel1 component = getComponent(); - + + //reset settings if supports it + //getComponent().reset(); + // Prepopulate the image directory from the properties file - try{ - String lastDataSourceDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_LASTDATASOURCE_PATH); - String lastDataSourceType = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_LASTDATASOURCE_TYPE); - - //set the last path for the content panel for which it was saved - if (component.getContentType().toString().equals(lastDataSourceType)) { - component.setContentPath(lastDataSourceDirectory); - } - - // Load hash database settings, enable or disable the checkbox - this.NSRLPath = null; - this.knownBadPath = null; - //JCheckBox lookupFilesCheckbox = component.getLookupFilesCheckbox(); - //lookupFilesCheckbox.setSelected(false); - //lookupFilesCheckbox.setEnabled(this.NSRLPath != null || this.knownBadPath != null); - - // If there is a process object in the settings, revert it and remove it from the settings - AddImageAction.CleanupTask cleanupTask = (AddImageAction.CleanupTask) settings.getProperty(AddImageAction.IMAGECLEANUPTASK_PROP); - if(cleanupTask != null){ - try{ - cleanupTask.cleanup(); - }catch(Exception ex){ - Logger logger = Logger.getLogger(AddImageWizardPanel1.class.getName()); - logger.log(Level.WARNING, "Error cleaning up image task", ex); - }finally{ - cleanupTask.disable(); + try { + String lastDataSourceDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_LASTDATASOURCE_PATH); + String lastDataSourceType = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_LASTDATASOURCE_TYPE); + + //set the last path for the content panel for which it was saved + if (component.getContentType().toString().equals(lastDataSourceType)) { + component.setContentPath(lastDataSourceDirectory); } + + // Load hash database settings, enable or disable the checkbox + this.NSRLPath = null; + this.knownBadPath = null; + //JCheckBox lookupFilesCheckbox = component.getLookupFilesCheckbox(); + //lookupFilesCheckbox.setSelected(false); + //lookupFilesCheckbox.setEnabled(this.NSRLPath != null || this.knownBadPath != null); + + // If there is a process object in the settings, revert it and remove it from the settings + AddImageAction.CleanupTask cleanupTask = (AddImageAction.CleanupTask) settings.getProperty(AddImageAction.IMAGECLEANUPTASK_PROP); + if (cleanupTask != null) { + try { + cleanupTask.cleanup(); + } catch (Exception ex) { + Logger logger = Logger.getLogger(AddImageWizardPanel1.class.getName()); + logger.log(Level.WARNING, "Error cleaning up image task", ex); + } finally { + cleanupTask.disable(); + } + } + } catch (Exception e) { } - } - catch(Exception e){ - } - + } /** * Provides the wizard panel with the opportunity to update the settings - * with its current customized state. Rather than updating its settings - * with every change in the GUI, it should collect them, and then only save - * them when requested to by this method. This method can be called multiple + * with its current customized state. Rather than updating its settings with + * every change in the GUI, it should collect them, and then only save them + * when requested to by this method. This method can be called multiple * times on one instance of WizardDescriptor.Panel. * - * @param settings the setting to be stored to + * @param settings the setting to be stored to */ @Override public void storeSettings(WizardDescriptor settings) { settings.putProperty(AddImageAction.DATASOURCEPATH_PROP, getComponent().getContentPaths()); settings.putProperty(AddImageAction.DATASOURCETYPE_PROP, getComponent().getContentType()); settings.putProperty(AddImageAction.TIMEZONE_PROP, getComponent().getSelectedTimezone()); // store the timezone - settings.putProperty(AddImageAction.NOFATORPHANS_PROP, Boolean.valueOf(getComponent().getNoFatOrphans())); + settings.putProperty(AddImageAction.NOFATORPHANS_PROP, Boolean.valueOf(getComponent().getNoFatOrphans())); //settings.putProperty(AddImageAction.LOOKUPFILES_PROP, getComponent().getLookupFilesCheckboxChecked()); //settings.putProperty(AddImageAction.SOLR_PROP, getComponent().getIndexImageCheckboxChecked()); @@ -230,14 +228,14 @@ class AddImageWizardPanel1 implements WizardDescriptor.Panel, String firstImagePath = firstImage.substring(0, firstImage.lastIndexOf(File.separator) + 1); ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_LASTDATASOURCE_PATH, firstImagePath); ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_LASTDATASOURCE_TYPE, getComponent().getContentType().toString()); + } - /** - * The "listener" for any property change in this panel. Any property changes - * will invoke the "fireChangeEvent()" method. + * The "listener" for any property change in this panel. Any property + * changes will invoke the "fireChangeEvent()" method. * - * @param evt the property change event + * @param evt the property change event */ @Override public void propertyChange(PropertyChangeEvent evt) { diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel3.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel3.java index 9497d55f4d..a0aaaddcb4 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel3.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel3.java @@ -52,7 +52,7 @@ import org.sleuthkit.datamodel.TskException; */ class AddImageWizardPanel3 implements WizardDescriptor.Panel { - private Logger logger = Logger.getLogger(AddImageWizardPanel3.class.getName()); + private static final Logger logger = Logger.getLogger(AddImageWizardPanel3.class.getName()); private IngestConfigurator ingestConfig = Lookup.getDefault().lookup(IngestConfigurator.class); /** * The visual component that displays this panel. If you need to access the diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ContentTypePanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/ContentTypePanel.java index ea47e6a68e..0a8eb2c303 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ContentTypePanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ContentTypePanel.java @@ -58,6 +58,11 @@ abstract class ContentTypePanel extends JPanel { */ abstract public boolean enableNext(); + /** + * Tells this panel to reset itself + */ + abstract public void reset(); + /** * Tells this panel it has been selected. */ diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java index bc4ad0ae6d..f7bc809a8c 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ImageFilePanel.java @@ -154,6 +154,11 @@ public class ImageFilePanel extends ContentTypePanel implements DocumentListener public ContentType getContentType() { return ContentType.IMAGE; } + + @Override + public void reset() { + //nothing to reset + } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java index 857a3221f3..1ac9e5ed5c 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalDiskPanel.java @@ -166,6 +166,11 @@ public class LocalDiskPanel extends ContentTypePanel { return enableNext; } + @Override + public void reset() { + //nothing to reset + } + /** * @return the representation of this panel as a String. */ diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java index 7f7db756c5..2aeb0b30b5 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesPanel.java @@ -91,7 +91,13 @@ public class LocalFilesPanel extends ContentTypePanel { @Override public void select() { - //nothing needed + reset(); + } + + @Override + public void reset() { + currentFiles.clear(); + selectedPaths.setText(""); } @Override @@ -213,8 +219,7 @@ public class LocalFilesPanel extends ContentTypePanel { }//GEN-LAST:event_selectButtonActionPerformed private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed - currentFiles.clear(); - selectedPaths.setText(""); + reset(); }//GEN-LAST:event_clearButtonActionPerformed