Loading UI settings based on input configuration, bug fixes

This commit is contained in:
Eugene Livis 2019-08-20 12:38:52 -04:00
parent 17580c484d
commit 269662c591
6 changed files with 83 additions and 57 deletions

View File

@ -68,25 +68,20 @@ final class ReportVisualPanel2 extends JPanel {
/** /**
* Creates new form ReportVisualPanel2 * Creates new form ReportVisualPanel2
*/ */
public ReportVisualPanel2(ReportWizardPanel2 wizPanel, boolean useCaseSpecificData) { public ReportVisualPanel2(ReportWizardPanel2 wizPanel, boolean useCaseSpecificData, TableReportSettings settings) {
this.useCaseSpecificData = useCaseSpecificData;
initComponents(); initComponents();
initTags(); initTags();
initArtifactTypes(); initArtifactTypes();
tagsList.setEnabled(false);
selectAllButton.setEnabled(false);
deselectAllButton.setEnabled(false);
allResultsRadioButton.setSelected(true);
advancedButton.setEnabled(useCaseSpecificData);
specificTaggedResultsRadioButton.setEnabled(useCaseSpecificData);
this.wizPanel = wizPanel; this.wizPanel = wizPanel;
this.useCaseSpecificData = useCaseSpecificData;
this.allResultsRadioButton.addChangeListener(new ChangeListener() { this.allResultsRadioButton.addChangeListener(new ChangeListener() {
@Override @Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
tagsList.setEnabled(specificTaggedResultsRadioButton.isSelected()); tagsList.setEnabled(specificTaggedResultsRadioButton.isSelected());
selectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected()); selectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
deselectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected()); deselectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
advancedButton.setEnabled(!specificTaggedResultsRadioButton.isSelected() && useCaseSpecificData); advancedButton.setEnabled(allResultsRadioButton.isSelected() && useCaseSpecificData);
updateFinishButton(); updateFinishButton();
} }
}); });
@ -96,7 +91,7 @@ final class ReportVisualPanel2 extends JPanel {
tagsList.setEnabled(specificTaggedResultsRadioButton.isSelected()); tagsList.setEnabled(specificTaggedResultsRadioButton.isSelected());
selectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected()); selectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
deselectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected()); deselectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
advancedButton.setEnabled(!specificTaggedResultsRadioButton.isSelected() && useCaseSpecificData); advancedButton.setEnabled(allResultsRadioButton.isSelected() && useCaseSpecificData);
updateFinishButton(); updateFinishButton();
} }
}); });
@ -106,16 +101,48 @@ final class ReportVisualPanel2 extends JPanel {
tagsList.setEnabled(specificTaggedResultsRadioButton.isSelected()); tagsList.setEnabled(specificTaggedResultsRadioButton.isSelected());
selectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected()); selectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
deselectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected()); deselectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
advancedButton.setEnabled(!specificTaggedResultsRadioButton.isSelected() && useCaseSpecificData); advancedButton.setEnabled(allResultsRadioButton.isSelected() && useCaseSpecificData);
updateFinishButton(); updateFinishButton();
} }
}); });
// enable things based on input settings
advancedButton.setEnabled(useCaseSpecificData);
specificTaggedResultsRadioButton.setEnabled(useCaseSpecificData);
TableReportSettings.TableReportType type = TableReportSettings.TableReportType.ALL_RESULTS;
if (settings != null) {
type = settings.getReportType();
}
switch (type) {
case ALL_TAGGED_RESULTS:
allTaggedResultsRadioButton.setSelected(true);
tagsList.setEnabled(false);
selectAllButton.setEnabled(false);
deselectAllButton.setEnabled(false);
break;
case SPECIFIC_TAGGED_RESULTS:
specificTaggedResultsRadioButton.setSelected(useCaseSpecificData);
tagsList.setEnabled(useCaseSpecificData);
selectAllButton.setEnabled(useCaseSpecificData);
deselectAllButton.setEnabled(useCaseSpecificData);
break;
case ALL_RESULTS:
default:
allResultsRadioButton.setSelected(true);
tagsList.setEnabled(false);
selectAllButton.setEnabled(false);
deselectAllButton.setEnabled(false);
break;
}
} }
// Initialize the list of Tags // Initialize the list of Tags
private void initTags() { private void initTags() {
List<TagName> tagNamesInUse = new ArrayList<>(); List<TagName> tagNamesInUse = new ArrayList<>();
// NOTE: we do not want to load tag names that came from persisted settings
// because there might have been new/additional tag names that have been added
// by user. We should read tag names from the database each time.
try { try {
// only try to load tag names if we are displaying case specific data, otherwise // only try to load tag names if we are displaying case specific data, otherwise
// there may not be a case open. // there may not be a case open.
@ -162,6 +189,12 @@ final class ReportVisualPanel2 extends JPanel {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void initArtifactTypes() { private void initArtifactTypes() {
// only try to load existing artifact types if we are displaying case
// specific data, otherwise there may not be a case open.
if (!useCaseSpecificData) {
return;
}
try { try {
Case openCase = Case.getCurrentCaseThrows(); Case openCase = Case.getCurrentCaseThrows();
ArrayList<BlackboardArtifact.Type> doNotReport = new ArrayList<>(); ArrayList<BlackboardArtifact.Type> doNotReport = new ArrayList<>();
@ -172,13 +205,8 @@ final class ReportVisualPanel2 extends JPanel {
BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getLabel(), BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getLabel(),
BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getDisplayName())); // output is too unstructured for table review BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getDisplayName())); // output is too unstructured for table review
if (useCaseSpecificData) { // get artifact types that exist in the current case
// get artifact types that exist in the current case artifacts = openCase.getSleuthkitCase().getArtifactTypesInUse();
artifacts = openCase.getSleuthkitCase().getArtifactTypesInUse();
} else {
// get all possible artifact types
openCase.getSleuthkitCase().getArtifactTypes().forEach(artifacts::add);
}
artifacts.removeAll(doNotReport); artifacts.removeAll(doNotReport);
@ -241,14 +269,15 @@ final class ReportVisualPanel2 extends JPanel {
} }
/** /**
* @return true if the Specific Tags radio button is selected, false otherwise * @return true if the Specific Tags radio button is selected, false
* otherwise
*/ */
TableReportSettings.TableReportType getSelectedReportType() { TableReportSettings.TableReportType getSelectedReportType() {
if (allTaggedResultsRadioButton.isSelected()) { if (allTaggedResultsRadioButton.isSelected()) {
return TableReportSettings.TableReportType.ALL_TAGGED_RESULTS; return TableReportSettings.TableReportType.ALL_TAGGED_RESULTS;
} else if (specificTaggedResultsRadioButton.isSelected()) { } else if (specificTaggedResultsRadioButton.isSelected()) {
return TableReportSettings.TableReportType.SPECIFIC_TAGGED_RESULTS; return TableReportSettings.TableReportType.SPECIFIC_TAGGED_RESULTS;
} }
return TableReportSettings.TableReportType.ALL_RESULTS; return TableReportSettings.TableReportType.ALL_RESULTS;
} }

View File

@ -57,7 +57,7 @@ public final class ReportWizardAction extends CallableSystemAction implements Pr
private static final Logger logger = Logger.getLogger(ReportWizardAction.class.getName()); private static final Logger logger = Logger.getLogger(ReportWizardAction.class.getName());
private static final String REPORTING_CONFIGURATION_NAME = "ReportAction"; private static final String REPORTING_CONFIGURATION_NAME = "ReportAction";
private static final boolean DISPLAY_CASE_SPECIFIC_DATA = false; // ELTODO true; private static final boolean DISPLAY_CASE_SPECIFIC_DATA = true;
private static final boolean RUN_REPORTS = true; private static final boolean RUN_REPORTS = true;
private final JButton toolbarButton = new JButton(); private final JButton toolbarButton = new JButton();
private static final String ACTION_NAME = NbBundle.getMessage(ReportWizardAction.class, "ReportWizardAction.actionName.text"); private static final String ACTION_NAME = NbBundle.getMessage(ReportWizardAction.class, "ReportWizardAction.actionName.text");

View File

@ -36,8 +36,10 @@ class ReportWizardFileOptionsPanel implements WizardDescriptor.FinishablePanel<W
private WizardDescriptor wiz; private WizardDescriptor wiz;
private ReportWizardFileOptionsVisualPanel component; private ReportWizardFileOptionsVisualPanel component;
private final JButton finishButton; private final JButton finishButton;
private final FileReportSettings settings;
ReportWizardFileOptionsPanel(FileReportSettings fileReportSettings) { ReportWizardFileOptionsPanel(FileReportSettings settings) {
this.settings = settings;
finishButton = new JButton( finishButton = new JButton(
NbBundle.getMessage(this.getClass(), "ReportWizardFileOptionsPanel.finishButton.text")); NbBundle.getMessage(this.getClass(), "ReportWizardFileOptionsPanel.finishButton.text"));
finishButton.setEnabled(false); finishButton.setEnabled(false);
@ -65,7 +67,7 @@ class ReportWizardFileOptionsPanel implements WizardDescriptor.FinishablePanel<W
@Override @Override
public ReportWizardFileOptionsVisualPanel getComponent() { public ReportWizardFileOptionsVisualPanel getComponent() {
if (component == null) { if (component == null) {
component = new ReportWizardFileOptionsVisualPanel(this); component = new ReportWizardFileOptionsVisualPanel(this, settings);
} }
return component; return component;
} }

View File

@ -21,10 +21,12 @@ package org.sleuthkit.autopsy.report;
import java.awt.Component; import java.awt.Component;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JList; import javax.swing.JList;
@ -39,15 +41,15 @@ import org.openide.util.NbBundle;
@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
class ReportWizardFileOptionsVisualPanel extends javax.swing.JPanel { class ReportWizardFileOptionsVisualPanel extends javax.swing.JPanel {
private List<FileReportDataTypes> options; private List<FileReportDataTypes> options = new ArrayList<>();
private final Map<FileReportDataTypes, Boolean> optionStates = new EnumMap<>(FileReportDataTypes.class); private final Map<FileReportDataTypes, Boolean> optionStates = new EnumMap<>(FileReportDataTypes.class);
private ListModel<FileReportDataTypes> model; private ListModel<FileReportDataTypes> model;
private final ReportWizardFileOptionsPanel wizPanel; private final ReportWizardFileOptionsPanel wizPanel;
public ReportWizardFileOptionsVisualPanel(ReportWizardFileOptionsPanel wizPanel) { public ReportWizardFileOptionsVisualPanel(ReportWizardFileOptionsPanel wizPanel, FileReportSettings settings) {
this.wizPanel = wizPanel; this.wizPanel = wizPanel;
initComponents(); initComponents();
initOptionsList(); initOptionsList(settings);
} }
@Override @Override
@ -58,10 +60,19 @@ class ReportWizardFileOptionsVisualPanel extends javax.swing.JPanel {
/** /**
* Populate the list of File Report Information that can be selected. * Populate the list of File Report Information that can be selected.
*/ */
private void initOptionsList() { private void initOptionsList(FileReportSettings settings) {
options = Arrays.asList(FileReportDataTypes.values()); if (settings != null && settings.getFileProperties() != null && !settings.getFileProperties().isEmpty()) {
for (FileReportDataTypes col : options) { // load the configuration
optionStates.put(col, Boolean.FALSE); for (Entry<FileReportDataTypes, Boolean> entry : settings.getFileProperties().entrySet()) {
optionStates.put(entry.getKey(), entry.getValue());
options.add(entry.getKey());
}
} else {
// load defaults
options = Arrays.asList(FileReportDataTypes.values());
for (FileReportDataTypes entry : options) {
optionStates.put(entry, Boolean.FALSE);
}
} }
model = new OptionsListModel(); model = new OptionsListModel();

View File

@ -33,9 +33,11 @@ class ReportWizardPanel2 implements WizardDescriptor.Panel<WizardDescriptor> {
private final JButton nextButton; private final JButton nextButton;
private WizardDescriptor wiz; private WizardDescriptor wiz;
private final boolean useCaseSpecificData; private final boolean useCaseSpecificData;
private final TableReportSettings settings;
ReportWizardPanel2(boolean useCaseSpecificData, TableReportSettings tableReportSettings) { ReportWizardPanel2(boolean useCaseSpecificData, TableReportSettings settings) {
this.useCaseSpecificData = useCaseSpecificData; this.useCaseSpecificData = useCaseSpecificData;
this.settings = settings;
finishButton = new JButton(NbBundle.getMessage(this.getClass(), "ReportWizardPanel2.finishButton.text")); finishButton = new JButton(NbBundle.getMessage(this.getClass(), "ReportWizardPanel2.finishButton.text"));
nextButton = new JButton(NbBundle.getMessage(this.getClass(), "ReportWizardPanel2.nextButton.text")); nextButton = new JButton(NbBundle.getMessage(this.getClass(), "ReportWizardPanel2.nextButton.text"));
nextButton.setEnabled(true); nextButton.setEnabled(true);
@ -58,7 +60,7 @@ class ReportWizardPanel2 implements WizardDescriptor.Panel<WizardDescriptor> {
@Override @Override
public ReportVisualPanel2 getComponent() { public ReportVisualPanel2 getComponent() {
if (component == null) { if (component == null) {
component = new ReportVisualPanel2(this, useCaseSpecificData); component = new ReportVisualPanel2(this, useCaseSpecificData, settings);
} }
return component; return component;
} }

View File

@ -41,10 +41,10 @@ final class TableReportSettings implements Serializable {
} }
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private List<BlackboardArtifact.Type> artifactTypes = new ArrayList<>(); private final List<BlackboardArtifact.Type> artifactTypes = new ArrayList<>();
private List<String> tagNames = new ArrayList<>(); private final List<String> tagNames = new ArrayList<>();
private boolean useCaseSpecificData = false; private final boolean useCaseSpecificData;
private TableReportType reportType = TableReportType.ALL_RESULTS; private final TableReportType reportType;
/** /**
* Creates TableReportSettings object. This constructor is used when user * Creates TableReportSettings object. This constructor is used when user
@ -55,6 +55,8 @@ final class TableReportSettings implements Serializable {
* types to be included in the report. Only enabled entries will be kept. * types to be included in the report. Only enabled entries will be kept.
* @param tagNameSelections The enabled/disabled state of the tag names to * @param tagNameSelections The enabled/disabled state of the tag names to
* be included in the report. Only enabled entries will be kept. * be included in the report. Only enabled entries will be kept.
* @param useCaseSpecificData Flag whether to use case specific tag and artifact data.
* @param reportType Table report type.
*/ */
TableReportSettings(Map<BlackboardArtifact.Type, Boolean> artifactTypeSelections, Map<String, Boolean> tagNameSelections, boolean useCaseSpecificData, TableReportType reportType) { TableReportSettings(Map<BlackboardArtifact.Type, Boolean> artifactTypeSelections, Map<String, Boolean> tagNameSelections, boolean useCaseSpecificData, TableReportType reportType) {
// Get the artifact types selected by the user // Get the artifact types selected by the user
@ -76,26 +78,6 @@ final class TableReportSettings implements Serializable {
this.useCaseSpecificData = useCaseSpecificData; this.useCaseSpecificData = useCaseSpecificData;
} }
// ELTODO remove this constructor?
/*TableReportSettings(List<BlackboardArtifact.Type> artifactTypes, List<String> tagNames, boolean useCaseSpecificData) {
this.artifactTypes = artifactTypes;
this.tagNames = tagNames;
this.useCaseSpecificData = useCaseSpecificData;
}*/
/**
* Creates TableReportSettings object. This constructor is used when user
* configures command line ingest. Most likely there will be no case open at
* the time, so tags and artifacts will have to be read from database at the
* report execution time.
*
* @param useCaseSpecificData
* @param reportType
*/
/*TableReportSettings(boolean useCaseSpecificData, TableReportType reportType) {
this.useCaseSpecificData = useCaseSpecificData;
this.reportType = reportType;
}*/
List<BlackboardArtifact.Type> getArtifactSelections() { List<BlackboardArtifact.Type> getArtifactSelections() {
return artifactTypes; return artifactTypes;
} }