Autopsy  4.0
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 
44 public final class CaseCloseAction extends CallableSystemAction implements Presenter.Toolbar {
45 
46  JButton toolbarButton = new JButton();
47 
51  public CaseCloseAction() {
52  putValue("iconBase", "org/sleuthkit/autopsy/images/close-icon.png"); // put the icon NON-NLS
53  putValue(Action.NAME, NbBundle.getMessage(CaseCloseAction.class, "CTL_CaseCloseAct")); // put the action Name
54 
55  // set action of the toolbar button
56  toolbarButton.addActionListener(CaseCloseAction.this::actionPerformed);
57 
58  this.setEnabled(false);
59  }
60 
66  @Override
67  public void actionPerformed(ActionEvent e) {
68 
69  // if ingest is ongoing, warn and get confirmaion before opening a different case
71  // show the confirmation first to close the current case and open the "New Case" wizard panel
72  String closeCurrentCase = NbBundle.getMessage(this.getClass(), "CloseCaseWhileIngesting.Warning");
73  NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(closeCurrentCase,
74  NbBundle.getMessage(this.getClass(), "CloseCaseWhileIngesting.Warning.title"),
75  NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
76  descriptor.setValue(NotifyDescriptor.NO_OPTION);
77 
78  Object res = DialogDisplayer.getDefault().notify(descriptor);
79  if (res != null && res == DialogDescriptor.YES_OPTION) {
80  try {
81  Case.getCurrentCase().closeCase(); // close the current case
82  } catch (Exception ex) {
83  Logger.getLogger(NewCaseWizardAction.class.getName()).log(Level.WARNING, "Error closing case.", ex); //NON-NLS
84  }
85  } else {
86  return;
87  }
88  }
89 
90  if (Case.existsCurrentCase() == false) {
91  return;
92  }
93  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
94  new SwingWorker<Void, Void>() {
95 
96  @Override
97  protected Void doInBackground() throws Exception {
98  try {
99  Case result = Case.getCurrentCase();
100  result.closeCase();
101  } catch (CaseActionException | IllegalStateException unused) {
102  // Already logged.
103  }
104  return null;
105  }
106 
107  @Override
108  protected void done() {
109  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
111  }
112  }.execute();
113  }
114 
119  @Override
120  public void performAction() {
121  }
122 
128  @Override
129  public String getName() {
130  return NbBundle.getMessage(CaseCloseAction.class, "CTL_CaseCloseAct");
131  }
132 
138  @Override
139  public HelpCtx getHelpCtx() {
140  return HelpCtx.DEFAULT_HELP;
141  }
142 
148  @Override
149  public Component getToolbarPresenter() {
150  ImageIcon icon = new ImageIcon(getClass().getResource("btn_icon_close_case.png")); //NON-NLS
151  toolbarButton.setIcon(icon);
152  toolbarButton.setText(this.getName());
153  return toolbarButton;
154  }
155 
161  @Override
162  public void setEnabled(boolean value) {
163  super.setEnabled(value);
164  toolbarButton.setEnabled(value);
165  }
166 }
static synchronized IngestManager getInstance()
static boolean existsCurrentCase()
Definition: Case.java:966
synchronized static Logger getLogger(String name)
Definition: Logger.java:166

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.