Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ReportWizardIterator.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2012-2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.report.infrastructure;
20 
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;
32 
33 final class ReportWizardIterator implements WizardDescriptor.Iterator<WizardDescriptor> {
34 
35  private static final Logger logger = Logger.getLogger(ReportWizardIterator.class.getName());
36  private int index;
37 
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;
43 
44  private List<WizardDescriptor.Panel<WizardDescriptor>> panels;
45 
46  // Panels that should be shown if both Table and File report modules should
47  // be configured.
48  private final WizardDescriptor.Panel<WizardDescriptor>[] allConfigPanels;
49 
50  // Panels that should be shown if only Table report modules should
51  // be configured.
52  private final WizardDescriptor.Panel<WizardDescriptor>[] tableConfigPanels;
53 
54  // Panels that should be shown if only File report modules should
55  // be configured.
56  private final WizardDescriptor.Panel<WizardDescriptor>[] fileConfigPanels;
57 
58  // Panels that should be shown if only Portable Case report modules should
59  // be configured.
60  private final WizardDescriptor.Panel<WizardDescriptor>[] portableCaseConfigPanels;
61 
62  @SuppressWarnings({"rawtypes", "unchecked"})
63  ReportWizardIterator(String reportingConfigurationName, boolean useCaseSpecificData) {
64 
65  ReportingConfig config = null;
66  try {
67  if(ReportingConfigLoader.configExists(reportingConfigurationName)) {
68  config = ReportingConfigLoader.loadConfig(reportingConfigurationName);
69  }
70  } catch (ReportConfigException ex) {
71  logger.log(Level.SEVERE, "Unable to load reporting configuration " + reportingConfigurationName + ". Using default settings", ex);
72  }
73 
74  if (config != null) {
75  firstPanel = new ReportWizardPanel1(config.getModuleConfigs(), useCaseSpecificData);
76  tableConfigPanel = new ReportWizardPanel2(useCaseSpecificData, config.getTableReportSettings());
77  fileConfigPanel = new ReportWizardFileOptionsPanel(config.getFileReportSettings());
78  portableCaseConfigPanel = new ReportWizardPortableCaseOptionsPanel(config.getModuleConfigs(), useCaseSpecificData);
79  } else {
80  firstPanel = new ReportWizardPanel1(null, useCaseSpecificData);
81  tableConfigPanel = new ReportWizardPanel2(useCaseSpecificData, null);
82  fileConfigPanel = new ReportWizardFileOptionsPanel(null);
83  portableCaseConfigPanel = new ReportWizardPortableCaseOptionsPanel(null, useCaseSpecificData);
84  }
85 
86  if (useCaseSpecificData) {
87  dataSourceSelectionPanel = new ReportWizardDataSourceSelectionPanel();
88  allConfigPanels = new WizardDescriptor.Panel[]{firstPanel, dataSourceSelectionPanel, tableConfigPanel, fileConfigPanel, portableCaseConfigPanel};
89  }
90  else {
91  dataSourceSelectionPanel = null;
92  allConfigPanels = new WizardDescriptor.Panel[]{firstPanel, tableConfigPanel, fileConfigPanel, portableCaseConfigPanel};
93  }
94 
95  tableConfigPanels = new WizardDescriptor.Panel[]{firstPanel, tableConfigPanel};
96  fileConfigPanels = new WizardDescriptor.Panel[]{firstPanel, fileConfigPanel};
97  portableCaseConfigPanels = new WizardDescriptor.Panel[]{firstPanel, portableCaseConfigPanel};
98  }
99 
100  private List<WizardDescriptor.Panel<WizardDescriptor>> getPanels() {
101  if (panels == null) {
102  panels = Arrays.asList(allConfigPanels);
103  String[] steps = new String[panels.size()];
104  for (int i = 0; i < panels.size(); i++) {
105  Component c = panels.get(i).getComponent();
106  // Default step name to component name of panel.
107  steps[i] = c.getName();
108  if (c instanceof JComponent) { // assume Swing components
109  JComponent jc = (JComponent) c;
110  jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i);
111  jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps);
112  jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, true);
113  jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, false);
114  jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, true);
115  }
116  }
117  }
118  return panels;
119  }
120 
128  private void enableConfigPanels(boolean generalModule, boolean tableModule, boolean portableCaseModule, boolean showDataSourceSelectionPanel) {
129  boolean includedDataSourceSelection = showDataSourceSelectionPanel && dataSourceSelectionPanel != null;
130  if (generalModule) {
131  if(includedDataSourceSelection) {
132  panels = Arrays.asList(firstPanel, dataSourceSelectionPanel);
133  }
134  } else if (tableModule) {
135  // Table Module selected, need Artifact Configuration Panel
136  // (ReportWizardPanel2)
137  panels = Arrays.asList(tableConfigPanels);
138  if(includedDataSourceSelection) {
139  panels = new ArrayList<>(panels);
140  panels.add(1, dataSourceSelectionPanel);
141  }
142  } else if (portableCaseModule) {
143  // Portable Case Module selected, need Portable Case Configuration Panel
144  // (ReportWizardPortableCaseOptionsPanel)
145  panels = Arrays.asList(portableCaseConfigPanels);
146  } else {
147  // File Module selected, need File Report Configuration Panel
148  // (ReportWizardFileOptionsPanel)
149  panels = Arrays.asList(fileConfigPanels);
150  if(includedDataSourceSelection) {
151  panels = new ArrayList<>(panels);
152  panels.add(1, dataSourceSelectionPanel);
153  }
154  }
155  }
156 
157  @Override
158  public WizardDescriptor.Panel<WizardDescriptor> current() {
159  return getPanels().get(index);
160  }
161 
162  @Override
163  public String name() {
164  return "";
165  }
166 
167  @Override
168  public boolean hasNext() {
169  return index < getPanels().size() - 1;
170  }
171 
172  @Override
173  public boolean hasPrevious() {
174  return index > 0;
175  }
176 
177  @Override
178  public void nextPanel() {
179  if (!hasNext()) {
180  throw new NoSuchElementException();
181  }
182 
183  if (index == 0) {
184  // Update path through configuration panels
185  boolean generalModule, tableModule, portableModule;
186  // These preferences are set in ReportWizardPanel1.storeSettings()
187  generalModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean("generalModule", true); //NON-NLS
188  tableModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean("tableModule", true); //NON-NLS
189  portableModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean("portableCaseModule", true); //NON-NLS
190  boolean showDataSourceSelectionPanel = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean("showDataSourceSelectionPanel", false); // NON-NLS
191  enableConfigPanels(generalModule, tableModule, portableModule, showDataSourceSelectionPanel);
192  }
193 
194  index++;
195  }
196 
197  @Override
198  public void previousPanel() {
199  if (!hasPrevious()) {
200  throw new NoSuchElementException();
201  }
202  index--;
203  }
204 
205  @Override
206  public void addChangeListener(ChangeListener l) {
207  }
208 
209  @Override
210  public void removeChangeListener(ChangeListener l) {
211  }
212 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.