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