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;
44 final class CaseDeleteAction
extends CallableSystemAction {
46 private static final long serialVersionUID = 1L;
47 private static final Logger LOGGER = Logger.
getLogger(CaseDeleteAction.class.getName());
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) -> {
56 setEnabled(null != evt.getNewValue());
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) {
68 Case currentCase = Case.getCurrentCase();
69 String caseName = currentCase.getName();
70 String caseDirectory = currentCase.getCaseDirectory();
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,
82 NotifyDescriptor.NO_OPTION));
83 if (null != response && DialogDescriptor.YES_OPTION == response) {
85 new SwingWorker<Void, Void>() {
88 protected Void doInBackground() throws Exception {
89 Case.deleteCurrentCase();
94 protected void done() {
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(
101 Bundle.Case_deleteCaseFailureMessageBox_message(ex.getLocalizedMessage()),
102 Bundle.Case_deleteCaseFailureMessageBox_title(),
103 JOptionPane.ERROR_MESSAGE);
108 StartupWindowProvider.getInstance().open();
112 }
catch (IllegalStateException ex) {
113 LOGGER.log(Level.SEVERE,
"Case delete action called with no current case", ex);
118 public void performAction() {
122 public String getName() {
123 return NbBundle.getMessage(CaseDeleteAction.class,
"CTL_CaseDeleteAction");
127 public HelpCtx getHelpCtx() {
128 return HelpCtx.DEFAULT_HELP;
synchronized static Logger getLogger(String name)