Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CaseCloseAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2015 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.Component;
22 import java.awt.event.ActionEvent;
23 import javax.swing.Action;
24 import javax.swing.ImageIcon;
25 import javax.swing.JButton;
26 import javax.swing.SwingWorker;
27 import org.openide.util.HelpCtx;
28 import org.openide.util.NbBundle;
29 import org.openide.util.actions.CallableSystemAction;
30 import org.openide.util.actions.Presenter;
33 import java.util.logging.Level;
34 import org.openide.DialogDescriptor;
35 import org.openide.DialogDisplayer;
36 import org.openide.NotifyDescriptor;
37 import org.openide.windows.WindowManager;
38 import java.awt.Cursor;
39 import org.openide.awt.ActionID;
40 import org.openide.awt.ActionReference;
41 import org.openide.awt.ActionReferences;
42 import org.openide.awt.ActionRegistration;
43 
48 @ActionID(category = "Tools", id = "org.sleuthkit.autopsy.casemodule.CaseCloseAction")
49 @ActionRegistration(displayName = "#CTL_CaseCloseAct", lazy = false)
50 @ActionReferences(value = {
51  @ActionReference(path = "Toolbars/Case", position = 104)})
52 public final class CaseCloseAction extends CallableSystemAction implements Presenter.Toolbar {
53 
54  JButton toolbarButton = new JButton();
55 
59  public CaseCloseAction() {
60  putValue("iconBase", "org/sleuthkit/autopsy/images/close-icon.png"); // put the icon NON-NLS
61  putValue(Action.NAME, NbBundle.getMessage(CaseCloseAction.class, "CTL_CaseCloseAct")); // put the action Name
62 
63  // set action of the toolbar button
64  toolbarButton.addActionListener(CaseCloseAction.this::actionPerformed);
65 
66  this.setEnabled(false);
67  }
68 
74  @Override
75  public void actionPerformed(ActionEvent e) {
76 
77  // if ingest is ongoing, warn and get confirmaion before opening a different case
79  // show the confirmation first to close the current case and open the "New Case" wizard panel
80  String closeCurrentCase = NbBundle.getMessage(this.getClass(), "CloseCaseWhileIngesting.Warning");
81  NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(closeCurrentCase,
82  NbBundle.getMessage(this.getClass(), "CloseCaseWhileIngesting.Warning.title"),
83  NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
84  descriptor.setValue(NotifyDescriptor.NO_OPTION);
85 
86  Object res = DialogDisplayer.getDefault().notify(descriptor);
87  if (res != null && res == DialogDescriptor.YES_OPTION) {
88  try {
89  Case.getCurrentCase().closeCase(); // close the current case
90  } catch (Exception ex) {
91  Logger.getLogger(NewCaseWizardAction.class.getName()).log(Level.WARNING, "Error closing case.", ex); //NON-NLS
92  }
93  } else {
94  return;
95  }
96  }
97 
98  if (Case.isCaseOpen() == false) {
99  return;
100  }
101  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
102  new SwingWorker<Void, Void>() {
103 
104  @Override
105  protected Void doInBackground() throws Exception {
106  try {
107  Case result = Case.getCurrentCase();
108  result.closeCase();
109  } catch (CaseActionException | IllegalStateException unused) {
110  // Already logged.
111  }
112  return null;
113  }
114 
115  @Override
116  protected void done() {
117  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
119  }
120  }.execute();
121  }
122 
127  @Override
128  public void performAction() {
129  }
130 
136  @Override
137  public String getName() {
138  return NbBundle.getMessage(CaseCloseAction.class, "CTL_CaseCloseAct");
139  }
140 
146  @Override
147  public HelpCtx getHelpCtx() {
148  return HelpCtx.DEFAULT_HELP;
149  }
150 
156  @Override
157  public Component getToolbarPresenter() {
158  ImageIcon icon = new ImageIcon(getClass().getResource("btn_icon_close_case.png")); //NON-NLS
159  toolbarButton.setIcon(icon);
160  toolbarButton.setText(this.getName());
161  return toolbarButton;
162  }
163 
169  @Override
170  public void setEnabled(boolean value) {
171  super.setEnabled(value);
172  toolbarButton.setEnabled(value);
173  }
174 }
static synchronized IngestManager getInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.