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                         logger.log(Level.SEVERE, String.format(
"Error creating case %s", wizardDescriptor.getProperty(
"caseName")), ex); 
 
   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"), 
 
  102                                 JOptionPane.ERROR_MESSAGE);
 
  103                         StartupWindowProvider.getInstance().close();
 
  104                         StartupWindowProvider.getInstance().open();
 
  105                         doFailedCaseCleanup(wizardDescriptor);
 
  107                         WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
 
  112             WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
 
  114                 doFailedCaseCleanup(wizardDescriptor);
 
  119     private void doFailedCaseCleanup(WizardDescriptor wizardDescriptor) {
 
  120         String createdDirectory = (String) wizardDescriptor.getProperty(
"createdDirectory"); 
 
  121         if (createdDirectory != null) {
 
  122             FileUtil.deleteDir(
new File(createdDirectory));
 
  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()
 
  136             String[] steps = 
new String[panels.length];
 
  137             for (
int i = 0; i < panels.length; i++) {
 
  138                 Component c = panels[i].getComponent();
 
  142                 steps[i] = c.getName();
 
  143                 if (c instanceof JComponent) { 
 
  144                     JComponent jc = (JComponent) c;
 
  146                     jc.putClientProperty(
"WizardPanel_contentSelectedIndex", i);
 
  148                     jc.putClientProperty(
"WizardPanel_contentData", steps);
 
  150                     jc.putClientProperty(
"WizardPanel_autoWizardStyle", Boolean.TRUE);
 
  152                     jc.putClientProperty(
"WizardPanel_contentDisplayed", Boolean.TRUE);
 
  154                     jc.putClientProperty(
"WizardPanel_contentNumbered", Boolean.TRUE);
 
  165     public String getName() {
 
  166         return NbBundle.getMessage(this.getClass(), 
"NewCaseWizardAction.getName.text");
 
  173     public String iconResource() {
 
  181     public HelpCtx getHelpCtx() {
 
  182         return HelpCtx.DEFAULT_HELP;
 
  189     protected boolean asynchronous() {
 
synchronized static Logger getLogger(String name)