Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
NewCaseWizardAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.casemodule;
20 
21 import java.awt.Component;
22 import java.awt.Cursor;
23 import java.awt.Dialog;
24 import java.io.File;
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;
42 
50 final class NewCaseWizardAction extends CallableSystemAction {
51 
52  private static final long serialVersionUID = 1L;
53  private static final Logger logger = Logger.getLogger(NewCaseWizardAction.class.getName());
54  private WizardDescriptor.Panel<WizardDescriptor>[] panels;
55 
56  @Override
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)) {
61  runNewCaseWizard();
62  }
63  }
64 
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);
72  dialog.toFront();
73  if (wizardDescriptor.getValue() == WizardDescriptor.FINISH_OPTION) {
74  new SwingWorker<Void, Void>() {
75  @Override
76  protected Void doInBackground() throws Exception {
77  String caseNumber = (String) wizardDescriptor.getProperty("caseNumber"); //NON-NLS
78  String examiner = (String) wizardDescriptor.getProperty("caseExaminer"); //NON-NLS
79  final String caseName = (String) wizardDescriptor.getProperty("caseName"); //NON-NLS
80  String createdDirectory = (String) wizardDescriptor.getProperty("createdDirectory"); //NON-NLS
81  CaseType caseType = CaseType.values()[(int) wizardDescriptor.getProperty("caseType")]; //NON-NLS
82  Case.createAsCurrentCase(createdDirectory, caseName, caseNumber, examiner, caseType);
83  return null;
84  }
85 
86  @Override
87  protected void done() {
88  try {
89  get();
90  /*
91  * Run the Add Data Source wizard by invoking the Add
92  * Data Source wizard.
93  */
94  AddImageAction addImageAction = SystemAction.get(AddImageAction.class);
95  addImageAction.actionPerformed(null);
96  } catch (InterruptedException | ExecutionException ex) {
97  logger.log(Level.SEVERE, String.format("Error creating case %s", wizardDescriptor.getProperty("caseName")), ex); //NON-NLS
98  JOptionPane.showMessageDialog(
99  WindowManager.getDefault().getMainWindow(),
100  (ex instanceof ExecutionException ? ex.getCause().getMessage() : ex.getMessage()),
101  NbBundle.getMessage(this.getClass(), "CaseCreateAction.msgDlg.cantCreateCase.msg"), //NON-NLS
102  JOptionPane.ERROR_MESSAGE);
103  StartupWindowProvider.getInstance().close();
104  StartupWindowProvider.getInstance().open();
105  doFailedCaseCleanup(wizardDescriptor);
106  } finally {
107  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
108  }
109  }
110  }.execute();
111  } else {
112  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
113  new Thread(() -> {
114  doFailedCaseCleanup(wizardDescriptor);
115  }).start();
116  }
117  }
118 
119  private void doFailedCaseCleanup(WizardDescriptor wizardDescriptor) {
120  String createdDirectory = (String) wizardDescriptor.getProperty("createdDirectory"); //NON-NLS
121  if (createdDirectory != null) {
122  FileUtil.deleteDir(new File(createdDirectory));
123  }
124  }
125 
129  @SuppressWarnings({"unchecked", "rawtypes"})
130  private WizardDescriptor.Panel<WizardDescriptor>[] getNewCaseWizardPanels() {
131  if (panels == null) {
132  panels = new WizardDescriptor.Panel[]{
133  new NewCaseWizardPanel1(),
134  new NewCaseWizardPanel2()
135  };
136  String[] steps = new String[panels.length];
137  for (int i = 0; i < panels.length; i++) {
138  Component c = panels[i].getComponent();
139  // Default step name to component name of panel. Mainly useful
140  // for getting the name of the target chooser to appear in the
141  // list of steps.
142  steps[i] = c.getName();
143  if (c instanceof JComponent) { // assume Swing components
144  JComponent jc = (JComponent) c;
145  // Sets step number of a component
146  jc.putClientProperty("WizardPanel_contentSelectedIndex", i);
147  // Sets steps names for a panel
148  jc.putClientProperty("WizardPanel_contentData", steps);
149  // Turn on subtitle creation on each step
150  jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
151  // Show steps on the left side with the image on the background
152  jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
153  // Turn on numbering of all steps
154  jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE);
155  }
156  }
157  }
158  return panels;
159  }
160 
164  @Override
165  public String getName() {
166  return NbBundle.getMessage(this.getClass(), "NewCaseWizardAction.getName.text");
167  }
168 
172  @Override
173  public String iconResource() {
174  return null;
175  }
176 
180  @Override
181  public HelpCtx getHelpCtx() {
182  return HelpCtx.DEFAULT_HELP;
183  }
184 
188  @Override
189  protected boolean asynchronous() {
190  return false;
191  }
192 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.