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

Copyright © 2012-2018 Basis Technology. Generated on: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.