Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddImageWizardIterator.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 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.casemodule;
20 
21 import java.awt.Component;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.NoSuchElementException;
25 import javax.swing.JComponent;
26 import javax.swing.event.ChangeListener;
27 import org.openide.WizardDescriptor;
28 import org.openide.util.NbBundle;
32 import org.sleuthkit.datamodel.Host;
33 
38 class AddImageWizardIterator implements WizardDescriptor.Iterator<WizardDescriptor> {
39 
40  private int index = 0;
41  private List<ShortcutWizardDescriptorPanel> panels;
42  private final AddImageAction action;
43  private int progressPanelIndex;
44  private int dsPanelIndex;
45  private int hostPanelIndex;
46  private int ingestPanelIndex;
47  private final static String PROP_LASTPROFILE_NAME = "AIW_LASTPROFILE_NAME"; //NON-NLS
48  private AddImageWizardSelectHostPanel hostPanel = null;
49 
50  AddImageWizardIterator(AddImageAction action) {
51  this.action = action;
52  }
53 
58  private List<ShortcutWizardDescriptorPanel> getPanels() {
59  if (panels == null) {
60  panels = new ArrayList<>();
61  hostPanel = new AddImageWizardSelectHostPanel();
62  panels.add(hostPanel);
63  hostPanelIndex = panels.indexOf(hostPanel);
64  AddImageWizardSelectDspPanel dspSelection = new AddImageWizardSelectDspPanel();
65  panels.add(dspSelection);
66  AddImageWizardAddingProgressPanel progressPanel = new AddImageWizardAddingProgressPanel(action);
67  AddImageWizardDataSourceSettingsPanel dsPanel = new AddImageWizardDataSourceSettingsPanel();
68  AddImageWizardIngestConfigPanel ingestConfigPanel = new AddImageWizardIngestConfigPanel(progressPanel);
69  panels.add(dsPanel);
70  List<IngestProfiles.IngestProfile> profiles = IngestProfiles.getIngestProfiles();
71  if (!profiles.isEmpty()) {
72  panels.add(new IngestProfileSelectionWizardPanel(AddImageWizardIngestConfigPanel.class.getCanonicalName(), getPropLastprofileName()));
73  }
74  panels.add(ingestConfigPanel);
75  panels.add(progressPanel);
76  progressPanelIndex = panels.indexOf(progressPanel); //Doing programatically because number of panels is variable
77  dsPanelIndex = panels.indexOf(dsPanel);
78  ingestPanelIndex = panels.indexOf(ingestConfigPanel);
79  String[] steps = new String[panels.size()];
80  for (int i = 0; i < panels.size(); i++) {
81  Component c = panels.get(i).getComponent();
82  // Default step name to component name of panel.
83  steps[i] = c.getName();
84  if (c instanceof JComponent) { // assume Swing components
85  JComponent jc = (JComponent) c;
86  // Sets step number of a component
87  jc.putClientProperty("WizardPanel_contentSelectedIndex", i);
88  // Sets steps names for a panel
89  jc.putClientProperty("WizardPanel_contentData", steps);
90  // Turn on subtitle creation on each step
91  jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
92  // Show steps on the left side with the image on the background
93  jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
94  // Turn on numbering of all steps
95  jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE);
96  }
97  }
98  }
99  return panels;
100  }
101 
108  public int getIndex() {
109  return index;
110  }
111 
118  static String getPropLastprofileName() {
119  return PROP_LASTPROFILE_NAME;
120  }
121 
125  static String getPROP_LASTPROFILE_NAME() {
126  return PROP_LASTPROFILE_NAME;
127  }
128 
134  @Override
135  public ShortcutWizardDescriptorPanel current() {
136  if (panels != null) {
137  return panels.get(index);
138  } else {
139  return getPanels().get(index);
140  }
141  }
142 
148  @Override
149  public String name() {
150  return NbBundle.getMessage(this.getClass(), "AddImageWizardIterator.stepXofN", Integer.toString(index + 1),
151  getPanels().size());
152  }
153 
159  @Override
160  public boolean hasNext() {
161  return index < getPanels().size() - 1;
162  }
163 
169  @Override
170  // disable the previous button on all panels except the data source panel
171  public boolean hasPrevious() {
172  return (index <= dsPanelIndex && index > 0); //Users should be able to back up to select a different DSP
173  }
174 
179  @Override
180  public void nextPanel() {
181  if (!hasNext()) {
182  throw new NoSuchElementException();
183  }
184  // Start processing the data source by handing it off to the selected DSP,
185  // so it gets going in the background while the user is still picking the Ingest modules
186  // This will occur when the next button is clicked on the panel where you have chosen your data to process
187  if (index == ingestPanelIndex) {
188  AddImageWizardAddingProgressPanel addingProgressPanel = (AddImageWizardAddingProgressPanel) panels.get(progressPanelIndex);
189  AddImageWizardDataSourceSettingsVisual dspSettingsPanel = ((AddImageWizardDataSourceSettingsPanel) panels.get(dsPanelIndex)).getComponent();
190  Host host = (hostPanel == null) ? null : hostPanel.getSelectedHost();
191  addingProgressPanel.startDataSourceProcessing(dspSettingsPanel.getCurrentDSProcessor(), host);
192  }
193  boolean panelEnablesSkipping = current().panelEnablesSkipping();
194  boolean skipNextPanel = current().skipNextPanel();
195  index++;
196  if (panelEnablesSkipping && skipNextPanel) {
197  current().processThisPanelBeforeSkipped();
198  nextPanel();
199  }
200  }
201 
206  @Override
207  public void previousPanel() {
208  if (!hasPrevious()) {
209  throw new NoSuchElementException();
210  }
211  if (index == progressPanelIndex) {
212  index--;
213  }
214  index--;
215  }
216 
217  // If nothing unusual changes in the middle of the wizard, simply:
218  @Override
219  public void addChangeListener(ChangeListener l) {
220  }
221 
222  @Override
223  public void removeChangeListener(ChangeListener l) {
224  }
225 }

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