Autopsy  4.4.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.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.util.HelpCtx;
33 import org.openide.util.NbBundle;
34 import org.openide.util.actions.CallableSystemAction;
35 import org.openide.util.lookup.ServiceProvider;
36 import org.openide.windows.WindowManager;
41 
49 @ServiceProvider(service = CaseOpenAction.class)
50 public final class CaseOpenAction extends CallableSystemAction implements ActionListener {
51 
52  private static final long serialVersionUID = 1L;
53  private static final String PROP_BASECASE = "LBL_BaseCase_PATH"; //NON-NLS
54  private static final Logger logger = Logger.getLogger(CaseOpenAction.class.getName());
55  private final JFileChooser fileChooser = new JFileChooser();
56  private final FileFilter caseMetadataFileFilter;
57 
65  public CaseOpenAction() {
66  caseMetadataFileFilter = new FileNameExtensionFilter(NbBundle.getMessage(CaseOpenAction.class, "CaseOpenAction.autFilter.title", Version.getName(), CaseMetadata.getFileExtension()), CaseMetadata.getFileExtension().substring(1));
67  fileChooser.setDragEnabled(false);
68  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
69  fileChooser.setMultiSelectionEnabled(false);
70  fileChooser.setFileFilter(caseMetadataFileFilter);
71  if (null != ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE)) {
72  fileChooser.setCurrentDirectory(new File(ModuleSettings.getConfigSetting("Case", PROP_BASECASE))); //NON-NLS
73  }
74  }
75 
82  @Override
83  public void actionPerformed(ActionEvent e) {
84  String optionsDlgTitle = NbBundle.getMessage(Case.class, "CloseCaseWhileIngesting.Warning.title");
85  String optionsDlgMessage = NbBundle.getMessage(Case.class, "CloseCaseWhileIngesting.Warning");
86  if (IngestRunningCheck.checkAndConfirmProceed(optionsDlgTitle, optionsDlgMessage)) {
91  int retval = fileChooser.showOpenDialog(WindowManager.getDefault().getMainWindow());
92  if (retval == JFileChooser.APPROVE_OPTION) {
93  /*
94  * Close the startup window, if it is open.
95  */
97 
98  /*
99  * Try to open the case associated with the case metadata file
100  * the user selected.
101  */
102  final String path = fileChooser.getSelectedFile().getPath();
103  String dirPath = fileChooser.getSelectedFile().getParent();
104  ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE, dirPath.substring(0, dirPath.lastIndexOf(File.separator)));
105  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
106  new SwingWorker<Void, Void>() {
107 
108  @Override
109  protected Void doInBackground() throws Exception {
110  Case.openAsCurrentCase(path);
111  return null;
112  }
113 
114  @Override
115  protected void done() {
116  try {
117  get();
118  } catch (InterruptedException | ExecutionException ex) {
119  if (ex instanceof InterruptedException || (null != ex.getCause() && !(ex.getCause() instanceof CaseActionCancelledException))) {
120  logger.log(Level.SEVERE, String.format("Error opening case with metadata file path %s", path), ex); //NON-NLS
121  JOptionPane.showMessageDialog(
122  WindowManager.getDefault().getMainWindow(),
123  ex.getCause().getMessage(), //get the message of the wrapped exception
124  NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"), //NON-NLS
125  JOptionPane.ERROR_MESSAGE);
126  }
128  } finally {
129  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
130  }
131  }
132  }.execute();
133  }
134  }
135  }
136 
137  @Override
138  public void performAction() {
139  actionPerformed(null);
140  }
141 
142  @Override
143  public String getName() {
144  return NbBundle.getMessage(CaseOpenAction.class, "CTL_OpenAction");
145  }
146 
147  @Override
148  public HelpCtx getHelpCtx() {
149  return HelpCtx.DEFAULT_HELP;
150  }
151 }
static boolean checkAndConfirmProceed(String optionsDlgTitle, String optionsDlgMessage)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static void openAsCurrentCase(String caseMetadataFilePath)
Definition: Case.java:512
static String getConfigSetting(String moduleName, String settingName)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.