19 package org.sleuthkit.autopsy.casemodule;
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;
45 final class CaseDeleteAction
extends CallableSystemAction {
47 private static final long serialVersionUID = 1L;
48 private static final Logger logger = Logger.
getLogger(CaseDeleteAction.class.getName());
51 putValue(Action.NAME, NbBundle.getMessage(CaseDeleteAction.class,
"CTL_CaseDeleteAction"));
52 this.setEnabled(
false);
53 Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> {
54 setEnabled(null != evt.getNewValue() && UserPreferences.getMode() != UserPreferences.SelectedMode.REVIEW);
60 "Case.deleteCaseConfirmationDialog.title=Delete Current Case?",
61 "Case.deleteCaseConfirmationDialog.message=Are you sure you want to close and delete the current case?",
62 "Case.deleteCaseFailureMessageBox.title=Failed to Delete Case",
63 "# {0} - exception message",
"Case.deleteCaseFailureMessageBox.message=Error deleting case: {0}",})
64 public void actionPerformed(ActionEvent e) {
66 Case currentCase = Case.getCurrentCase();
67 String caseName = currentCase.getName();
68 String caseDirectory = currentCase.getCaseDirectory();
74 Object response = DialogDisplayer.getDefault().notify(
new NotifyDescriptor(
75 Bundle.Case_deleteCaseConfirmationDialog_message(),
76 Bundle.Case_deleteCaseConfirmationDialog_title(),
77 NotifyDescriptor.YES_NO_OPTION,
78 NotifyDescriptor.WARNING_MESSAGE,
80 NotifyDescriptor.NO_OPTION));
81 if (null != response && DialogDescriptor.YES_OPTION == response) {
83 new SwingWorker<Void, Void>() {
86 protected Void doInBackground() throws Exception {
87 Case.deleteCurrentCase();
92 protected void done() {
95 }
catch (InterruptedException | ExecutionException ex) {
96 logger.log(Level.SEVERE, String.format(
"Failed to delete case %s at %s", caseName, caseDirectory), ex);
97 JOptionPane.showMessageDialog(
99 Bundle.Case_deleteCaseFailureMessageBox_message(ex.getLocalizedMessage()),
100 Bundle.Case_deleteCaseFailureMessageBox_title(),
101 JOptionPane.ERROR_MESSAGE);
106 StartupWindowProvider.getInstance().open();
110 }
catch (IllegalStateException ex) {
111 logger.log(Level.SEVERE,
"Case delete action called with no current case", ex);
116 public void performAction() {
120 public String getName() {
121 return NbBundle.getMessage(CaseDeleteAction.class,
"CTL_CaseDeleteAction");
125 public HelpCtx getHelpCtx() {
126 return HelpCtx.DEFAULT_HELP;
synchronized static Logger getLogger(String name)