Autopsy  3.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-2014 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 
20 package org.sleuthkit.autopsy.casemodule;
21 
22 import java.awt.Component;
23 import java.awt.Dialog;
24 import java.io.File;
25 import java.text.MessageFormat;
26 import java.util.logging.Level;
27 import javax.swing.JComponent;
28 import org.openide.DialogDescriptor;
29 import org.openide.DialogDisplayer;
30 import org.openide.NotifyDescriptor;
31 import org.openide.WizardDescriptor;
32 import org.openide.util.HelpCtx;
33 import org.openide.util.NbBundle;
34 import org.openide.util.actions.CallableSystemAction;
35 import org.openide.util.actions.SystemAction;
37 
41  final class NewCaseWizardAction extends CallableSystemAction {
42 
43  private WizardDescriptor.Panel<WizardDescriptor>[] panels;
44 
45  private static final Logger logger = Logger.getLogger(NewCaseWizardAction.class.getName());
46 
47  @Override
48  public void performAction() {
49  // there's a case open
50  if (Case.existsCurrentCase()) {
51  // show the confirmation first to close the current case and open the "New Case" wizard panel
52  String closeCurrentCase = NbBundle
53  .getMessage(this.getClass(), "NewCaseWizardAction.closeCurCase.confMsg.msg");
54  NotifyDescriptor d = new NotifyDescriptor.Confirmation(closeCurrentCase,
55  NbBundle.getMessage(this.getClass(),
56  "NewCaseWizardAction.closeCurCase.confMsg.title"),
57  NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
58  d.setValue(NotifyDescriptor.NO_OPTION);
59 
60  Object res = DialogDisplayer.getDefault().notify(d);
61  if (res != null && res == DialogDescriptor.YES_OPTION) {
62  try {
63  Case.getCurrentCase().closeCase(); // close the current case
64  newCaseAction(); // start the new case creation process
65  } catch (Exception ex) {
66  Logger.getLogger(NewCaseWizardAction.class.getName()).log(Level.WARNING, "Error closing case.", ex); //NON-NLS
67  }
68  }
69  } else {
70  newCaseAction();
71  }
72  }
73 
77  private void newCaseAction() {
78  WizardDescriptor wizardDescriptor = new WizardDescriptor(getPanels());
79  // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
80  wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
81  wizardDescriptor.setTitle(NbBundle.getMessage(this.getClass(), "NewCaseWizardAction.newCase.windowTitle.text"));
82  Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
83  dialog.setVisible(true);
84  dialog.toFront();
85 
86 
87  boolean finished = wizardDescriptor.getValue() == WizardDescriptor.FINISH_OPTION; // check if it finishes (it's not cancelled)
88  boolean isCancelled = wizardDescriptor.getValue() == WizardDescriptor.CANCEL_OPTION; // check if the "Cancel" button is pressed
89 
90  // if the finish button is pressed (not cancelled)
91  if (finished) {
92  // now start the 'Add Image' wizard
93  //TODO fix for local
94  AddImageAction addImageAction = SystemAction.get(AddImageAction.class);
95  addImageAction.actionPerformed(null);
96  }
97 
98  // if Cancel button is pressed
99  if (isCancelled) {
100  String createdDirectory = (String) wizardDescriptor.getProperty("createdDirectory"); //NON-NLS
101  if(createdDirectory != null) {
102  logger.log(Level.INFO, "Deleting a created case directory due to isCancelled set, dir: " + createdDirectory); //NON-NLS
103  Case.deleteCaseDirectory(new File(createdDirectory));
104  }
105  // if there's case opened, close the case
106  if (Case.existsCurrentCase()) {
107  // close the previous case if there's any
108  CaseCloseAction closeCase = SystemAction.get(CaseCloseAction.class);
109  closeCase.actionPerformed(null);
110  }
111  }
112  panels = null; // reset the panel
113  }
114 
119  @SuppressWarnings({"unchecked", "rawtypes"})
120  private WizardDescriptor.Panel<WizardDescriptor>[] getPanels() {
121  if (panels == null) {
122  panels = new WizardDescriptor.Panel[]{
123  new NewCaseWizardPanel1(),
124  new NewCaseWizardPanel2()
125  };
126  String[] steps = new String[panels.length];
127  for (int i = 0; i < panels.length; i++) {
128  Component c = panels[i].getComponent();
129  // Default step name to component name of panel. Mainly useful
130  // for getting the name of the target chooser to appear in the
131  // list of steps.
132  steps[i] = c.getName();
133  if (c instanceof JComponent) { // assume Swing components
134  JComponent jc = (JComponent) c;
135  // Sets step number of a component
136  jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i));
137  // Sets steps names for a panel
138  jc.putClientProperty("WizardPanel_contentData", steps);
139  // Turn on subtitle creation on each step
140  jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
141  // Show steps on the left side with the image on the background
142  jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
143  // Turn on numbering of all steps
144  jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE);
145  }
146  }
147  }
148  return panels;
149  }
150 
151  @Override
152  public String getName() {
153  return NbBundle.getMessage(this.getClass(), "NewCaseWizardAction.getName.text");
154  }
155 
156  @Override
157  public String iconResource() {
158  return null;
159  }
160 
161  @Override
162  public HelpCtx getHelpCtx() {
163  return HelpCtx.DEFAULT_HELP;
164  }
165 
166  @Override
167  protected boolean asynchronous() {
168  return false;
169  }
170 }
static Logger getLogger(String name)
Definition: Logger.java:131

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.