From 288a993aafbfb55cfe71470511f49d434b797321 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Mon, 6 Feb 2017 17:43:47 -0500 Subject: [PATCH] 2199 Changed from casting to abstract class use and other clean up --- .../AddImageWizardAddingProgressPanel.java | 7 +- .../AddImageWizardChooseDataSourcePanel.java | 8 +-- .../AddImageWizardIngestConfigPanel.java | 34 ++++------ .../casemodule/AddImageWizardIterator.java | 49 +++++++++----- .../IngestModulesConfigWizardPanel.java | 7 +- .../IngestProfileSelectionWizardPanel.java | 37 +++++++---- .../RunIngestModulesWizardIterator.java | 14 ++-- .../ShortcutWizardDescriptorPanel.java | 64 +++++++++++++++++++ 8 files changed, 145 insertions(+), 75 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/ingest/runIngestModuleWizard/ShortcutWizardDescriptorPanel.java diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardAddingProgressPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardAddingProgressPanel.java index 7204664d2f..50134fa88a 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardAddingProgressPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardAddingProgressPanel.java @@ -30,6 +30,7 @@ import org.openide.util.HelpCtx; import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorProgressMonitor; +import org.sleuthkit.autopsy.ingest.runIngestModuleWizard.ShortcutWizardDescriptorPanel; /** * The final panel of the add image wizard. It displays a progress bar and @@ -39,7 +40,7 @@ import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessorProgress * {@link AddImageWizardIngestConfigPanel} (which is a bit weird if you ask m * -jm) */ -class AddImageWizardAddingProgressPanel implements WizardDescriptor.FinishablePanel { +class AddImageWizardAddingProgressPanel extends ShortcutWizardDescriptorPanel { /** * flag to indicate that the image adding process is finished and this panel @@ -239,8 +240,4 @@ class AddImageWizardAddingProgressPanel implements WizardDescriptor.FinishablePa getComponent().showErrors(errorString, critical); } - @Override - public boolean isFinishPanel() { - return true; - } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourcePanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourcePanel.java index e845b89349..259cb4f4d3 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourcePanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardChooseDataSourcePanel.java @@ -33,12 +33,13 @@ import org.openide.util.HelpCtx; import org.openide.util.Lookup; import org.openide.windows.WindowManager; import java.awt.Cursor; +import org.sleuthkit.autopsy.ingest.runIngestModuleWizard.ShortcutWizardDescriptorPanel; /** * The "Add Image" wizard panel1 handling the logic of selecting image file(s) * to add to Case, and pick the time zone. */ -class AddImageWizardChooseDataSourcePanel implements WizardDescriptor.FinishablePanel, PropertyChangeListener { +class AddImageWizardChooseDataSourcePanel extends ShortcutWizardDescriptorPanel implements PropertyChangeListener { /** * The visual component that displays this panel. If you need to access the @@ -232,9 +233,4 @@ class AddImageWizardChooseDataSourcePanel implements WizardDescriptor.Finishable public void propertyChange(PropertyChangeEvent evt) { fireChangeEvent(); } - - @Override - public boolean isFinishPanel() { - return false; - } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIngestConfigPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIngestConfigPanel.java index ccdd0c1426..a37df4227a 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIngestConfigPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIngestConfigPanel.java @@ -40,6 +40,8 @@ import org.sleuthkit.autopsy.coreutils.PlatformUtil; import org.sleuthkit.autopsy.ingest.IngestJobSettings; import org.sleuthkit.autopsy.ingest.IngestJobSettingsPanel; import org.sleuthkit.autopsy.ingest.IngestManager; +import org.sleuthkit.autopsy.ingest.runIngestModuleWizard.IngestProfileSelectionWizardPanel; +import org.sleuthkit.autopsy.ingest.runIngestModuleWizard.ShortcutWizardDescriptorPanel; /** * second panel of add image wizard, allows user to configure ingest modules. @@ -47,7 +49,7 @@ import org.sleuthkit.autopsy.ingest.IngestManager; * TODO: review this for dead code. think about moving logic of adding image to * 3rd panel( {@link AddImageWizardAddingProgressPanel}) separate class -jm */ -class AddImageWizardIngestConfigPanel implements WizardDescriptor.FinishablePanel { +class AddImageWizardIngestConfigPanel extends ShortcutWizardDescriptorPanel { private IngestJobSettingsPanel ingestJobSettingsPanel; @@ -60,7 +62,6 @@ class AddImageWizardIngestConfigPanel implements WizardDescriptor.FinishablePane private final List newContents = Collections.synchronizedList(new ArrayList()); private boolean ingested = false; private boolean readyToIngest = false; - // task that will clean up the created database file if the wizard is cancelled before it finishes private AddImageAction.CleanupTask cleanupTask; @@ -79,7 +80,6 @@ class AddImageWizardIngestConfigPanel implements WizardDescriptor.FinishablePane IngestJobSettings ingestJobSettings = new IngestJobSettings(lastProfileUsed); showWarnings(ingestJobSettings); - System.out.println("LAST PROFILE USED CREATE: " + lastProfileUsed); this.ingestJobSettingsPanel = new IngestJobSettingsPanel(ingestJobSettings); } @@ -162,12 +162,9 @@ class AddImageWizardIngestConfigPanel implements WizardDescriptor.FinishablePane */ @Override public void readSettings(WizardDescriptor settings) { - String PROP_LASTPROFILE_NAME = "RIMW_LASTPROFILE_NAME"; //NON-NLS //WJS-TODO remove these copies, leaving copies in IngestProfileSelectionWizardPanel - String LAST_PROFILE_PROPERTIES_FILE = "IngestProfileSelectionPanel"; //NON-NLS - if (!(ModuleSettings.getConfigSetting(LAST_PROFILE_PROPERTIES_FILE, PROP_LASTPROFILE_NAME) == null) - && !ModuleSettings.getConfigSetting(LAST_PROFILE_PROPERTIES_FILE, PROP_LASTPROFILE_NAME).isEmpty()) { - lastProfileUsed = ModuleSettings.getConfigSetting(LAST_PROFILE_PROPERTIES_FILE, PROP_LASTPROFILE_NAME); - System.out.println("LAST PROFILE USED READ: " + lastProfileUsed); + if (!(ModuleSettings.getConfigSetting(IngestProfileSelectionWizardPanel.getLastProfilePropertiesFile(), AddImageWizardIterator.getPropLastprofileName()) == null) + && !ModuleSettings.getConfigSetting(IngestProfileSelectionWizardPanel.getLastProfilePropertiesFile(), AddImageWizardIterator.getPropLastprofileName()).isEmpty()) { + lastProfileUsed = ModuleSettings.getConfigSetting(IngestProfileSelectionWizardPanel.getLastProfilePropertiesFile(), AddImageWizardIterator.getPropLastprofileName()); } IngestJobSettings ingestJobSettings = new IngestJobSettings(lastProfileUsed); showWarnings(ingestJobSettings); @@ -200,7 +197,6 @@ class AddImageWizardIngestConfigPanel implements WizardDescriptor.FinishablePane public void storeSettings(WizardDescriptor settings) { IngestJobSettings ingestJobSettings = this.ingestJobSettingsPanel.getSettings(); - System.out.println("LAST PROFILE USED STORE: " + lastProfileUsed); ingestJobSettings.save(); showWarnings(ingestJobSettings); @@ -220,13 +216,12 @@ class AddImageWizardIngestConfigPanel implements WizardDescriptor.FinishablePane } } - void skippingThisPanel() { - String PROP_LASTPROFILE_NAME = "RIMW_LASTPROFILE_NAME"; //NON-NLS //WJS-TODO remove these copies, leaving copies in IngestProfileSelectionWizardPanel - String LAST_PROFILE_PROPERTIES_FILE = "IngestProfileSelectionPanel"; //NON-NLS - if (!(ModuleSettings.getConfigSetting(LAST_PROFILE_PROPERTIES_FILE, PROP_LASTPROFILE_NAME) == null) - && !ModuleSettings.getConfigSetting(LAST_PROFILE_PROPERTIES_FILE, PROP_LASTPROFILE_NAME).isEmpty()) { - lastProfileUsed = ModuleSettings.getConfigSetting(LAST_PROFILE_PROPERTIES_FILE, PROP_LASTPROFILE_NAME); - System.out.println("LAST PROFILE USED READ: " + lastProfileUsed); + + @Override + public void processThisPanelBeforeSkipped() { + if (!(ModuleSettings.getConfigSetting(IngestProfileSelectionWizardPanel.getLastProfilePropertiesFile(), AddImageWizardIterator.getPropLastprofileName()) == null) + && !ModuleSettings.getConfigSetting(IngestProfileSelectionWizardPanel.getLastProfilePropertiesFile(), AddImageWizardIterator.getPropLastprofileName()).isEmpty()) { + lastProfileUsed = ModuleSettings.getConfigSetting(IngestProfileSelectionWizardPanel.getLastProfilePropertiesFile(), AddImageWizardIterator.getPropLastprofileName()); } IngestJobSettings ingestJobSettings = new IngestJobSettings(lastProfileUsed); showWarnings(ingestJobSettings); @@ -355,9 +350,4 @@ class AddImageWizardIngestConfigPanel implements WizardDescriptor.FinishablePane } } - - @Override - public boolean isFinishPanel() { - return false; - } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIterator.java b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIterator.java index c8bc86b17b..51aaab6313 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIterator.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/AddImageWizardIterator.java @@ -29,6 +29,7 @@ import org.openide.WizardDescriptor; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.ingest.IngestProfileMap; import org.sleuthkit.autopsy.ingest.runIngestModuleWizard.IngestProfileSelectionWizardPanel; +import org.sleuthkit.autopsy.ingest.runIngestModuleWizard.ShortcutWizardDescriptorPanel; /** * The iterator class for the "Add Image" wizard panel. This class is used to @@ -37,11 +38,11 @@ import org.sleuthkit.autopsy.ingest.runIngestModuleWizard.IngestProfileSelection class AddImageWizardIterator implements WizardDescriptor.Iterator { private int index = 0; - private List> panels; + private List panels; private AddImageAction action; private int progressPanelIndex; - private int profileSelectionIndex; - + private final static String PROP_LASTPROFILE_NAME = "AIW_LASTPROFILE_NAME"; //NON-NLS + AddImageWizardIterator(AddImageAction action) { this.action = action; } @@ -50,25 +51,23 @@ class AddImageWizardIterator implements WizardDescriptor.Iterator> getPanels() { + private List getPanels() { if (panels == null) { - panels = new ArrayList>(); + panels = new ArrayList<>(); AddImageWizardAddingProgressPanel progressPanel = new AddImageWizardAddingProgressPanel(); AddImageWizardChooseDataSourcePanel dsPanel = new AddImageWizardChooseDataSourcePanel(progressPanel); AddImageWizardIngestConfigPanel ingestConfigPanel = new AddImageWizardIngestConfigPanel(dsPanel, action, progressPanel); - IngestProfileSelectionWizardPanel profileSelectionPanel = new IngestProfileSelectionWizardPanel(AddImageWizardIngestConfigPanel.class.getCanonicalName()); + IngestProfileSelectionWizardPanel profileSelectionPanel = new IngestProfileSelectionWizardPanel(AddImageWizardIngestConfigPanel.class.getCanonicalName(), getPropLastprofileName()); panels.add(dsPanel); TreeMap profileMap = new IngestProfileMap().getIngestProfileMap(); if (!profileMap.isEmpty()) { panels.add(profileSelectionPanel); } - panels.add(ingestConfigPanel); panels.add(progressPanel); - progressPanelIndex = panels.indexOf(progressPanel); //Doing programatically incase more panels added - profileSelectionIndex = panels.indexOf(profileSelectionPanel); //will be -1 if it wasn't added + progressPanelIndex = panels.indexOf(progressPanel); //Doing programatically because number of panels is variable String[] steps = new String[panels.size()]; for (int i = 0; i < panels.size(); i++) { Component c = panels.get(i).getComponent(); @@ -101,14 +100,32 @@ class AddImageWizardIterator implements WizardDescriptor.Iterator current() { + public ShortcutWizardDescriptorPanel current() { if (panels != null) { return panels.get(index); } else { @@ -157,14 +174,12 @@ class AddImageWizardIterator implements WizardDescriptor.Iterator { +class IngestModulesConfigWizardPanel extends ShortcutWizardDescriptorPanel { /** * The visual ingestJobSettingsPanel that displays this panel. If you need @@ -76,9 +76,4 @@ class IngestModulesConfigWizardPanel implements WizardDescriptor.FinishablePanel wiz.putProperty("executionContext", RunIngestModulesAction.getDefaultContext()); //NON-NLS } - @Override - public boolean isFinishPanel() { - return true; - } - } diff --git a/Core/src/org/sleuthkit/autopsy/ingest/runIngestModuleWizard/IngestProfileSelectionWizardPanel.java b/Core/src/org/sleuthkit/autopsy/ingest/runIngestModuleWizard/IngestProfileSelectionWizardPanel.java index edfe5e1513..67abe8d3f7 100644 --- a/Core/src/org/sleuthkit/autopsy/ingest/runIngestModuleWizard/IngestProfileSelectionWizardPanel.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/runIngestModuleWizard/IngestProfileSelectionWizardPanel.java @@ -31,10 +31,11 @@ import org.sleuthkit.autopsy.coreutils.ModuleSettings; * selection panel and is only created when profiles exist. * */ -public class IngestProfileSelectionWizardPanel implements WizardDescriptor.Panel { +public class IngestProfileSelectionWizardPanel extends ShortcutWizardDescriptorPanel { + + private final Set listeners = new HashSet<>(1); - private final static String PROP_LASTPROFILE_NAME = "RIMW_LASTPROFILE_NAME"; //NON-NLS private final static String LAST_PROFILE_PROPERTIES_FILE = "IngestProfileSelectionPanel"; //NON-NLS /** * The visual component that displays this panel. If you need to access the @@ -42,9 +43,11 @@ public class IngestProfileSelectionWizardPanel implements WizardDescriptor.Panel */ private IngestProfileSelectionPanel component; private String lastProfileUsed; + private final String lastProfilePropertyName; private final String defaultContext; - public IngestProfileSelectionWizardPanel(String defaultContext) { + public IngestProfileSelectionWizardPanel(String defaultContext, String lastProfilePropertyName) { + this.lastProfilePropertyName = lastProfilePropertyName; this.defaultContext = defaultContext; } @@ -54,7 +57,15 @@ public class IngestProfileSelectionWizardPanel implements WizardDescriptor.Panel String getDefaultContext() { return defaultContext; } - + + /** + * Gets the name of the file which stores the last profile used properties. + * + * @return the LAST_PROFILE_PROPERTIES_FILE + */ + public static String getLastProfilePropertiesFile() { + return LAST_PROFILE_PROPERTIES_FILE; + } // 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 @@ -62,9 +73,9 @@ public class IngestProfileSelectionWizardPanel implements WizardDescriptor.Panel @Override public IngestProfileSelectionPanel getComponent() { if (component == null) { - if (!(ModuleSettings.getConfigSetting(LAST_PROFILE_PROPERTIES_FILE, PROP_LASTPROFILE_NAME) == null) - && !ModuleSettings.getConfigSetting(LAST_PROFILE_PROPERTIES_FILE, PROP_LASTPROFILE_NAME).isEmpty()) { - lastProfileUsed = ModuleSettings.getConfigSetting(LAST_PROFILE_PROPERTIES_FILE, PROP_LASTPROFILE_NAME); + if (!(ModuleSettings.getConfigSetting(LAST_PROFILE_PROPERTIES_FILE, lastProfilePropertyName) == null) + && !ModuleSettings.getConfigSetting(LAST_PROFILE_PROPERTIES_FILE, lastProfilePropertyName).isEmpty()) { + lastProfileUsed = ModuleSettings.getConfigSetting(LAST_PROFILE_PROPERTIES_FILE, lastProfilePropertyName); } else { lastProfileUsed = getDefaultContext(); } @@ -121,12 +132,16 @@ public class IngestProfileSelectionWizardPanel implements WizardDescriptor.Panel public void storeSettings(WizardDescriptor wiz) { lastProfileUsed = component.getLastSelectedProfile(); wiz.putProperty("executionContext", lastProfileUsed); //NON-NLS - ModuleSettings.setConfigSetting(LAST_PROFILE_PROPERTIES_FILE, PROP_LASTPROFILE_NAME, lastProfileUsed); - System.out.println("STORED LAST PROFILE USED AS: " + lastProfileUsed); + ModuleSettings.setConfigSetting(LAST_PROFILE_PROPERTIES_FILE, lastProfilePropertyName, lastProfileUsed); } - public boolean isFinishPanel() { + @Override + public boolean skipNextPanel() { return component.isLastPanel; } - + + @Override + public boolean panelEnablesSkipping(){ + return true; + } } diff --git a/Core/src/org/sleuthkit/autopsy/ingest/runIngestModuleWizard/RunIngestModulesWizardIterator.java b/Core/src/org/sleuthkit/autopsy/ingest/runIngestModuleWizard/RunIngestModulesWizardIterator.java index c7bae2a5e0..092b616f73 100644 --- a/Core/src/org/sleuthkit/autopsy/ingest/runIngestModuleWizard/RunIngestModulesWizardIterator.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/runIngestModuleWizard/RunIngestModulesWizardIterator.java @@ -35,9 +35,8 @@ import org.sleuthkit.autopsy.ingest.IngestProfileMap; final class RunIngestModulesWizardIterator implements WizardDescriptor.Iterator { private int index; - private int profilePanelIndex; - - private List> panels; + private final static String PROP_LASTPROFILE_NAME = "RIMW_LASTPROFILE_NAME"; //NON-NLS + private List panels; /** * Gets the list of panels used by this wizard for iterating over. @@ -45,17 +44,16 @@ final class RunIngestModulesWizardIterator implements WizardDescriptor.Iterator< * * @return panels - the list of of WizardDescriptor panels */ - private List> getPanels() { + private List getPanels() { if (panels == null) { panels = new ArrayList<>(); - IngestProfileSelectionWizardPanel profilePanel = new IngestProfileSelectionWizardPanel(RunIngestModulesAction.getDefaultContext()); + IngestProfileSelectionWizardPanel profilePanel = new IngestProfileSelectionWizardPanel(RunIngestModulesAction.getDefaultContext(), PROP_LASTPROFILE_NAME); TreeMap profileMap = new IngestProfileMap().getIngestProfileMap(); if (!profileMap.isEmpty()) { panels.add(profilePanel); } panels.add(new IngestModulesConfigWizardPanel()); - profilePanelIndex=panels.indexOf(profilePanel); String[] steps = new String[panels.size()]; for (int i = 0; i < panels.size(); i++) { Component c = panels.get(i).getComponent(); @@ -75,7 +73,7 @@ final class RunIngestModulesWizardIterator implements WizardDescriptor.Iterator< } @Override - public WizardDescriptor.Panel current() { + public ShortcutWizardDescriptorPanel current() { return getPanels().get(index); } @@ -88,7 +86,7 @@ final class RunIngestModulesWizardIterator implements WizardDescriptor.Iterator< @Override public boolean hasNext() { return (index < getPanels().size() - 1 && - !(index == profilePanelIndex && ((IngestProfileSelectionWizardPanel)current()).isFinishPanel())); + !(current().panelEnablesSkipping() && current().skipNextPanel())); } @Override diff --git a/Core/src/org/sleuthkit/autopsy/ingest/runIngestModuleWizard/ShortcutWizardDescriptorPanel.java b/Core/src/org/sleuthkit/autopsy/ingest/runIngestModuleWizard/ShortcutWizardDescriptorPanel.java new file mode 100644 index 0000000000..35c9cf7705 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/ingest/runIngestModuleWizard/ShortcutWizardDescriptorPanel.java @@ -0,0 +1,64 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2011-2017 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.ingest.runIngestModuleWizard; + +import org.openide.WizardDescriptor; + +/** + * An abstract class providing a methods which can be checked by + * the iterator containing panels of this type. So that Wizards containing these + * panels can skip panels, but still call necessary methods of those panels. + */ +public abstract class ShortcutWizardDescriptorPanel implements WizardDescriptor.Panel { + + /** + * Whether or not this panel under the correct conditions can enable the skipping of the panel after it. + * @return true or false + */ + public boolean panelEnablesSkipping(){ + /* + * This method should be overriden by any panel that might want to + * enable the iterator to skip the panel that comes after it. + */ + return false; + } + + /** + * Whether or not the panel immediately following this one should be skipped . + * + * @return true or false + */ + public boolean skipNextPanel(){ + /* + * This method should be overriden by any panel that might want to + * enable the iterator to skip the panel that comes after it. + */ + return false; + } + + /** + * Provides a method which will allow code to be executed in a panel you plan to skip + */ + public void processThisPanelBeforeSkipped(){ + /* + * If you need to perform some actions of this panel before it is skipped + * override this method to have it call the necessary code. + */ + } +}