Autopsy  4.21.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-2020 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;
36 import org.openide.windows.WindowManager;
39 
46 final class CaseDeleteAction extends CallableSystemAction {
47 
48  private static final long serialVersionUID = 1L;
49  private static final Logger logger = Logger.getLogger(CaseDeleteAction.class.getName());
50 
51  CaseDeleteAction() {
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) -> {
55  /*
56  * A value of 'null' signifies that there is no case open.
57  */
58  setEnabled(null != evt.getNewValue() && FeatureAccessUtils.canDeleteCurrentCase());
59  });
60  }
61 
62  @Override
63  @Messages({
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) {
69  try {
70  Case currentCase = Case.getCurrentCaseThrows();
71  String caseName = currentCase.getName();
72  String caseDirectory = currentCase.getCaseDirectory();
73 
74  /*
75  * Do a confirmation dialog and close the current case if the user
76  * confirms he/she wants to proceed.
77  */
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,
83  null,
84  NotifyDescriptor.NO_OPTION));
85  if (null != response && DialogDescriptor.YES_OPTION == response) {
86 
87  new SwingWorker<Void, Void>() {
88 
89  @Override
90  protected Void doInBackground() throws Exception {
91  Case.deleteCurrentCase();
92  return null;
93  }
94 
95  @Override
96  protected void done() {
97  try {
98  get();
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);
106  }
107  /*
108  * Re-open the startup window.
109  */
110  StartupWindowProvider.getInstance().open();
111  }
112  }.execute();
113  }
114  } catch (NoCurrentCaseException ex) {
115  logger.log(Level.SEVERE, "Case delete action called with no current case", ex);
116  }
117  }
118 
119  @Override
120  public void performAction() {
121  }
122 
123  @Override
124  public String getName() {
125  return NbBundle.getMessage(CaseDeleteAction.class, "CTL_CaseDeleteAction");
126  }
127 
128  @Override
129  public HelpCtx getHelpCtx() {
130  return HelpCtx.DEFAULT_HELP;
131  }
132 
133 }

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