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;
 
   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 {
 
   62     private static final String 
DISPLAY_NAME = Bundle.CTL_CaseOpenAction();
 
   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);
 
   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) {
 
  116                 StartupWindowProvider.getInstance().close();
 
  121                 multiUserCaseDialog.setVisible(
false);
 
  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>() {
 
  134                     protected Void doInBackground() throws Exception {
 
  135                         Case.openAsCurrentCase(path);
 
  140                     protected void done() {
 
  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); 
 
  146                                 JOptionPane.showMessageDialog(
 
  147                                         WindowManager.getDefault().getMainWindow(),
 
  148                                         ex.getCause().getMessage(), 
 
  149                                         NbBundle.getMessage(this.getClass(), 
"CaseOpenAction.msgDlg.cantOpenCase.title"),
 
  150                                         JOptionPane.ERROR_MESSAGE);
 
  152                             StartupWindowProvider.getInstance().open();
 
  154                             WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
 
  171             WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
 
  173             OpenMultiUserCaseDialog multiUserCaseWindow = OpenMultiUserCaseDialog.getInstance();
 
  174             multiUserCaseWindow.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
 
  176             multiUserCaseWindow.setAlwaysOnTop(
true);
 
  177             multiUserCaseWindow.setVisible(
true);
 
  179             WindowManager.getDefault().getMainWindow().setCursor(null);
 
  181             openCaseSelectionWindow();
 
  197         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
 
static final String MAIN_SETTINGS
 
synchronized static Logger getLogger(String name)
 
static final Logger LOGGER
 
static final long serialVersionUID