19 package org.sleuthkit.autopsy.report.infrastructure;
21 import java.awt.Component;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.NoSuchElementException;
26 import java.util.logging.Level;
27 import javax.swing.JComponent;
28 import javax.swing.event.ChangeListener;
29 import org.openide.WizardDescriptor;
30 import org.openide.util.NbPreferences;
33 final class ReportWizardIterator
implements WizardDescriptor.Iterator<WizardDescriptor> {
35 private static final Logger logger = Logger.
getLogger(ReportWizardIterator.class.getName());
38 private final ReportWizardPanel1 firstPanel;
39 private final ReportWizardPanel2 tableConfigPanel;
40 private final ReportWizardFileOptionsPanel fileConfigPanel;
41 private final ReportWizardPortableCaseOptionsPanel portableCaseConfigPanel;
42 private final ReportWizardDataSourceSelectionPanel dataSourceSelectionPanel;
44 private List<WizardDescriptor.Panel<WizardDescriptor>> panels;
48 private final WizardDescriptor.Panel<WizardDescriptor>[] allConfigPanels;
52 private final WizardDescriptor.Panel<WizardDescriptor>[] tableConfigPanels;
56 private final WizardDescriptor.Panel<WizardDescriptor>[] fileConfigPanels;
60 private final WizardDescriptor.Panel<WizardDescriptor>[] portableCaseConfigPanels;
62 @SuppressWarnings({
"rawtypes",
"unchecked"})
63 ReportWizardIterator(String reportingConfigurationName,
boolean useCaseSpecificData) {
65 ReportingConfig config = null;
67 config = ReportingConfigLoader.loadConfig(reportingConfigurationName);
68 }
catch (ReportConfigException ex) {
69 logger.log(Level.SEVERE,
"Unable to load reporting configuration " + reportingConfigurationName +
". Using default settings", ex);
73 firstPanel =
new ReportWizardPanel1(config.getModuleConfigs());
74 tableConfigPanel =
new ReportWizardPanel2(useCaseSpecificData, config.getTableReportSettings());
75 fileConfigPanel =
new ReportWizardFileOptionsPanel(config.getFileReportSettings());
76 portableCaseConfigPanel =
new ReportWizardPortableCaseOptionsPanel(config.getModuleConfigs(), useCaseSpecificData);
78 firstPanel =
new ReportWizardPanel1(null);
79 tableConfigPanel =
new ReportWizardPanel2(useCaseSpecificData, null);
80 fileConfigPanel =
new ReportWizardFileOptionsPanel(null);
81 portableCaseConfigPanel =
new ReportWizardPortableCaseOptionsPanel(null, useCaseSpecificData);
84 dataSourceSelectionPanel =
new ReportWizardDataSourceSelectionPanel();
86 allConfigPanels =
new WizardDescriptor.Panel[]{firstPanel, dataSourceSelectionPanel, tableConfigPanel, fileConfigPanel, portableCaseConfigPanel};
87 tableConfigPanels =
new WizardDescriptor.Panel[]{firstPanel, tableConfigPanel};
88 fileConfigPanels =
new WizardDescriptor.Panel[]{firstPanel, fileConfigPanel};
89 portableCaseConfigPanels =
new WizardDescriptor.Panel[]{firstPanel, portableCaseConfigPanel};
92 private List<WizardDescriptor.Panel<WizardDescriptor>> getPanels() {
94 panels = Arrays.asList(allConfigPanels);
95 String[] steps =
new String[panels.size()];
96 for (
int i = 0; i < panels.size(); i++) {
97 Component c = panels.get(i).getComponent();
99 steps[i] = c.getName();
100 if (c instanceof JComponent) {
101 JComponent jc = (JComponent) c;
102 jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i);
103 jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps);
104 jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE,
true);
105 jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED,
false);
106 jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED,
true);
120 private void enableConfigPanels(
boolean generalModule,
boolean tableModule,
boolean portableCaseModule,
boolean showDataSourceSelectionPanel) {
122 if(showDataSourceSelectionPanel) {
123 panels = Arrays.asList(firstPanel, dataSourceSelectionPanel);
125 }
else if (tableModule) {
128 panels = Arrays.asList(tableConfigPanels);
129 if(showDataSourceSelectionPanel) {
130 panels =
new ArrayList<>(panels);
131 panels.add(1, dataSourceSelectionPanel);
133 }
else if (portableCaseModule) {
136 panels = Arrays.asList(portableCaseConfigPanels);
140 panels = Arrays.asList(fileConfigPanels);
141 if(showDataSourceSelectionPanel) {
142 panels =
new ArrayList<>(panels);
143 panels.add(1, dataSourceSelectionPanel);
149 public WizardDescriptor.Panel<WizardDescriptor> current() {
150 return getPanels().get(index);
154 public String name() {
159 public boolean hasNext() {
160 return index < getPanels().size() - 1;
164 public boolean hasPrevious() {
169 public void nextPanel() {
171 throw new NoSuchElementException();
176 boolean generalModule, tableModule, portableModule;
178 generalModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean(
"generalModule",
true);
179 tableModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean(
"tableModule",
true);
180 portableModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean(
"portableCaseModule",
true);
181 boolean showDataSourceSelectionPanel = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean(
"showDataSourceSelectionPanel",
false);
182 enableConfigPanels(generalModule, tableModule, portableModule, showDataSourceSelectionPanel);
189 public void previousPanel() {
190 if (!hasPrevious()) {
191 throw new NoSuchElementException();
197 public void addChangeListener(ChangeListener l) {
201 public void removeChangeListener(ChangeListener l) {
synchronized static Logger getLogger(String name)