Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CaseOpenAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 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.Cursor;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.io.File;
25 import java.util.concurrent.ExecutionException;
26 import java.util.logging.Level;
27 import javax.swing.JDialog;
28 import javax.swing.JFileChooser;
29 import javax.swing.JOptionPane;
30 import javax.swing.SwingWorker;
31 import javax.swing.filechooser.FileFilter;
32 import javax.swing.filechooser.FileNameExtensionFilter;
33 import org.openide.awt.ActionID;
34 import org.openide.awt.ActionReference;
35 import org.openide.awt.ActionRegistration;
36 import org.openide.util.HelpCtx;
37 import org.openide.util.NbBundle;
38 import org.openide.util.actions.CallableSystemAction;
39 import org.openide.util.lookup.ServiceProvider;
40 import org.openide.windows.WindowManager;
46 
54 @ActionID(category = "Case", id = "org.sleuthkit.autopsy.casemodule.CaseOpenAction")
55 @ActionReference(path = "Menu/Case", position = 102)
56 @ActionRegistration(displayName = "#CTL_CaseOpenAction", lazy = false)
57 @NbBundle.Messages({"CTL_CaseOpenAction=Open Case"})
58 @ServiceProvider(service = CaseOpenAction.class)
59 public final class CaseOpenAction extends CallableSystemAction implements ActionListener {
60 
61  private static final long serialVersionUID = 1L;
62  private static final String DISPLAY_NAME = Bundle.CTL_CaseOpenAction();
63  private static final String PROP_BASECASE = "LBL_BaseCase_PATH"; //NON-NLS
64  private static final Logger LOGGER = Logger.getLogger(CaseOpenAction.class.getName());
65  private static JDialog multiUserCaseWindow;
66  private final JFileChooser fileChooser = new JFileChooser();
67  private final FileFilter caseMetadataFileFilter;
68 
75  public CaseOpenAction() {
76  caseMetadataFileFilter = new FileNameExtensionFilter(NbBundle.getMessage(CaseOpenAction.class, "CaseOpenAction.autFilter.title", Version.getName(), CaseMetadata.getFileExtension()), CaseMetadata.getFileExtension().substring(1));
77  fileChooser.setDragEnabled(false);
78  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
79  fileChooser.setMultiSelectionEnabled(false);
80  fileChooser.setFileFilter(caseMetadataFileFilter);
81  if (null != ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE)) {
82  fileChooser.setCurrentDirectory(new File(ModuleSettings.getConfigSetting("Case", PROP_BASECASE))); //NON-NLS
83  }
84  }
85 
91  void openCaseSelectionWindow() {
92  String optionsDlgTitle = NbBundle.getMessage(Case.class, "CloseCaseWhileIngesting.Warning.title");
93  String optionsDlgMessage = NbBundle.getMessage(Case.class, "CloseCaseWhileIngesting.Warning");
94  if (IngestRunningCheck.checkAndConfirmProceed(optionsDlgTitle, optionsDlgMessage)) {
99  int retval = fileChooser.showOpenDialog(WindowManager.getDefault().getMainWindow());
100  if (retval == JFileChooser.APPROVE_OPTION) {
101  /*
102  * Close the startup window, if it is open.
103  */
105 
106  /*
107  * Close the Open Multi-User Case window, if it is open.
108  */
109  if (multiUserCaseWindow != null) {
110  multiUserCaseWindow.setVisible(false);
111  }
112 
113  /*
114  * Try to open the case associated with the case metadata file
115  * the user selected.
116  */
117  final String path = fileChooser.getSelectedFile().getPath();
118  String dirPath = fileChooser.getSelectedFile().getParent();
119  ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE, dirPath.substring(0, dirPath.lastIndexOf(File.separator)));
120  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
121  new SwingWorker<Void, Void>() {
122 
123  @Override
124  protected Void doInBackground() throws Exception {
125  Case.openAsCurrentCase(path);
126  return null;
127  }
128 
129  @Override
130  protected void done() {
131  try {
132  get();
133  } catch (InterruptedException | ExecutionException ex) {
134  if (ex instanceof InterruptedException || (null != ex.getCause() && !(ex.getCause() instanceof CaseActionCancelledException))) {
135  LOGGER.log(Level.SEVERE, String.format("Error opening case with metadata file path %s", path), ex); //NON-NLS
136  JOptionPane.showMessageDialog(
137  WindowManager.getDefault().getMainWindow(),
138  ex.getCause().getMessage(), //get the message of the wrapped exception
139  NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"), //NON-NLS
140  JOptionPane.ERROR_MESSAGE);
141  }
142  StartupWindowProvider.getInstance().open();
143  } finally {
144  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
145  }
146  }
147  }.execute();
148  }
149  }
150  }
151 
158  @Override
159  public void actionPerformed(ActionEvent e) {
161  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
162 
163  if (multiUserCaseWindow == null) {
164  multiUserCaseWindow = MultiUserCasesDialog.getInstance();
165  }
166  multiUserCaseWindow.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
167  multiUserCaseWindow.setVisible(true);
168 
169  WindowManager.getDefault().getMainWindow().setCursor(null);
170  } else {
171  openCaseSelectionWindow();
172  }
173  }
174 
175  @Override
176  public void performAction() {
177  actionPerformed(null);
178  }
179 
180  @Override
181  public String getName() {
182  return DISPLAY_NAME;
183  }
184 
185  @Override
186  public HelpCtx getHelpCtx() {
187  return HelpCtx.DEFAULT_HELP;
188  }
189 }
static boolean checkAndConfirmProceed(String optionsDlgTitle, String optionsDlgMessage)
static String getConfigSetting(String moduleName, String settingName)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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