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);
75 dialog.setAlwaysOnTop(
true);
76 dialog.setVisible(
true);
78 if (wizardDescriptor.getValue() == WizardDescriptor.FINISH_OPTION) {
79 new SwingWorker<Void, Void>() {
81 protected Void doInBackground() throws Exception {
82 String caseNumber = (String) wizardDescriptor.getProperty(
"caseNumber");
83 String examinerName = (String) wizardDescriptor.getProperty(
"caseExaminerName");
84 String examinerPhone = (String) wizardDescriptor.getProperty(
"caseExaminerPhone");
85 String examinerEmail = (String) wizardDescriptor.getProperty(
"caseExaminerEmail");
86 String caseNotes = (String) wizardDescriptor.getProperty(
"caseNotes");
87 String organizationName = (String) wizardDescriptor.getProperty(
"caseOrganization");
88 final String caseName = (String) wizardDescriptor.getProperty(
"caseName");
89 String createdDirectory = (String) wizardDescriptor.getProperty(
"createdDirectory");
90 CaseType caseType = CaseType.values()[(int) wizardDescriptor.getProperty(
"caseType")];
91 Case.createAsCurrentCase(caseType, createdDirectory,
new CaseDetails(caseName, caseNumber, examinerName, examinerPhone, examinerEmail, caseNotes));
92 if (CentralRepository.isEnabled()) {
93 CentralRepository dbManager = CentralRepository.getInstance();
94 if (dbManager != null) {
95 CorrelationCase cRCase = dbManager.getCase(Case.getCurrentCaseThrows());
97 cRCase = dbManager.newCase(Case.getCurrentCaseThrows());
99 if (!organizationName.isEmpty()) {
100 for (CentralRepoOrganization
org : dbManager.getOrganizations()) {
101 if (
org.getName().equals(organizationName)) {
103 dbManager.updateCase(cRCase);
113 protected void done() {
120 AddImageAction addImageAction = SystemAction.get(AddImageAction.class);
121 addImageAction.actionPerformed(null);
122 }
catch (InterruptedException | ExecutionException ex) {
123 if (null != ex.getCause() && !(ex.getCause() instanceof CaseActionCancelledException)) {
124 logger.log(Level.SEVERE, String.format(
"Error creating case %s", wizardDescriptor.getProperty(
"caseName")), ex);
125 JOptionPane.showMessageDialog(
126 WindowManager.getDefault().getMainWindow(),
127 (ex instanceof ExecutionException ? ex.getCause().getMessage() : ex.getMessage()),
128 NbBundle.getMessage(
this.getClass(),
"CaseCreateAction.msgDlg.cantCreateCase.msg"),
129 JOptionPane.ERROR_MESSAGE);
131 doFailedCaseCleanup(wizardDescriptor);
132 StartupWindowProvider.getInstance().close();
133 StartupWindowProvider.getInstance().open();
135 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
140 WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
142 doFailedCaseCleanup(wizardDescriptor);
147 private void doFailedCaseCleanup(WizardDescriptor wizardDescriptor) {
148 String createdDirectory = (String) wizardDescriptor.getProperty(
"createdDirectory");
149 if (createdDirectory != null) {
150 FileUtil.deleteDir(
new File(createdDirectory));
157 @SuppressWarnings({
"unchecked",
"rawtypes"})
158 private WizardDescriptor.Panel<WizardDescriptor>[] getNewCaseWizardPanels() {
159 if (panels == null) {
160 panels =
new WizardDescriptor.Panel[]{
161 new NewCaseWizardPanel1(),
162 new NewCaseWizardPanel2()
164 String[] steps =
new String[panels.length];
165 for (
int i = 0; i < panels.length; i++) {
166 Component c = panels[i].getComponent();
170 steps[i] = c.getName();
171 if (c instanceof JComponent) {
172 JComponent jc = (JComponent) c;
174 jc.putClientProperty(
"WizardPanel_contentSelectedIndex", i);
176 jc.putClientProperty(
"WizardPanel_contentData", steps);
178 jc.putClientProperty(
"WizardPanel_autoWizardStyle", Boolean.TRUE);
180 jc.putClientProperty(
"WizardPanel_contentDisplayed", Boolean.TRUE);
182 jc.putClientProperty(
"WizardPanel_contentNumbered", Boolean.TRUE);
193 public String getName() {
194 return NbBundle.getMessage(this.getClass(),
"NewCaseWizardAction.getName.text");
201 public String iconResource() {
209 public HelpCtx getHelpCtx() {
210 return HelpCtx.DEFAULT_HELP;
217 protected boolean asynchronous() {