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

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