Autopsy  4.20.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-2021 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;
47 
55 @ActionID(category = "Case", id = "org.sleuthkit.autopsy.casemodule.CaseOpenAction")
56 @ActionReference(path = "Menu/Case", position = 102)
57 @ActionRegistration(displayName = "#CTL_CaseOpenAction", lazy = false)
58 @NbBundle.Messages({"CTL_CaseOpenAction=Open Case"})
59 @ServiceProvider(service = CaseOpenAction.class)
60 public final class CaseOpenAction extends CallableSystemAction implements ActionListener {
61 
62  private static final long serialVersionUID = 1L;
63  private static final String DISPLAY_NAME = Bundle.CTL_CaseOpenAction();
64  private static final String PROP_BASECASE = "LBL_BaseCase_PATH"; //NON-NLS
65  private static final Logger LOGGER = Logger.getLogger(CaseOpenAction.class.getName());
66  private final FileFilter caseMetadataFileFilter;
67 
69 
76  public CaseOpenAction() {
77  caseMetadataFileFilter = new FileNameExtensionFilter(NbBundle.getMessage(CaseOpenAction.class, "CaseOpenAction.autFilter.title", Version.getName(), CaseMetadata.getFileExtension()), CaseMetadata.getFileExtension().substring(1));
78  fileChooserHelper = new JFileChooserFactory();
79  }
80 
86  void openCaseSelectionWindow() {
87  JFileChooser fileChooser = fileChooserHelper.getChooser();
88  fileChooser.setDragEnabled(false);
89  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
90  fileChooser.setMultiSelectionEnabled(false);
91  fileChooser.setFileFilter(caseMetadataFileFilter);
92 
93  if (null != ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE)) {
94  fileChooser.setCurrentDirectory(new File(ModuleSettings.getConfigSetting("Case", PROP_BASECASE))); //NON-NLS
95  }
96 
101  OpenMultiUserCaseDialog multiUserCaseDialog = OpenMultiUserCaseDialog.getInstance();
102  multiUserCaseDialog.setAlwaysOnTop(false);
103  String optionsDlgTitle = NbBundle.getMessage(Case.class, "CloseCaseWhileIngesting.Warning.title");
104  String optionsDlgMessage = NbBundle.getMessage(Case.class, "CloseCaseWhileIngesting.Warning");
105  if (IngestRunningCheck.checkAndConfirmProceed(optionsDlgTitle, optionsDlgMessage)) {
114  int retval = fileChooser.showOpenDialog(multiUserCaseDialog.isVisible()
115  ? multiUserCaseDialog : (Component) StartupWindowProvider.getInstance().getStartupWindow());
116  if (retval == JFileChooser.APPROVE_OPTION) {
117  /*
118  * Close the startup window, if it is open.
119  */
120  StartupWindowProvider.getInstance().close();
121 
122  /*
123  * Close the Open Multi-User Case window, if it is open.
124  */
125  multiUserCaseDialog.setVisible(false);
126 
127  /*
128  * Try to open the case associated with the case metadata file
129  * the user selected.
130  */
131  final String path = fileChooser.getSelectedFile().getPath();
132  String dirPath = fileChooser.getSelectedFile().getParent();
133  ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE, dirPath.substring(0, dirPath.lastIndexOf(File.separator)));
134  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
135  new SwingWorker<Void, Void>() {
136 
137  @Override
138  protected Void doInBackground() throws Exception {
139  Case.openAsCurrentCase(path);
140  return null;
141  }
142 
143  @Override
144  protected void done() {
145  try {
146  get();
147  } catch (InterruptedException | ExecutionException ex) {
148  if (ex instanceof InterruptedException || (null != ex.getCause() && !(ex.getCause() instanceof CaseActionCancelledException))) {
149  LOGGER.log(Level.SEVERE, String.format("Error opening case with metadata file path %s", path), ex); //NON-NLS
150  JOptionPane.showMessageDialog(
151  WindowManager.getDefault().getMainWindow(),
152  ex.getCause().getMessage(), //get the message of the wrapped exception
153  NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"),
154  JOptionPane.ERROR_MESSAGE);
155  }
156  StartupWindowProvider.getInstance().open();
157  } finally {
158  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
159  }
160  }
161  }.execute();
162  }
163  }
164  }
165 
172  @Override
173  public void actionPerformed(ActionEvent e) {
175  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
176 
177  OpenMultiUserCaseDialog multiUserCaseWindow = OpenMultiUserCaseDialog.getInstance();
178  multiUserCaseWindow.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
179  // Workaround to ensure that dialog is not hidden on macOS.
180  multiUserCaseWindow.setAlwaysOnTop(true);
181  multiUserCaseWindow.setVisible(true);
182 
183  WindowManager.getDefault().getMainWindow().setCursor(null);
184  } else {
185  openCaseSelectionWindow();
186  }
187  }
188 
189  @Override
190  public void performAction() {
191  actionPerformed(null);
192  }
193 
194  @Override
195  public String getName() {
196  return DISPLAY_NAME;
197  }
198 
199  @Override
200  public HelpCtx getHelpCtx() {
201  return HelpCtx.DEFAULT_HELP;
202  }
203 }
static synchronized String getConfigSetting(String moduleName, String settingName)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.