Autopsy  4.1
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 caseFolder = new File(currentCase.getCaseDirectory());
85  String caseName = currentCase.getName();
86  if (!caseFolder.exists()) {
87  // throw an error
88 
89  logger.log(Level.WARNING, "Couldn't delete case.", new Exception("The case directory doesn't exist.")); //NON-NLS
90  } else {
91  // show the confirmation first to close the current case and open the "New Case" wizard panel
92  String closeCurrentCase = NbBundle.getMessage(this.getClass(), "CaseDeleteAction.closeConfMsg.text", caseName, caseFolder.getPath());
93  NotifyDescriptor d = new NotifyDescriptor.Confirmation(closeCurrentCase,
94  NbBundle.getMessage(this.getClass(),
95  "CaseDeleteAction.closeConfMsg.title"),
96  NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
97  d.setValue(NotifyDescriptor.NO_OPTION);
98 
99  Object res = DialogDisplayer.getDefault().notify(d);
100  if (res != null && res == DialogDescriptor.YES_OPTION) {
101  boolean success = false;
102 
103  try {
104  Case.getCurrentCase().deleteCase(caseFolder); // delete the current case
105  success = true;
106  } catch (CaseActionException ex) {
107  logger.log(Level.WARNING, "Could not delete the case folder: " + caseFolder); //NON-NLS
108  }
109 
110  // show notification whether the case has been deleted or it failed to delete...
111  if (!success) {
112  JOptionPane.showMessageDialog(caller,
113  NbBundle.getMessage(this.getClass(),
114  "CaseDeleteAction.msgDlg.fileInUse.msg"),
115  NbBundle.getMessage(this.getClass(),
116  "CaseDeleteAction.msgDlg.fileInUse.title"),
117  JOptionPane.ERROR_MESSAGE); // throw an error
118  } else {
119  CasePropertiesAction.closeCasePropertiesWindow(); // because the "Delete Case" button is in the "CaseProperties" window, we have to close that window when we delete the case.
120  JOptionPane.showMessageDialog(caller, NbBundle.getMessage(this.getClass(),
121  "CaseDeleteAction.msgDlg.caseDelete.msg",
122  caseName));
123  }
124  }
125  }
126  }
127 
132  @Override
133  public void performAction() {
134  // Note: I use the actionPerformed above instead of this method
135  }
136 
142  @Override
143  public String getName() {
144  return NbBundle.getMessage(CaseDeleteAction.class, "CTL_CaseDeleteAction");
145  }
146 
152  @Override
153  public HelpCtx getHelpCtx() {
154  return HelpCtx.DEFAULT_HELP;
155  }
156 }

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