Autopsy  4.14.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 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.Arrays;
23 import java.util.List;
24 import java.util.NoSuchElementException;
25 import java.util.logging.Level;
26 import javax.swing.JComponent;
27 import javax.swing.event.ChangeListener;
28 import org.openide.WizardDescriptor;
29 import org.openide.util.NbPreferences;
31 
32 final class ReportWizardIterator implements WizardDescriptor.Iterator<WizardDescriptor> {
33 
34  private static final Logger logger = Logger.getLogger(ReportWizardIterator.class.getName());
35  private int index;
36 
37  private final ReportWizardPanel1 firstPanel;
38  private final ReportWizardPanel2 tableConfigPanel;
39  private final ReportWizardFileOptionsPanel fileConfigPanel;
40  private final ReportWizardPortableCaseOptionsPanel portableCaseConfigPanel;
41 
42  private List<WizardDescriptor.Panel<WizardDescriptor>> panels;
43 
44  // Panels that should be shown if both Table and File report modules should
45  // be configured.
46  private final WizardDescriptor.Panel<WizardDescriptor>[] allConfigPanels;
47 
48  // Panels that should be shown if only Table report modules should
49  // be configured.
50  private final WizardDescriptor.Panel<WizardDescriptor>[] tableConfigPanels;
51 
52  // Panels that should be shown if only File report modules should
53  // be configured.
54  private final WizardDescriptor.Panel<WizardDescriptor>[] fileConfigPanels;
55 
56  // Panels that should be shown if only Portable Case report modules should
57  // be configured.
58  private final WizardDescriptor.Panel<WizardDescriptor>[] portableCaseConfigPanels;
59 
60  @SuppressWarnings({"rawtypes", "unchecked"})
61  ReportWizardIterator(String reportingConfigurationName, boolean useCaseSpecificData) {
62 
63  ReportingConfig config = null;
64  try {
65  config = ReportingConfigLoader.loadConfig(reportingConfigurationName);
66  } catch (ReportConfigException ex) {
67  logger.log(Level.SEVERE, "Unable to load reporting configuration " + reportingConfigurationName + ". Using default settings", ex);
68  }
69 
70  if (config != null) {
71  firstPanel = new ReportWizardPanel1(config.getModuleConfigs());
72  tableConfigPanel = new ReportWizardPanel2(useCaseSpecificData, config.getTableReportSettings());
73  fileConfigPanel = new ReportWizardFileOptionsPanel(config.getFileReportSettings());
74  portableCaseConfigPanel = new ReportWizardPortableCaseOptionsPanel(config.getModuleConfigs(), useCaseSpecificData);
75  } else {
76  firstPanel = new ReportWizardPanel1(null);
77  tableConfigPanel = new ReportWizardPanel2(useCaseSpecificData, null);
78  fileConfigPanel = new ReportWizardFileOptionsPanel(null);
79  portableCaseConfigPanel = new ReportWizardPortableCaseOptionsPanel(null, useCaseSpecificData);
80  }
81 
82  allConfigPanels = new WizardDescriptor.Panel[]{firstPanel, tableConfigPanel, fileConfigPanel, portableCaseConfigPanel};
83  tableConfigPanels = new WizardDescriptor.Panel[]{firstPanel, tableConfigPanel};
84  fileConfigPanels = new WizardDescriptor.Panel[]{firstPanel, fileConfigPanel};
85  portableCaseConfigPanels = new WizardDescriptor.Panel[]{firstPanel, portableCaseConfigPanel};
86  }
87 
88  private List<WizardDescriptor.Panel<WizardDescriptor>> getPanels() {
89  if (panels == null) {
90  panels = Arrays.asList(allConfigPanels);
91  String[] steps = new String[panels.size()];
92  for (int i = 0; i < panels.size(); i++) {
93  Component c = panels.get(i).getComponent();
94  // Default step name to component name of panel.
95  steps[i] = c.getName();
96  if (c instanceof JComponent) { // assume Swing components
97  JComponent jc = (JComponent) c;
98  jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i);
99  jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps);
100  jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, true);
101  jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, false);
102  jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, true);
103  }
104  }
105  }
106  return panels;
107  }
108 
116  private void enableConfigPanels(boolean generalModule, boolean tableModule, boolean portableCaseModule) {
117  if (generalModule) {
118  // General Module selected, no additional panels
119  } else if (tableModule) {
120  // Table Module selected, need Artifact Configuration Panel
121  // (ReportWizardPanel2)
122  panels = Arrays.asList(tableConfigPanels);
123  } else if (portableCaseModule) {
124  // Portable Case Module selected, need Portable Case Configuration Panel
125  // (ReportWizardPortableCaseOptionsPanel)
126  panels = Arrays.asList(portableCaseConfigPanels);
127  } else {
128  // File Module selected, need File Report Configuration Panel
129  // (ReportWizardFileOptionsPanel)
130  panels = Arrays.asList(fileConfigPanels);
131  }
132  }
133 
134  @Override
135  public WizardDescriptor.Panel<WizardDescriptor> current() {
136  return getPanels().get(index);
137  }
138 
139  @Override
140  public String name() {
141  return "";
142  }
143 
144  @Override
145  public boolean hasNext() {
146  return index < getPanels().size() - 1;
147  }
148 
149  @Override
150  public boolean hasPrevious() {
151  return index > 0;
152  }
153 
154  @Override
155  public void nextPanel() {
156  if (!hasNext()) {
157  throw new NoSuchElementException();
158  }
159 
160  if (index == 0) {
161  // Update path through configuration panels
162  boolean generalModule, tableModule, portableModule;
163  // These preferences are set in ReportWizardPanel1.storeSettings()
164  generalModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean("generalModule", true); //NON-NLS
165  tableModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean("tableModule", true); //NON-NLS
166  portableModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean("portableCaseModule", true); //NON-NLS
167  enableConfigPanels(generalModule, tableModule, portableModule);
168  }
169 
170  index++;
171  }
172 
173  @Override
174  public void previousPanel() {
175  if (!hasPrevious()) {
176  throw new NoSuchElementException();
177  }
178  index--;
179  }
180 
181  @Override
182  public void addChangeListener(ChangeListener l) {
183  }
184 
185  @Override
186  public void removeChangeListener(ChangeListener l) {
187  }
188 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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