Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
NewCaseWizardAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2016 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.awt.Dialog;
23 import java.io.File;
24 import java.text.MessageFormat;
25 import java.util.logging.Level;
26 import javax.swing.JComponent;
27 import javax.swing.SwingWorker;
28 import javax.swing.SwingUtilities;
29 import org.openide.DialogDescriptor;
30 import org.openide.DialogDisplayer;
31 import org.openide.NotifyDescriptor;
32 import org.openide.WizardDescriptor;
33 import org.openide.util.HelpCtx;
34 import org.openide.util.NbBundle;
35 import org.openide.util.actions.CallableSystemAction;
36 import org.openide.util.actions.SystemAction;
38 import javax.swing.JOptionPane;
40 import org.openide.windows.WindowManager;
41 import java.awt.Cursor;
42 import java.util.concurrent.ExecutionException;
44 
48 final class NewCaseWizardAction extends CallableSystemAction {
49 
50  private static final long serialVersionUID = 1L;
51  private static final Logger logger = Logger.getLogger(NewCaseWizardAction.class.getName());
52  private WizardDescriptor.Panel<WizardDescriptor>[] panels;
53 
54  @Override
55  public void performAction() {
56  /*
57  * If ingest is running, do a dialog to warn the user and confirm the
58  * intent to close the current case and leave the ingest process
59  * incomplete.
60  */
61  if (IngestManager.getInstance().isIngestRunning()) {
62  NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(
63  NbBundle.getMessage(this.getClass(), "CloseCaseWhileIngesting.Warning"),
64  NbBundle.getMessage(this.getClass(), "CloseCaseWhileIngesting.Warning.title"),
65  NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
66  descriptor.setValue(NotifyDescriptor.NO_OPTION);
67  Object res = DialogDisplayer.getDefault().notify(descriptor);
68  if (res != null && res == DialogDescriptor.YES_OPTION) {
69  Case currentCase = null;
70  try {
71  currentCase = Case.getCurrentCase();
72  currentCase.closeCase();
73  } catch (IllegalStateException ignored) {
74  /*
75  * No current case.
76  */
77  } catch (CaseActionException ex) {
78  logger.log(Level.SEVERE, String.format("Error closing case at %s while ingest was running", (null != currentCase ? currentCase.getCaseDirectory() : "?")), ex); //NON-NLS
79  }
80  } else {
81  return;
82  }
83  }
84  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
85  runNewCaseWizard();
86  }
87 
88  private void runNewCaseWizard() {
89  final WizardDescriptor wizardDescriptor = new WizardDescriptor(getNewCaseWizardPanels());
90  wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
91  wizardDescriptor.setTitle(NbBundle.getMessage(this.getClass(), "NewCaseWizardAction.newCase.windowTitle.text"));
92  Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
93  dialog.setVisible(true);
94  dialog.toFront();
95  if (wizardDescriptor.getValue() == WizardDescriptor.FINISH_OPTION) {
96  new SwingWorker<Void, Void>() {
97  @Override
98  protected Void doInBackground() throws Exception {
99  String caseNumber = (String) wizardDescriptor.getProperty("caseNumber"); //NON-NLS
100  String examiner = (String) wizardDescriptor.getProperty("caseExaminer"); //NON-NLS
101  final String caseName = (String) wizardDescriptor.getProperty("caseName"); //NON-NLS
102  String createdDirectory = (String) wizardDescriptor.getProperty("createdDirectory"); //NON-NLS
103  CaseType caseType = CaseType.values()[(int) wizardDescriptor.getProperty("caseType")]; //NON-NLS
104  Case.create(createdDirectory, caseName, caseNumber, examiner, caseType);
105  return null;
106  }
107 
108  @Override
109  protected void done() {
110  try {
111  get();
112  AddImageAction addImageAction = SystemAction.get(AddImageAction.class);
113  addImageAction.actionPerformed(null);
114  } catch (Exception ex) {
115  logger.log(Level.SEVERE, String.format("Error creating case %s", wizardDescriptor.getProperty("caseName")), ex); //NON-NLS
116  SwingUtilities.invokeLater(() -> {
117  JOptionPane.showMessageDialog(
118  WindowManager.getDefault().getMainWindow(),
119  (ex instanceof ExecutionException ? ex.getCause().getMessage() : ex.getMessage()),
120  NbBundle.getMessage(this.getClass(), "CaseCreateAction.msgDlg.cantCreateCase.msg"), //NON-NLS
121  JOptionPane.ERROR_MESSAGE);
122  StartupWindowProvider.getInstance().close(); // RC: Why close and open?
123  if (!Case.isCaseOpen()) {
124  StartupWindowProvider.getInstance().open();
125  }
126  });
127  doFailedCaseCleanup(wizardDescriptor);
128  }
129  }
130  }.execute();
131  } else {
132  new Thread(() -> {
133  doFailedCaseCleanup(wizardDescriptor);
134  }).start();
135  }
136  }
137 
138  private void doFailedCaseCleanup(WizardDescriptor wizardDescriptor) {
139  String createdDirectory = (String) wizardDescriptor.getProperty("createdDirectory"); //NON-NLS
140  if (createdDirectory != null) {
141  Case.deleteCaseDirectory(new File(createdDirectory));
142  }
143  SwingUtilities.invokeLater(() -> {
144  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
145  });
146  }
147 
151  @SuppressWarnings({"unchecked", "rawtypes"})
152  private WizardDescriptor.Panel<WizardDescriptor>[] getNewCaseWizardPanels() {
153  if (panels == null) {
154  panels = new WizardDescriptor.Panel[]{
155  new NewCaseWizardPanel1(),
156  new NewCaseWizardPanel2()
157  };
158  String[] steps = new String[panels.length];
159  for (int i = 0; i < panels.length; i++) {
160  Component c = panels[i].getComponent();
161  // Default step name to component name of panel. Mainly useful
162  // for getting the name of the target chooser to appear in the
163  // list of steps.
164  steps[i] = c.getName();
165  if (c instanceof JComponent) { // assume Swing components
166  JComponent jc = (JComponent) c;
167  // Sets step number of a component
168  jc.putClientProperty("WizardPanel_contentSelectedIndex", i);
169  // Sets steps names for a panel
170  jc.putClientProperty("WizardPanel_contentData", steps);
171  // Turn on subtitle creation on each step
172  jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
173  // Show steps on the left side with the image on the background
174  jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
175  // Turn on numbering of all steps
176  jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE);
177  }
178  }
179  }
180  return panels;
181  }
182 
186  @Override
187  public String getName() {
188  return NbBundle.getMessage(this.getClass(), "NewCaseWizardAction.getName.text");
189  }
190 
194  @Override
195  public String iconResource() {
196  return null;
197  }
198 
202  @Override
203  public HelpCtx getHelpCtx() {
204  return HelpCtx.DEFAULT_HELP;
205  }
206 
210  @Override
211  protected boolean asynchronous() {
212  return false;
213  }
214 }

Copyright © 2012-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.