19 package org.sleuthkit.autopsy.casemodule;
21 import org.openide.util.NbBundle;
22 import java.awt.Color;
23 import java.awt.Component;
24 import java.awt.Window;
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.List;
28 import javax.swing.JButton;
29 import javax.swing.JOptionPane;
30 import javax.swing.SwingUtilities;
31 import javax.swing.event.ChangeListener;
32 import org.openide.WizardDescriptor;
33 import org.openide.util.HelpCtx;
47 class AddImageWizardIngestConfigPanel
implements WizardDescriptor.Panel<WizardDescriptor> {
50 private IngestJobSettingsPanel ingestJobSettingsPanel;
56 private Component component = null;
58 private final List<Content> newContents = Collections.synchronizedList(
new ArrayList<Content>());
59 private boolean ingested =
false;
60 private boolean readyToIngest =
false;
63 private AddImageAction.CleanupTask cleanupTask;
65 private final AddImageAction addImageAction;
67 private final AddImageWizardAddingProgressPanel progressPanel;
68 private final AddImageWizardChooseDataSourcePanel dataSourcePanel;
70 private DataSourceProcessor dsProcessor;
73 AddImageWizardIngestConfigPanel(AddImageWizardChooseDataSourcePanel dsPanel, AddImageAction action, AddImageWizardAddingProgressPanel proPanel) {
74 this.addImageAction = action;
75 this.progressPanel = proPanel;
76 this.dataSourcePanel = dsPanel;
78 IngestJobSettings ingestJobSettings =
new IngestJobSettings(AddImageWizardIngestConfigPanel.class.getCanonicalName());
79 showWarnings(ingestJobSettings);
80 this.ingestJobSettingsPanel =
new IngestJobSettingsPanel(ingestJobSettings);
92 public Component getComponent() {
93 if (component == null) {
94 component =
new AddImageWizardIngestConfigVisual(this.ingestJobSettingsPanel);
106 public HelpCtx getHelp() {
108 return HelpCtx.DEFAULT_HELP;
120 public boolean isValid() {
136 public final void addChangeListener(ChangeListener l) {
145 public final void removeChangeListener(ChangeListener l) {
161 public void readSettings(WizardDescriptor settings) {
162 JButton cancel =
new JButton(
163 NbBundle.getMessage(
this.getClass(),
"AddImageWizardIngestConfigPanel.CANCEL_BUTTON.text"));
164 cancel.setEnabled(
false);
165 settings.setOptions(
new Object[]{WizardDescriptor.PREVIOUS_OPTION, WizardDescriptor.NEXT_OPTION, WizardDescriptor.FINISH_OPTION, cancel});
167 readyToIngest =
false;
173 startDataSourceProcessing(settings);
186 public void storeSettings(WizardDescriptor settings) {
187 IngestJobSettings ingestJobSettings = this.ingestJobSettingsPanel.getSettings();
188 ingestJobSettings.save();
189 showWarnings(ingestJobSettings);
192 readyToIngest =
true;
196 private static void showWarnings(IngestJobSettings ingestJobSettings) {
197 List<String> warnings = ingestJobSettings.getWarnings();
198 if (warnings.isEmpty() ==
false) {
199 StringBuilder warningMessage =
new StringBuilder();
200 for (String warning : warnings) {
201 warningMessage.append(warning).append(
"\n");
203 JOptionPane.showMessageDialog(null, warningMessage.toString());
211 private void startIngest() {
212 if (!newContents.isEmpty() && readyToIngest && !ingested) {
214 IngestManager.getInstance().queueIngestJob(newContents, ingestJobSettingsPanel.getSettings());
215 progressPanel.setStateFinished();
222 private void startDataSourceProcessing(WizardDescriptor settings) {
228 cleanupTask = addImageAction.new CleanupTask() {
230 void cleanup() throws Exception {
231 cancelDataSourceProcessing();
235 cleanupTask.enable();
238 dsProcessor = dataSourcePanel.getComponent().getCurrentDSProcessor();
240 DataSourceProcessorCallback cbObj =
new DataSourceProcessorCallback () {
242 public void doneEDT(DataSourceProcessorCallback.DataSourceProcessorResult result, List<String> errList, List<Content> contents) {
243 dataSourceProcessorDone(result, errList, contents );
248 progressPanel.setStateStarted();
251 dsProcessor.run(progressPanel.getDSPProgressMonitorImpl(), cbObj);
258 private void cancelDataSourceProcessing() {
259 dsProcessor.cancel();
266 private void dataSourceProcessorDone(DataSourceProcessorCallback.DataSourceProcessorResult result, List<String> errList, List<Content> contents) {
269 cleanupTask.disable();
272 java.awt.Toolkit.getDefaultToolkit().beep();
273 AddImageWizardAddingProgressVisual panel = progressPanel.getComponent();
275 Window w = SwingUtilities.getWindowAncestor(panel);
281 progressPanel.setStateFinished();
285 if (result == DataSourceProcessorCallback.DataSourceProcessorResult.NO_ERRORS)
286 progressPanel.getComponent().setProgressBarTextAndColor(
287 NbBundle.getMessage(
this.getClass(),
"AddImageWizardIngestConfigPanel.dsProcDone.noErrs.text"), 100, Color.black);
289 progressPanel.getComponent().setProgressBarTextAndColor(
290 NbBundle.getMessage(
this.getClass(),
"AddImageWizardIngestConfigPanel.dsProcDone.errs.text"), 100, Color.red);
294 boolean critErr =
false;
295 if (result == DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS) {
298 for ( String err: errList ) {
300 progressPanel.addErrors(err, critErr);
304 newContents.addAll(contents);
307 if (!newContents.isEmpty()) {
309 Case.getCurrentCase().notifyNewDataSource(newContents.get(0));
314 progressPanel.setStateStarted();