Autopsy  4.5.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-2017 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.beans.PropertyChangeEvent;
23 import java.util.EnumSet;
24 import java.util.concurrent.ExecutionException;
25 import java.util.logging.Level;
26 import javax.swing.Action;
27 import javax.swing.JOptionPane;
28 import javax.swing.SwingWorker;
29 import org.openide.DialogDescriptor;
30 import org.openide.DialogDisplayer;
31 import org.openide.NotifyDescriptor;
32 import org.openide.util.HelpCtx;
33 import org.openide.util.NbBundle;
34 import org.openide.util.NbBundle.Messages;
35 import org.openide.util.actions.CallableSystemAction;
37 
44 final class CaseDeleteAction extends CallableSystemAction {
45 
46  private static final long serialVersionUID = 1L;
47  private static final Logger LOGGER = Logger.getLogger(CaseDeleteAction.class.getName());
48 
49  CaseDeleteAction() {
50  putValue(Action.NAME, NbBundle.getMessage(CaseDeleteAction.class, "CTL_CaseDeleteAction"));
51  this.setEnabled(false);
52  Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> {
53  /*
54  * A value of 'null' signifies that there is no case open.
55  */
56  setEnabled(null != evt.getNewValue());
57  });
58  }
59 
60  @Override
61  @Messages({
62  "Case.deleteCaseConfirmationDialog.title=Delete Current Case?",
63  "Case.deleteCaseConfirmationDialog.message=Are you sure you want to close and delete the current case?",
64  "Case.deleteCaseFailureMessageBox.title=Failed to Delete Case",
65  "# {0} - exception message", "Case.deleteCaseFailureMessageBox.message=Error deleting case: {0}",})
66  public void actionPerformed(ActionEvent e) {
67  try {
68  Case currentCase = Case.getCurrentCase();
69  String caseName = currentCase.getName();
70  String caseDirectory = currentCase.getCaseDirectory();
71 
72  /*
73  * Do a confirmation dialog and close the current case if the user
74  * confirms he/she wants to proceed.
75  */
76  Object response = DialogDisplayer.getDefault().notify(new NotifyDescriptor(
77  Bundle.Case_deleteCaseConfirmationDialog_message(),
78  Bundle.Case_deleteCaseConfirmationDialog_title(),
79  NotifyDescriptor.YES_NO_OPTION,
80  NotifyDescriptor.WARNING_MESSAGE,
81  null,
82  NotifyDescriptor.NO_OPTION));
83  if (null != response && DialogDescriptor.YES_OPTION == response) {
84 
85  new SwingWorker<Void, Void>() {
86 
87  @Override
88  protected Void doInBackground() throws Exception {
89  Case.deleteCurrentCase();
90  return null;
91  }
92 
93  @Override
94  protected void done() {
95  try {
96  get();
97  } catch (InterruptedException | ExecutionException ex) {
98  LOGGER.log(Level.SEVERE, String.format("Failed to delete case %s at %s", caseName, caseDirectory), ex);
99  JOptionPane.showMessageDialog(
100  null,
101  Bundle.Case_deleteCaseFailureMessageBox_message(ex.getLocalizedMessage()),
102  Bundle.Case_deleteCaseFailureMessageBox_title(),
103  JOptionPane.ERROR_MESSAGE);
104  }
105  /*
106  * Re-open the startup window.
107  */
108  StartupWindowProvider.getInstance().open();
109  }
110  }.execute();
111  }
112  } catch (IllegalStateException ex) {
113  LOGGER.log(Level.SEVERE, "Case delete action called with no current case", ex);
114  }
115  }
116 
117  @Override
118  public void performAction() {
119  }
120 
121  @Override
122  public String getName() {
123  return NbBundle.getMessage(CaseDeleteAction.class, "CTL_CaseDeleteAction");
124  }
125 
126  @Override
127  public HelpCtx getHelpCtx() {
128  return HelpCtx.DEFAULT_HELP;
129  }
130 
131 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2016 Basis Technology. Generated on: Tue Feb 20 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.