Autopsy  4.15.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  config = ReportingConfigLoader.loadConfig(reportingConfigurationName);
68  } catch (ReportConfigException ex) {
69  logger.log(Level.SEVERE, "Unable to load reporting configuration " + reportingConfigurationName + ". Using default settings", ex);
70  }
71 
72  if (config != null) {
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);
77  } else {
78  firstPanel = new ReportWizardPanel1(null);
79  tableConfigPanel = new ReportWizardPanel2(useCaseSpecificData, null);
80  fileConfigPanel = new ReportWizardFileOptionsPanel(null);
81  portableCaseConfigPanel = new ReportWizardPortableCaseOptionsPanel(null, useCaseSpecificData);
82  }
83 
84  dataSourceSelectionPanel = new ReportWizardDataSourceSelectionPanel();
85 
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};
90  }
91 
92  private List<WizardDescriptor.Panel<WizardDescriptor>> getPanels() {
93  if (panels == null) {
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();
98  // Default step name to component name of panel.
99  steps[i] = c.getName();
100  if (c instanceof JComponent) { // assume Swing components
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);
107  }
108  }
109  }
110  return panels;
111  }
112 
120  private void enableConfigPanels(boolean generalModule, boolean tableModule, boolean portableCaseModule, boolean showDataSourceSelectionPanel) {
121  if (generalModule) {
122  if(showDataSourceSelectionPanel) {
123  panels = Arrays.asList(firstPanel, dataSourceSelectionPanel);
124  }
125  } else if (tableModule) {
126  // Table Module selected, need Artifact Configuration Panel
127  // (ReportWizardPanel2)
128  panels = Arrays.asList(tableConfigPanels);
129  if(showDataSourceSelectionPanel) {
130  panels = new ArrayList<>(panels);
131  panels.add(1, dataSourceSelectionPanel);
132  }
133  } else if (portableCaseModule) {
134  // Portable Case Module selected, need Portable Case Configuration Panel
135  // (ReportWizardPortableCaseOptionsPanel)
136  panels = Arrays.asList(portableCaseConfigPanels);
137  } else {
138  // File Module selected, need File Report Configuration Panel
139  // (ReportWizardFileOptionsPanel)
140  panels = Arrays.asList(fileConfigPanels);
141  if(showDataSourceSelectionPanel) {
142  panels = new ArrayList<>(panels);
143  panels.add(1, dataSourceSelectionPanel);
144  }
145  }
146  }
147 
148  @Override
149  public WizardDescriptor.Panel<WizardDescriptor> current() {
150  return getPanels().get(index);
151  }
152 
153  @Override
154  public String name() {
155  return "";
156  }
157 
158  @Override
159  public boolean hasNext() {
160  return index < getPanels().size() - 1;
161  }
162 
163  @Override
164  public boolean hasPrevious() {
165  return index > 0;
166  }
167 
168  @Override
169  public void nextPanel() {
170  if (!hasNext()) {
171  throw new NoSuchElementException();
172  }
173 
174  if (index == 0) {
175  // Update path through configuration panels
176  boolean generalModule, tableModule, portableModule;
177  // These preferences are set in ReportWizardPanel1.storeSettings()
178  generalModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean("generalModule", true); //NON-NLS
179  tableModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean("tableModule", true); //NON-NLS
180  portableModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean("portableCaseModule", true); //NON-NLS
181  boolean showDataSourceSelectionPanel = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean("showDataSourceSelectionPanel", false); // NON-NLS
182  enableConfigPanels(generalModule, tableModule, portableModule, showDataSourceSelectionPanel);
183  }
184 
185  index++;
186  }
187 
188  @Override
189  public void previousPanel() {
190  if (!hasPrevious()) {
191  throw new NoSuchElementException();
192  }
193  index--;
194  }
195 
196  @Override
197  public void addChangeListener(ChangeListener l) {
198  }
199 
200  @Override
201  public void removeChangeListener(ChangeListener l) {
202  }
203 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2020 Basis Technology. Generated on: Mon Jul 6 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.