Autopsy  4.14.0
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.Component;
22 import java.awt.Cursor;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.io.File;
26 import java.util.concurrent.ExecutionException;
27 import java.util.logging.Level;
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 final FileFilter caseMetadataFileFilter;
66 
73  public CaseOpenAction() {
74  caseMetadataFileFilter = new FileNameExtensionFilter(NbBundle.getMessage(CaseOpenAction.class, "CaseOpenAction.autFilter.title", Version.getName(), CaseMetadata.getFileExtension()), CaseMetadata.getFileExtension().substring(1));
75  }
76 
82  void openCaseSelectionWindow() {
83  JFileChooser fileChooser = new JFileChooser();
84  fileChooser.setDragEnabled(false);
85  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
86  fileChooser.setMultiSelectionEnabled(false);
87  fileChooser.setFileFilter(caseMetadataFileFilter);
88 
89  if (null != ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE)) {
90  fileChooser.setCurrentDirectory(new File(ModuleSettings.getConfigSetting("Case", PROP_BASECASE))); //NON-NLS
91  }
92 
97  OpenMultiUserCaseDialog multiUserCaseDialog = OpenMultiUserCaseDialog.getInstance();
98  multiUserCaseDialog.setAlwaysOnTop(false);
99  String optionsDlgTitle = NbBundle.getMessage(Case.class, "CloseCaseWhileIngesting.Warning.title");
100  String optionsDlgMessage = NbBundle.getMessage(Case.class, "CloseCaseWhileIngesting.Warning");
101  if (IngestRunningCheck.checkAndConfirmProceed(optionsDlgTitle, optionsDlgMessage)) {
110  int retval = fileChooser.showOpenDialog(multiUserCaseDialog.isVisible()
111  ? multiUserCaseDialog : (Component) StartupWindowProvider.getInstance().getStartupWindow());
112  if (retval == JFileChooser.APPROVE_OPTION) {
113  /*
114  * Close the startup window, if it is open.
115  */
116  StartupWindowProvider.getInstance().close();
117 
118  /*
119  * Close the Open Multi-User Case window, if it is open.
120  */
121  multiUserCaseDialog.setVisible(false);
122 
123  /*
124  * Try to open the case associated with the case metadata file
125  * the user selected.
126  */
127  final String path = fileChooser.getSelectedFile().getPath();
128  String dirPath = fileChooser.getSelectedFile().getParent();
129  ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE, dirPath.substring(0, dirPath.lastIndexOf(File.separator)));
130  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
131  new SwingWorker<Void, Void>() {
132 
133  @Override
134  protected Void doInBackground() throws Exception {
135  Case.openAsCurrentCase(path);
136  return null;
137  }
138 
139  @Override
140  protected void done() {
141  try {
142  get();
143  } catch (InterruptedException | ExecutionException ex) {
144  if (ex instanceof InterruptedException || (null != ex.getCause() && !(ex.getCause() instanceof CaseActionCancelledException))) {
145  LOGGER.log(Level.SEVERE, String.format("Error opening case with metadata file path %s", path), ex); //NON-NLS
146  JOptionPane.showMessageDialog(
147  WindowManager.getDefault().getMainWindow(),
148  ex.getCause().getMessage(), //get the message of the wrapped exception
149  NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"),
150  JOptionPane.ERROR_MESSAGE);
151  }
152  StartupWindowProvider.getInstance().open();
153  } finally {
154  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
155  }
156  }
157  }.execute();
158  }
159  }
160  }
161 
168  @Override
169  public void actionPerformed(ActionEvent e) {
171  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
172 
173  OpenMultiUserCaseDialog multiUserCaseWindow = OpenMultiUserCaseDialog.getInstance();
174  multiUserCaseWindow.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
175  // Workaround to ensure that dialog is not hidden on macOS.
176  multiUserCaseWindow.setAlwaysOnTop(true);
177  multiUserCaseWindow.setVisible(true);
178 
179  WindowManager.getDefault().getMainWindow().setCursor(null);
180  } else {
181  openCaseSelectionWindow();
182  }
183  }
184 
185  @Override
186  public void performAction() {
187  actionPerformed(null);
188  }
189 
190  @Override
191  public String getName() {
192  return DISPLAY_NAME;
193  }
194 
195  @Override
196  public HelpCtx getHelpCtx() {
197  return HelpCtx.DEFAULT_HELP;
198  }
199 }
static synchronized String getConfigSetting(String moduleName, String settingName)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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