Autopsy  3.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 
20 package org.sleuthkit.autopsy.casemodule;
21 
22 import java.awt.event.ActionEvent;
23 import java.io.File;
24 import java.util.logging.Level;import org.sleuthkit.autopsy.coreutils.Logger;
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 
60  final class CaseDeleteAction extends CallableSystemAction {
61 
62  private JPanel caller; // for error handling
63 
64  private static final Logger logger = Logger.getLogger(CaseDeleteAction.class.getName());
65 
69  public CaseDeleteAction() {
70  putValue(Action.NAME, NbBundle.getMessage(CaseDeleteAction.class, "CTL_CaseDeleteAction")); // put the action Name
71  this.setEnabled(false);
72  }
73 
78  @Override
79  public void actionPerformed(ActionEvent e) {
80  Case currentCase = Case.getCurrentCase();
81  File configFile = new File(currentCase.getConfigFilePath());
82  File caseFolder = new File(configFile.getParent());
83  String caseName = currentCase.getName();
84  if(!caseFolder.exists()){
85  // throw an error
86 
87  logger.log(Level.WARNING, "Couldn't delete case.", new Exception("The case directory doesn't exist.")); //NON-NLS
88  }
89  else{
90  // show the confirmation first to close the current case and open the "New Case" wizard panel
91  String closeCurrentCase = NbBundle.getMessage(this.getClass(), "CaseDeleteAction.closeConfMsg.text", caseName, caseFolder.getPath());
92  NotifyDescriptor d = new NotifyDescriptor.Confirmation(closeCurrentCase,
93  NbBundle.getMessage(this.getClass(),
94  "CaseDeleteAction.closeConfMsg.title"),
95  NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
96  d.setValue(NotifyDescriptor.NO_OPTION);
97 
98  Object res = DialogDisplayer.getDefault().notify(d);
99  if(res != null && res == DialogDescriptor.YES_OPTION){
100  boolean success = false;
101 
102  try {
103  Case.getCurrentCase().deleteCase(caseFolder); // delete the current case
104  success = true;
105  } catch (CaseActionException ex) {
106  logger.log(Level.WARNING, "Could not delete the case folder: " + caseFolder); //NON-NLS
107  }
108 
109  // show notification whether the case has been deleted or it failed to delete...
110  if(!success){
111  JOptionPane.showMessageDialog(caller,
112  NbBundle.getMessage(this.getClass(),
113  "CaseDeleteAction.msgDlg.fileInUse.msg"),
114  NbBundle.getMessage(this.getClass(),
115  "CaseDeleteAction.msgDlg.fileInUse.title"),
116  JOptionPane.ERROR_MESSAGE); // throw an error
117  }
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 
131  @Override
132  public void performAction() {
133  // Note: I use the actionPerformed above instead of this method
134  }
135 
140  @Override
141  public String getName() {
142  return NbBundle.getMessage(CaseDeleteAction.class, "CTL_CaseDeleteAction");
143  }
144 
149  @Override
150  public HelpCtx getHelpCtx() {
151  return HelpCtx.DEFAULT_HELP;
152  }
153 }

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.