19 package org.sleuthkit.autopsy.casemodule;
21 import java.awt.Component;
22 import java.awt.Dialog;
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;
48 final class NewCaseWizardAction
extends CallableSystemAction {
50 private static final long serialVersionUID = 1L;
51 private static final Logger logger = Logger.getLogger(NewCaseWizardAction.class.getName());
52 private WizardDescriptor.Panel<WizardDescriptor>[] panels;
55 public void performAction() {
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;
71 currentCase = Case.getCurrentCase();
72 currentCase.closeCase();
73 }
catch (IllegalStateException ignored) {
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);
84 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
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);
95 if (wizardDescriptor.getValue() == WizardDescriptor.FINISH_OPTION) {
96 new SwingWorker<Void, Void>() {
98 protected Void doInBackground() throws Exception {
99 String caseNumber = (String) wizardDescriptor.getProperty(
"caseNumber");
100 String examiner = (String) wizardDescriptor.getProperty(
"caseExaminer");
101 final String caseName = (String) wizardDescriptor.getProperty(
"caseName");
102 String createdDirectory = (String) wizardDescriptor.getProperty(
"createdDirectory");
103 CaseType caseType = CaseType.values()[(int) wizardDescriptor.getProperty(
"caseType")];
104 Case.create(createdDirectory, caseName, caseNumber, examiner, caseType);
109 protected void done() {
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);
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"),
121 JOptionPane.ERROR_MESSAGE);
122 StartupWindowProvider.getInstance().close();
123 if (!Case.isCaseOpen()) {
124 StartupWindowProvider.getInstance().open();
127 doFailedCaseCleanup(wizardDescriptor);
133 doFailedCaseCleanup(wizardDescriptor);
138 private void doFailedCaseCleanup(WizardDescriptor wizardDescriptor) {
139 String createdDirectory = (String) wizardDescriptor.getProperty(
"createdDirectory");
140 if (createdDirectory != null) {
141 Case.deleteCaseDirectory(
new File(createdDirectory));
143 SwingUtilities.invokeLater(() -> {
144 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
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()
158 String[] steps =
new String[panels.length];
159 for (
int i = 0; i < panels.length; i++) {
160 Component c = panels[i].getComponent();
164 steps[i] = c.getName();
165 if (c instanceof JComponent) {
166 JComponent jc = (JComponent) c;
168 jc.putClientProperty(
"WizardPanel_contentSelectedIndex", i);
170 jc.putClientProperty(
"WizardPanel_contentData", steps);
172 jc.putClientProperty(
"WizardPanel_autoWizardStyle", Boolean.TRUE);
174 jc.putClientProperty(
"WizardPanel_contentDisplayed", Boolean.TRUE);
176 jc.putClientProperty(
"WizardPanel_contentNumbered", Boolean.TRUE);
187 public String getName() {
188 return NbBundle.getMessage(this.getClass(),
"NewCaseWizardAction.getName.text");
195 public String iconResource() {
203 public HelpCtx getHelpCtx() {
204 return HelpCtx.DEFAULT_HELP;
211 protected boolean asynchronous() {