Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CaseDeleteAction.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 package org.sleuthkit.autopsy.casemodule;
20 
21 import java.awt.event.ActionEvent;
22 import java.io.File;
23 import java.util.logging.Level;
25 import javax.swing.Action;
26 import javax.swing.JOptionPane;
27 import javax.swing.JPanel;
28 import org.openide.DialogDescriptor;
29 import org.openide.DialogDisplayer;
30 import org.openide.NotifyDescriptor;
31 import org.openide.util.HelpCtx;
32 import org.openide.util.NbBundle;
33 import org.openide.util.actions.CallableSystemAction;
34 ;
36 import javax.swing.Action;
37 import javax.swing.JOptionPane;
38 import javax.swing.JPanel;
39 import org.openide.DialogDescriptor;
40 import org.openide.DialogDisplayer;
41 import org.openide.NotifyDescriptor;
42 import org.openide.util.HelpCtx;
43 import org.openide.util.NbBundle;
44 import org.openide.util.actions.CallableSystemAction;
46 import javax.swing.Action;
47 import javax.swing.JOptionPane;
48 import javax.swing.JPanel;
49 import org.openide.DialogDescriptor;
50 import org.openide.DialogDisplayer;
51 import org.openide.NotifyDescriptor;
52 import org.openide.util.HelpCtx;
53 import org.openide.util.NbBundle;
54 import org.openide.util.actions.CallableSystemAction;
55 
62 final class CaseDeleteAction extends CallableSystemAction {
63 
64  private JPanel caller; // for error handling
65 
66  private static final Logger logger = Logger.getLogger(CaseDeleteAction.class.getName());
67 
71  public CaseDeleteAction() {
72  putValue(Action.NAME, NbBundle.getMessage(CaseDeleteAction.class, "CTL_CaseDeleteAction")); // put the action Name
73  this.setEnabled(false);
74  }
75 
81  @Override
82  public void actionPerformed(ActionEvent e) {
83  Case currentCase = Case.getCurrentCase();
84  File configFile = new File(currentCase.getConfigFilePath());
85  File caseFolder = new File(configFile.getParent());
86  String caseName = currentCase.getName();
87  if (!caseFolder.exists()) {
88  // throw an error
89 
90  logger.log(Level.WARNING, "Couldn't delete case.", new Exception("The case directory doesn't exist.")); //NON-NLS
91  } else {
92  // show the confirmation first to close the current case and open the "New Case" wizard panel
93  String closeCurrentCase = NbBundle.getMessage(this.getClass(), "CaseDeleteAction.closeConfMsg.text", caseName, caseFolder.getPath());
94  NotifyDescriptor d = new NotifyDescriptor.Confirmation(closeCurrentCase,
95  NbBundle.getMessage(this.getClass(),
96  "CaseDeleteAction.closeConfMsg.title"),
97  NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
98  d.setValue(NotifyDescriptor.NO_OPTION);
99 
100  Object res = DialogDisplayer.getDefault().notify(d);
101  if (res != null && res == DialogDescriptor.YES_OPTION) {
102  boolean success = false;
103 
104  try {
105  Case.getCurrentCase().deleteCase(caseFolder); // delete the current case
106  success = true;
107  } catch (CaseActionException ex) {
108  logger.log(Level.WARNING, "Could not delete the case folder: " + caseFolder); //NON-NLS
109  }
110 
111  // show notification whether the case has been deleted or it failed to delete...
112  if (!success) {
113  JOptionPane.showMessageDialog(caller,
114  NbBundle.getMessage(this.getClass(),
115  "CaseDeleteAction.msgDlg.fileInUse.msg"),
116  NbBundle.getMessage(this.getClass(),
117  "CaseDeleteAction.msgDlg.fileInUse.title"),
118  JOptionPane.ERROR_MESSAGE); // throw an error
119  } else {
120  CasePropertiesAction.closeCasePropertiesWindow(); // because the "Delete Case" button is in the "CaseProperties" window, we have to close that window when we delete the case.
121  JOptionPane.showMessageDialog(caller, NbBundle.getMessage(this.getClass(),
122  "CaseDeleteAction.msgDlg.caseDelete.msg",
123  caseName));
124  }
125  }
126  }
127  }
128 
133  @Override
134  public void performAction() {
135  // Note: I use the actionPerformed above instead of this method
136  }
137 
143  @Override
144  public String getName() {
145  return NbBundle.getMessage(CaseDeleteAction.class, "CTL_CaseDeleteAction");
146  }
147 
153  @Override
154  public HelpCtx getHelpCtx() {
155  return HelpCtx.DEFAULT_HELP;
156  }
157 }

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