19 package org.sleuthkit.autopsy.casemodule;
21 import java.awt.Component;
22 import java.awt.Cursor;
23 import java.awt.Dialog;
25 import java.text.MessageFormat;
26 import java.util.concurrent.ExecutionException;
27 import java.util.logging.Level;
28 import javax.swing.JComponent;
29 import javax.swing.JOptionPane;
30 import javax.swing.SwingWorker;
31 import org.openide.DialogDisplayer;
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;
37 import org.openide.windows.WindowManager;
50 final class NewCaseWizardAction
extends CallableSystemAction {
52 private static final long serialVersionUID = 1L;
53 private static final Logger logger = Logger.
getLogger(NewCaseWizardAction.class.getName());
54 private WizardDescriptor.Panel<WizardDescriptor>[] panels;
57 public void performAction() {
58 String optionsDlgTitle = NbBundle.getMessage(Case.class,
"CloseCaseWhileIngesting.Warning.title");
59 String optionsDlgMessage = NbBundle.getMessage(Case.class,
"CloseCaseWhileIngesting.Warning");
60 if (IngestRunningCheck.checkAndConfirmProceed(optionsDlgTitle, optionsDlgMessage)) {
65 private void runNewCaseWizard() {
66 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
67 final WizardDescriptor wizardDescriptor =
new WizardDescriptor(getNewCaseWizardPanels());
68 wizardDescriptor.setTitleFormat(
new MessageFormat(
"{0}"));
69 wizardDescriptor.setTitle(NbBundle.getMessage(
this.getClass(),
"NewCaseWizardAction.newCase.windowTitle.text"));
70 Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
71 dialog.setVisible(
true);
73 if (wizardDescriptor.getValue() == WizardDescriptor.FINISH_OPTION) {
74 new SwingWorker<Void, Void>() {
76 protected Void doInBackground() throws Exception {
77 String caseNumber = (String) wizardDescriptor.getProperty(
"caseNumber");
78 String examiner = (String) wizardDescriptor.getProperty(
"caseExaminer");
79 final String caseName = (String) wizardDescriptor.getProperty(
"caseName");
80 String createdDirectory = (String) wizardDescriptor.getProperty(
"createdDirectory");
81 CaseType caseType = CaseType.values()[(int) wizardDescriptor.getProperty(
"caseType")];
82 Case.createAsCurrentCase(createdDirectory, caseName, caseNumber, examiner, caseType);
87 protected void done() {
94 AddImageAction addImageAction = SystemAction.get(AddImageAction.class);
95 addImageAction.actionPerformed(null);
96 }
catch (InterruptedException | ExecutionException ex) {
97 if (null != ex.getCause() && !(ex.getCause() instanceof CaseActionCancelledException)) {
98 logger.log(Level.SEVERE, String.format(
"Error creating case %s", wizardDescriptor.getProperty(
"caseName")), ex);
99 JOptionPane.showMessageDialog(
100 WindowManager.getDefault().getMainWindow(),
101 (ex instanceof ExecutionException ? ex.getCause().getMessage() : ex.getMessage()),
102 NbBundle.getMessage(
this.getClass(),
"CaseCreateAction.msgDlg.cantCreateCase.msg"),
103 JOptionPane.ERROR_MESSAGE);
105 doFailedCaseCleanup(wizardDescriptor);
106 StartupWindowProvider.getInstance().close();
107 StartupWindowProvider.getInstance().open();
109 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
114 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
116 doFailedCaseCleanup(wizardDescriptor);
121 private void doFailedCaseCleanup(WizardDescriptor wizardDescriptor) {
122 String createdDirectory = (String) wizardDescriptor.getProperty(
"createdDirectory");
123 if (createdDirectory != null) {
124 FileUtil.deleteDir(
new File(createdDirectory));
131 @SuppressWarnings({
"unchecked",
"rawtypes"})
132 private WizardDescriptor.Panel<WizardDescriptor>[] getNewCaseWizardPanels() {
133 if (panels == null) {
134 panels =
new WizardDescriptor.Panel[]{
135 new NewCaseWizardPanel1(),
136 new NewCaseWizardPanel2()
138 String[] steps =
new String[panels.length];
139 for (
int i = 0; i < panels.length; i++) {
140 Component c = panels[i].getComponent();
144 steps[i] = c.getName();
145 if (c instanceof JComponent) {
146 JComponent jc = (JComponent) c;
148 jc.putClientProperty(
"WizardPanel_contentSelectedIndex", i);
150 jc.putClientProperty(
"WizardPanel_contentData", steps);
152 jc.putClientProperty(
"WizardPanel_autoWizardStyle", Boolean.TRUE);
154 jc.putClientProperty(
"WizardPanel_contentDisplayed", Boolean.TRUE);
156 jc.putClientProperty(
"WizardPanel_contentNumbered", Boolean.TRUE);
167 public String getName() {
168 return NbBundle.getMessage(this.getClass(),
"NewCaseWizardAction.getName.text");
175 public String iconResource() {
183 public HelpCtx getHelpCtx() {
184 return HelpCtx.DEFAULT_HELP;
191 protected boolean asynchronous() {
synchronized static Logger getLogger(String name)