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             if(ReportingConfigLoader.configExists(reportingConfigurationName)) {
 
   68                 config = ReportingConfigLoader.loadConfig(reportingConfigurationName);
 
   70         } 
catch (ReportConfigException ex) {
 
   71             logger.log(Level.SEVERE, 
"Unable to load reporting configuration " + reportingConfigurationName + 
". Using default settings", ex);
 
   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);
 
   80             firstPanel = 
new ReportWizardPanel1(null, useCaseSpecificData);
 
   81             tableConfigPanel = 
new ReportWizardPanel2(useCaseSpecificData, null);
 
   82             fileConfigPanel = 
new ReportWizardFileOptionsPanel(null);
 
   83             portableCaseConfigPanel = 
new ReportWizardPortableCaseOptionsPanel(null, useCaseSpecificData);
 
   86         if (useCaseSpecificData) {
 
   87             dataSourceSelectionPanel = 
new ReportWizardDataSourceSelectionPanel();
 
   88             allConfigPanels = 
new WizardDescriptor.Panel[]{firstPanel, dataSourceSelectionPanel, tableConfigPanel, fileConfigPanel, portableCaseConfigPanel};
 
   91             dataSourceSelectionPanel = null;
 
   92             allConfigPanels = 
new WizardDescriptor.Panel[]{firstPanel, tableConfigPanel, fileConfigPanel, portableCaseConfigPanel};
 
   95         tableConfigPanels = 
new WizardDescriptor.Panel[]{firstPanel, tableConfigPanel};
 
   96         fileConfigPanels = 
new WizardDescriptor.Panel[]{firstPanel, fileConfigPanel};
 
   97         portableCaseConfigPanels = 
new WizardDescriptor.Panel[]{firstPanel, portableCaseConfigPanel};
 
  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();
 
  107                 steps[i] = c.getName();
 
  108                 if (c instanceof JComponent) { 
 
  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);
 
  128     private void enableConfigPanels(
boolean generalModule, 
boolean tableModule, 
boolean portableCaseModule, 
boolean showDataSourceSelectionPanel) {
 
  129         boolean includedDataSourceSelection = showDataSourceSelectionPanel && dataSourceSelectionPanel != null;
 
  131             if(includedDataSourceSelection) {
 
  132                 panels = Arrays.asList(firstPanel, dataSourceSelectionPanel);
 
  134         } 
else if (tableModule) {
 
  137             panels = Arrays.asList(tableConfigPanels);
 
  138             if(includedDataSourceSelection) {
 
  139                 panels = 
new ArrayList<>(panels);
 
  140                 panels.add(1, dataSourceSelectionPanel);
 
  142         } 
else if (portableCaseModule) {
 
  145             panels = Arrays.asList(portableCaseConfigPanels);
 
  149             panels = Arrays.asList(fileConfigPanels);
 
  150             if(includedDataSourceSelection) {
 
  151                 panels = 
new ArrayList<>(panels);
 
  152                 panels.add(1, dataSourceSelectionPanel);
 
  158     public WizardDescriptor.Panel<WizardDescriptor> current() {
 
  159         return getPanels().get(index);
 
  163     public String name() {
 
  168     public boolean hasNext() {
 
  169         return index < getPanels().size() - 1;
 
  173     public boolean hasPrevious() {
 
  178     public void nextPanel() {
 
  180             throw new NoSuchElementException();
 
  185             boolean generalModule, tableModule, portableModule;
 
  187             generalModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean(
"generalModule", 
true); 
 
  188             tableModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean(
"tableModule", 
true); 
 
  189             portableModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean(
"portableCaseModule", 
true); 
 
  190             boolean showDataSourceSelectionPanel = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean(
"showDataSourceSelectionPanel", 
false); 
 
  191             enableConfigPanels(generalModule, tableModule, portableModule, showDataSourceSelectionPanel);
 
  198     public void previousPanel() {
 
  199         if (!hasPrevious()) {
 
  200             throw new NoSuchElementException();
 
  206     public void addChangeListener(ChangeListener l) {
 
  210     public void removeChangeListener(ChangeListener l) {
 
synchronized static Logger getLogger(String name)