19 package org.sleuthkit.autopsy.casemodule;
 
   21 import java.awt.Component;
 
   22 import java.awt.Cursor;
 
   23 import java.awt.event.ActionEvent;
 
   24 import java.awt.event.ActionListener;
 
   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;
 
   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 {
 
   63     private static final String 
DISPLAY_NAME = Bundle.CTL_CaseOpenAction();
 
   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);
 
  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) {
 
  120                 StartupWindowProvider.getInstance().close();
 
  125                 multiUserCaseDialog.setVisible(
false);
 
  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>() {
 
  138                     protected Void doInBackground() throws Exception {
 
  139                         Case.openAsCurrentCase(path);
 
  144                     protected void done() {
 
  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); 
 
  150                                 JOptionPane.showMessageDialog(
 
  151                                         WindowManager.getDefault().getMainWindow(),
 
  152                                         ex.getCause().getMessage(), 
 
  153                                         NbBundle.getMessage(this.getClass(), 
"CaseOpenAction.msgDlg.cantOpenCase.title"),
 
  154                                         JOptionPane.ERROR_MESSAGE);
 
  156                             StartupWindowProvider.getInstance().open();
 
  158                             WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
 
  175             WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
 
  177             OpenMultiUserCaseDialog multiUserCaseWindow = OpenMultiUserCaseDialog.getInstance();
 
  178             multiUserCaseWindow.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
 
  180             multiUserCaseWindow.setAlwaysOnTop(
true);
 
  181             multiUserCaseWindow.setVisible(
true);
 
  183             WindowManager.getDefault().getMainWindow().setCursor(null);
 
  185             openCaseSelectionWindow();
 
  201         return HelpCtx.DEFAULT_HELP;
 
static synchronized String getConfigSetting(String moduleName, String settingName)
 
static final String PROP_BASECASE
 
void actionPerformed(ActionEvent e)
 
static boolean getIsMultiUserModeEnabled()
 
final FileFilter caseMetadataFileFilter
 
static final String DISPLAY_NAME
 
JFileChooser getChooser()
 
static final String MAIN_SETTINGS
 
synchronized static Logger getLogger(String name)
 
final JFileChooserFactory fileChooserHelper
 
static final Logger LOGGER
 
static final long serialVersionUID