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;
 
   36 import org.openide.windows.WindowManager;
 
   46 final class CaseDeleteAction 
extends CallableSystemAction {
 
   48     private static final long serialVersionUID = 1L;
 
   49     private static final Logger logger = Logger.getLogger(CaseDeleteAction.class.getName());
 
   52         putValue(Action.NAME, NbBundle.getMessage(CaseDeleteAction.class, 
"CTL_CaseDeleteAction"));
 
   53         this.setEnabled(
false);
 
   54         Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> {
 
   58             setEnabled(null != evt.getNewValue() && FeatureAccessUtils.canDeleteCurrentCase());
 
   64         "Case.deleteCaseConfirmationDialog.title=Delete Current Case?",
 
   65         "Case.deleteCaseConfirmationDialog.message=Are you sure you want to close and delete the current case?",
 
   66         "Case.deleteCaseFailureMessageBox.title=Failed to Delete Case",
 
   67         "# {0} - exception message", 
"Case.deleteCaseFailureMessageBox.message=Error deleting case: {0}",})
 
   68     public void actionPerformed(ActionEvent e) {
 
   70             Case currentCase = Case.getCurrentCaseThrows();
 
   71             String caseName = currentCase.getName();
 
   72             String caseDirectory = currentCase.getCaseDirectory();
 
   78             Object response = DialogDisplayer.getDefault().notify(
new NotifyDescriptor(
 
   79                     Bundle.Case_deleteCaseConfirmationDialog_message(),
 
   80                     Bundle.Case_deleteCaseConfirmationDialog_title(),
 
   81                     NotifyDescriptor.YES_NO_OPTION,
 
   82                     NotifyDescriptor.WARNING_MESSAGE,
 
   84                     NotifyDescriptor.NO_OPTION));
 
   85             if (null != response && DialogDescriptor.YES_OPTION == response) {
 
   87                 new SwingWorker<Void, Void>() {
 
   90                     protected Void doInBackground() throws Exception {
 
   91                         Case.deleteCurrentCase();
 
   96                     protected void done() {
 
   99                         } 
catch (InterruptedException | ExecutionException ex) {
 
  100                             logger.log(Level.SEVERE, String.format(
"Failed to delete case %s at %s", caseName, caseDirectory), ex);
 
  101                             JOptionPane.showMessageDialog(
 
  102                                     WindowManager.getDefault().getMainWindow(),
 
  103                                     Bundle.Case_deleteCaseFailureMessageBox_message(ex.getLocalizedMessage()),
 
  104                                     Bundle.Case_deleteCaseFailureMessageBox_title(),
 
  105                                     JOptionPane.ERROR_MESSAGE);
 
  110                         StartupWindowProvider.getInstance().open();
 
  114         } 
catch (NoCurrentCaseException ex) {
 
  115             logger.log(Level.SEVERE, 
"Case delete action called with no current case", ex);
 
  120     public void performAction() {
 
  124     public String getName() {
 
  125         return NbBundle.getMessage(CaseDeleteAction.class, 
"CTL_CaseDeleteAction");
 
  129     public HelpCtx getHelpCtx() {
 
  130         return HelpCtx.DEFAULT_HELP;