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;
53 final class NewCaseWizardAction
extends CallableSystemAction {
55 private static final long serialVersionUID = 1L;
56 private static final Logger logger = Logger.
getLogger(NewCaseWizardAction.class.getName());
57 private WizardDescriptor.Panel<WizardDescriptor>[] panels;
60 public void performAction() {
61 String optionsDlgTitle = NbBundle.getMessage(Case.class,
"CloseCaseWhileIngesting.Warning.title");
62 String optionsDlgMessage = NbBundle.getMessage(Case.class,
"CloseCaseWhileIngesting.Warning");
63 if (IngestRunningCheck.checkAndConfirmProceed(optionsDlgTitle, optionsDlgMessage)) {
68 private void runNewCaseWizard() {
69 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
70 final WizardDescriptor wizardDescriptor =
new WizardDescriptor(getNewCaseWizardPanels());
71 wizardDescriptor.setTitleFormat(
new MessageFormat(
"{0}"));
72 wizardDescriptor.setTitle(NbBundle.getMessage(
this.getClass(),
"NewCaseWizardAction.newCase.windowTitle.text"));
73 Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
74 dialog.setVisible(
true);
76 if (wizardDescriptor.getValue() == WizardDescriptor.FINISH_OPTION) {
77 new SwingWorker<Void, Void>() {
79 protected Void doInBackground() throws Exception {
80 String caseNumber = (String) wizardDescriptor.getProperty(
"caseNumber");
81 String examinerName = (String) wizardDescriptor.getProperty(
"caseExaminerName");
82 String examinerPhone = (String) wizardDescriptor.getProperty(
"caseExaminerPhone");
83 String examinerEmail = (String) wizardDescriptor.getProperty(
"caseExaminerEmail");
84 String caseNotes = (String) wizardDescriptor.getProperty(
"caseNotes");
85 String organizationName = (String) wizardDescriptor.getProperty(
"caseOrganization");
86 final String caseName = (String) wizardDescriptor.getProperty(
"caseName");
87 String createdDirectory = (String) wizardDescriptor.getProperty(
"createdDirectory");
88 CaseType caseType = CaseType.values()[(int) wizardDescriptor.getProperty(
"caseType")];
89 Case.createAsCurrentCase(caseType, createdDirectory,
new CaseDetails(caseName, caseNumber, examinerName, examinerPhone, examinerEmail, caseNotes));
90 if (EamDb.isEnabled()) {
91 EamDb dbManager = EamDb.getInstance();
92 if (dbManager != null) {
93 CorrelationCase cRCase = dbManager.getCase(Case.getCurrentCaseThrows());
95 cRCase = dbManager.newCase(Case.getCurrentCaseThrows());
97 if (!organizationName.isEmpty()) {
98 for (EamOrganization
org : dbManager.getOrganizations()) {
99 if (
org.getName().equals(organizationName)) {
101 dbManager.updateCase(cRCase);
111 protected void done() {
118 AddImageAction addImageAction = SystemAction.get(AddImageAction.class);
119 addImageAction.actionPerformed(null);
120 }
catch (InterruptedException | ExecutionException ex) {
121 if (null != ex.getCause() && !(ex.getCause() instanceof CaseActionCancelledException)) {
122 logger.log(Level.SEVERE, String.format(
"Error creating case %s", wizardDescriptor.getProperty(
"caseName")), ex);
123 JOptionPane.showMessageDialog(
124 WindowManager.getDefault().getMainWindow(),
125 (ex instanceof ExecutionException ? ex.getCause().getMessage() : ex.getMessage()),
126 NbBundle.getMessage(
this.getClass(),
"CaseCreateAction.msgDlg.cantCreateCase.msg"),
127 JOptionPane.ERROR_MESSAGE);
129 doFailedCaseCleanup(wizardDescriptor);
130 StartupWindowProvider.getInstance().close();
131 StartupWindowProvider.getInstance().open();
133 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
138 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
140 doFailedCaseCleanup(wizardDescriptor);
145 private void doFailedCaseCleanup(WizardDescriptor wizardDescriptor) {
146 String createdDirectory = (String) wizardDescriptor.getProperty(
"createdDirectory");
147 if (createdDirectory != null) {
148 FileUtil.deleteDir(
new File(createdDirectory));
155 @SuppressWarnings({
"unchecked",
"rawtypes"})
156 private WizardDescriptor.Panel<WizardDescriptor>[] getNewCaseWizardPanels() {
157 if (panels == null) {
158 panels =
new WizardDescriptor.Panel[]{
159 new NewCaseWizardPanel1(),
160 new NewCaseWizardPanel2()
162 String[] steps =
new String[panels.length];
163 for (
int i = 0; i < panels.length; i++) {
164 Component c = panels[i].getComponent();
168 steps[i] = c.getName();
169 if (c instanceof JComponent) {
170 JComponent jc = (JComponent) c;
172 jc.putClientProperty(
"WizardPanel_contentSelectedIndex", i);
174 jc.putClientProperty(
"WizardPanel_contentData", steps);
176 jc.putClientProperty(
"WizardPanel_autoWizardStyle", Boolean.TRUE);
178 jc.putClientProperty(
"WizardPanel_contentDisplayed", Boolean.TRUE);
180 jc.putClientProperty(
"WizardPanel_contentNumbered", Boolean.TRUE);
191 public String getName() {
192 return NbBundle.getMessage(this.getClass(),
"NewCaseWizardAction.getName.text");
199 public String iconResource() {
207 public HelpCtx getHelpCtx() {
208 return HelpCtx.DEFAULT_HELP;
215 protected boolean asynchronous() {
synchronized static Logger getLogger(String name)