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 java.util.UUID;
29 import javax.swing.JButton;
30 import javax.swing.JOptionPane;
31 import javax.swing.SwingUtilities;
32 import javax.swing.event.ChangeListener;
33 import org.openide.WizardDescriptor;
34 import org.openide.util.HelpCtx;
49 class AddImageWizardIngestConfigPanel
implements WizardDescriptor.Panel<WizardDescriptor> {
51 private final IngestJobSettingsPanel ingestJobSettingsPanel;
57 private Component component = null;
59 private final List<Content> newContents = Collections.synchronizedList(
new ArrayList<Content>());
60 private boolean ingested =
false;
61 private boolean readyToIngest =
false;
64 private AddImageAction.CleanupTask cleanupTask;
66 private final AddImageAction addImageAction;
68 private final AddImageWizardAddingProgressPanel progressPanel;
69 private final AddImageWizardChooseDataSourcePanel dataSourcePanel;
71 private DataSourceProcessor dsProcessor;
72 private boolean cancelled;
74 AddImageWizardIngestConfigPanel(AddImageWizardChooseDataSourcePanel dsPanel, AddImageAction action, AddImageWizardAddingProgressPanel proPanel) {
75 this.addImageAction = action;
76 this.progressPanel = proPanel;
77 this.dataSourcePanel = dsPanel;
79 IngestJobSettings ingestJobSettings =
new IngestJobSettings(AddImageWizardIngestConfigPanel.class.getCanonicalName());
80 showWarnings(ingestJobSettings);
81 this.ingestJobSettingsPanel =
new IngestJobSettingsPanel(ingestJobSettings);
93 public Component getComponent() {
94 if (component == null) {
95 component =
new AddImageWizardIngestConfigVisual(this.ingestJobSettingsPanel);
107 public HelpCtx getHelp() {
109 return HelpCtx.DEFAULT_HELP;
121 public boolean isValid() {
137 public final void addChangeListener(ChangeListener l) {
146 public final void removeChangeListener(ChangeListener l) {
162 public void readSettings(WizardDescriptor settings) {
163 JButton cancel =
new JButton(
164 NbBundle.getMessage(
this.getClass(),
"AddImageWizardIngestConfigPanel.CANCEL_BUTTON.text"));
165 cancel.setEnabled(
false);
166 settings.setOptions(
new Object[]{WizardDescriptor.PREVIOUS_OPTION, WizardDescriptor.NEXT_OPTION, WizardDescriptor.FINISH_OPTION, cancel});
168 readyToIngest =
false;
174 startDataSourceProcessing(settings);
187 public void storeSettings(WizardDescriptor settings) {
188 IngestJobSettings ingestJobSettings = this.ingestJobSettingsPanel.getSettings();
189 ingestJobSettings.save();
190 showWarnings(ingestJobSettings);
193 readyToIngest =
true;
197 private static void showWarnings(IngestJobSettings ingestJobSettings) {
198 List<String> warnings = ingestJobSettings.getWarnings();
199 if (warnings.isEmpty() ==
false) {
200 StringBuilder warningMessage =
new StringBuilder();
201 for (String warning : warnings) {
202 warningMessage.append(warning).append(
"\n");
204 JOptionPane.showMessageDialog(null, warningMessage.toString());
212 private void startIngest() {
213 if (!newContents.isEmpty() && readyToIngest && !ingested) {
215 IngestManager.getInstance().queueIngestJob(newContents, ingestJobSettingsPanel.getSettings());
216 progressPanel.setStateFinished();
224 private void startDataSourceProcessing(WizardDescriptor settings) {
225 final UUID dataSourceId = UUID.randomUUID();
229 cleanupTask = addImageAction.new CleanupTask() {
231 void cleanup() throws Exception {
232 cancelDataSourceProcessing(dataSourceId);
237 cleanupTask.enable();
240 dsProcessor = dataSourcePanel.getComponent().getCurrentDSProcessor();
243 Case.getCurrentCase().notifyAddingDataSource(dataSourceId);
245 DataSourceProcessorCallback cbObj =
new DataSourceProcessorCallback() {
247 public void doneEDT(DataSourceProcessorCallback.DataSourceProcessorResult result, List<String> errList, List<Content> contents) {
248 dataSourceProcessorDone(dataSourceId, result, errList, contents);
252 progressPanel.setStateStarted();
255 dsProcessor.run(progressPanel.getDSPProgressMonitorImpl(), cbObj);
262 private void cancelDataSourceProcessing(UUID dataSourceId) {
263 dsProcessor.cancel();
270 private void dataSourceProcessorDone(UUID dataSourceId, DataSourceProcessorCallback.DataSourceProcessorResult result, List<String> errList, List<Content> contents) {
272 cleanupTask.disable();
276 if (PlatformUtil.isWindowsOS() ==
true) {
277 java.awt.Toolkit.getDefaultToolkit().beep();
279 AddImageWizardAddingProgressVisual panel = progressPanel.getComponent();
281 Window w = SwingUtilities.getWindowAncestor(panel);
287 progressPanel.setStateFinished();
290 if (result == DataSourceProcessorCallback.DataSourceProcessorResult.NO_ERRORS) {
291 progressPanel.getComponent().setProgressBarTextAndColor(
292 NbBundle.getMessage(
this.getClass(),
"AddImageWizardIngestConfigPanel.dsProcDone.noErrs.text"), 100, Color.black);
294 progressPanel.getComponent().setProgressBarTextAndColor(
295 NbBundle.getMessage(
this.getClass(),
"AddImageWizardIngestConfigPanel.dsProcDone.errs.text"), 100, Color.red);
299 boolean critErr =
false;
300 if (result == DataSourceProcessorCallback.DataSourceProcessorResult.CRITICAL_ERRORS) {
303 for (String err : errList) {
305 progressPanel.addErrors(err, critErr);
310 if (!contents.isEmpty()) {
311 Case.getCurrentCase().notifyDataSourceAdded(contents.get(0), dataSourceId);
313 Case.getCurrentCase().notifyFailedAddingDataSource(dataSourceId);
319 newContents.addAll(contents);
320 progressPanel.setStateStarted();