2199 Changed from casting to abstract class use and other clean up

This commit is contained in:
William Schaefer 2017-02-06 17:43:47 -05:00
parent b99efaf031
commit 288a993aaf
8 changed files with 145 additions and 75 deletions

View File

@ -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<WizardDescriptor> {
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;
}
}

View File

@ -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<WizardDescriptor>, 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;
}
}

View File

@ -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<WizardDescriptor> {
class AddImageWizardIngestConfigPanel extends ShortcutWizardDescriptorPanel {
private IngestJobSettingsPanel ingestJobSettingsPanel;
@ -60,7 +62,6 @@ class AddImageWizardIngestConfigPanel implements WizardDescriptor.FinishablePane
private final List<Content> newContents = Collections.synchronizedList(new ArrayList<Content>());
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;
}
}

View File

@ -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<WizardDescriptor> {
private int index = 0;
private List<WizardDescriptor.Panel<WizardDescriptor>> panels;
private List<ShortcutWizardDescriptorPanel> 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<WizardDescript
* Initialize panels representing individual wizard's steps and sets various
* properties for them influencing wizard appearance.
*/
private List<WizardDescriptor.Panel<WizardDescriptor>> getPanels() {
private List<ShortcutWizardDescriptorPanel> getPanels() {
if (panels == null) {
panels = new ArrayList<WizardDescriptor.Panel<WizardDescriptor>>();
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<String, IngestProfileMap.IngestProfile> 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<WizardDescript
public int getIndex() {
return index;
}
/**
* Gets the name of the property which stores the name of the last profile used by
* the Add Image Wizard.
*
* @return the PROP_LASTPROFILE_NAME
*/
static String getPropLastprofileName() {
return PROP_LASTPROFILE_NAME;
}
/**
* @return the PROP_LASTPROFILE_NAME
*/
static String getPROP_LASTPROFILE_NAME() {
return PROP_LASTPROFILE_NAME;
}
/**
* Gets the current panel.
*
* @return panel the current panel
*/
@Override
public WizardDescriptor.Panel<WizardDescriptor> current() {
public ShortcutWizardDescriptorPanel current() {
if (panels != null) {
return panels.get(index);
} else {
@ -157,14 +174,12 @@ class AddImageWizardIterator implements WizardDescriptor.Iterator<WizardDescript
if (!hasNext()) {
throw new NoSuchElementException();
}
int lastIndex = index;
boolean canBeSkipPanel = false;
if (lastIndex==profileSelectionIndex ) {
canBeSkipPanel = ((IngestProfileSelectionWizardPanel)current()).isFinishPanel();
}
boolean panelEnablesSkipping = current().panelEnablesSkipping();
boolean skipNextPanel = current().skipNextPanel();
index++;
if (lastIndex==profileSelectionIndex && canBeSkipPanel){
((AddImageWizardIngestConfigPanel)current()).skippingThisPanel();
if (panelEnablesSkipping && skipNextPanel){
current().processThisPanelBeforeSkipped();
nextPanel();
}
}

View File

@ -24,7 +24,7 @@ import org.openide.util.HelpCtx;
import org.sleuthkit.autopsy.ingest.IngestJobSettings;
import org.sleuthkit.autopsy.ingest.IngestJobSettingsPanel;
class IngestModulesConfigWizardPanel implements WizardDescriptor.FinishablePanel<WizardDescriptor> {
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;
}
}

View File

@ -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<WizardDescriptor> {
public class IngestProfileSelectionWizardPanel extends ShortcutWizardDescriptorPanel {
private final Set<ChangeListener> 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;
}
}

View File

@ -35,9 +35,8 @@ import org.sleuthkit.autopsy.ingest.IngestProfileMap;
final class RunIngestModulesWizardIterator implements WizardDescriptor.Iterator<WizardDescriptor> {
private int index;
private int profilePanelIndex;
private List<WizardDescriptor.Panel<WizardDescriptor>> panels;
private final static String PROP_LASTPROFILE_NAME = "RIMW_LASTPROFILE_NAME"; //NON-NLS
private List<ShortcutWizardDescriptorPanel> 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<WizardDescriptor.Panel<WizardDescriptor>> getPanels() {
private List<ShortcutWizardDescriptorPanel> getPanels() {
if (panels == null) {
panels = new ArrayList<>();
IngestProfileSelectionWizardPanel profilePanel = new IngestProfileSelectionWizardPanel(RunIngestModulesAction.getDefaultContext());
IngestProfileSelectionWizardPanel profilePanel = new IngestProfileSelectionWizardPanel(RunIngestModulesAction.getDefaultContext(), PROP_LASTPROFILE_NAME);
TreeMap<String, IngestProfileMap.IngestProfile> 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<WizardDescriptor> 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

View File

@ -0,0 +1,64 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2017 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.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<WizardDescriptor> {
/**
* 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.
*/
}
}