Move case opening and closing off the EDT

This commit is contained in:
Ann Priestman 2015-07-17 09:15:27 -04:00
parent b4ee3471eb
commit dec241a278
8 changed files with 342 additions and 72 deletions

View File

@ -44,6 +44,7 @@ import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.util.actions.CallableSystemAction; import org.openide.util.actions.CallableSystemAction;
import org.openide.util.actions.SystemAction; import org.openide.util.actions.SystemAction;
@ -523,20 +524,24 @@ public class Case {
String dbPath = caseDir + File.separator + "autopsy.db"; //NON-NLS String dbPath = caseDir + File.separator + "autopsy.db"; //NON-NLS
db = SleuthkitCase.openCase(dbPath); db = SleuthkitCase.openCase(dbPath);
if (null != db.getBackupDatabasePath()) { if (null != db.getBackupDatabasePath()) {
JOptionPane.showMessageDialog(null, SwingUtilities.invokeLater(() -> {
NbBundle.getMessage(Case.class, "Case.open.msgDlg.updated.msg", JOptionPane.showMessageDialog(null,
db.getBackupDatabasePath()), NbBundle.getMessage(Case.class, "Case.open.msgDlg.updated.msg",
NbBundle.getMessage(Case.class, "Case.open.msgDlg.updated.title"), db.getBackupDatabasePath()),
JOptionPane.INFORMATION_MESSAGE); NbBundle.getMessage(Case.class, "Case.open.msgDlg.updated.title"),
JOptionPane.INFORMATION_MESSAGE);
});
} }
} else { } else {
db = SleuthkitCase.openCase(xmlcm.getDatabaseName(), UserPreferences.getDatabaseConnectionInfo(), caseDir); db = SleuthkitCase.openCase(xmlcm.getDatabaseName(), UserPreferences.getDatabaseConnectionInfo(), caseDir);
if (null != db.getBackupDatabasePath()) { if (null != db.getBackupDatabasePath()) {
JOptionPane.showMessageDialog(null, SwingUtilities.invokeLater(() -> {
NbBundle.getMessage(Case.class, "Case.open.msgDlg.updated.msg", JOptionPane.showMessageDialog(null,
db.getBackupDatabasePath()), NbBundle.getMessage(Case.class, "Case.open.msgDlg.updated.msg",
NbBundle.getMessage(Case.class, "Case.open.msgDlg.updated.title"), db.getBackupDatabasePath()),
JOptionPane.INFORMATION_MESSAGE); NbBundle.getMessage(Case.class, "Case.open.msgDlg.updated.title"),
JOptionPane.INFORMATION_MESSAGE);
});
} }
} }
@ -786,7 +791,9 @@ public class Case {
name = newCaseName; // change the local value name = newCaseName; // change the local value
RecentCases.getInstance().updateRecentCase(oldCaseName, oldPath, newCaseName, newPath); // update the recent case RecentCases.getInstance().updateRecentCase(oldCaseName, oldPath, newCaseName, newPath); // update the recent case
eventPublisher.publish(new AutopsyEvent(Events.NAME.toString(), oldCaseName, newCaseName)); eventPublisher.publish(new AutopsyEvent(Events.NAME.toString(), oldCaseName, newCaseName));
updateMainWindowTitle(newCaseName); SwingUtilities.invokeLater(() -> {
updateMainWindowTitle(newCaseName);
});
} catch (Exception e) { } catch (Exception e) {
throw new CaseActionException(NbBundle.getMessage(this.getClass(), "Case.updateCaseName.exception.msg"), e); throw new CaseActionException(NbBundle.getMessage(this.getClass(), "Case.updateCaseName.exception.msg"), e);
} }
@ -1474,24 +1481,34 @@ public class Case {
if (toChangeTo.hasData()) { if (toChangeTo.hasData()) {
// open all top components // open all top components
CoreComponentControl.openCoreWindows(); SwingUtilities.invokeLater(() -> {
CoreComponentControl.openCoreWindows();
});
} else { } else {
// close all top components // close all top components
CoreComponentControl.closeCoreWindows(); SwingUtilities.invokeLater(() -> {
CoreComponentControl.closeCoreWindows();
});
} }
} }
if (IngestManager.getInstance().isRunningInteractively()) { if (IngestManager.getInstance().isRunningInteractively()) {
updateMainWindowTitle(currentCase.name); SwingUtilities.invokeLater(() -> {
updateMainWindowTitle(currentCase.name);
});
} else { } else {
Frame f = WindowManager.getDefault().getMainWindow(); SwingUtilities.invokeLater(() -> {
f.setTitle(Case.getAppName()); // set the window name to just application name Frame f = WindowManager.getDefault().getMainWindow();
f.setTitle(Case.getAppName()); // set the window name to just application name
});
} }
} else { // case is closed } else { // case is closed
if (IngestManager.getInstance().isRunningInteractively()) { if (IngestManager.getInstance().isRunningInteractively()) {
// close all top components first // close all top components first
CoreComponentControl.closeCoreWindows(); SwingUtilities.invokeLater(() -> {
CoreComponentControl.closeCoreWindows();
});
// disable these menus // disable these menus
CallableSystemAction.get(AddImageAction.class).setEnabled(false); // Add Image menu CallableSystemAction.get(AddImageAction.class).setEnabled(false); // Add Image menu
@ -1503,8 +1520,10 @@ public class Case {
//clear pending notifications //clear pending notifications
MessageNotifyUtil.Notify.clear(); MessageNotifyUtil.Notify.clear();
Frame f = WindowManager.getDefault().getMainWindow(); SwingUtilities.invokeLater(() -> {
f.setTitle(Case.getAppName()); // set the window name to just application name Frame f = WindowManager.getDefault().getMainWindow();
f.setTitle(Case.getAppName()); // set the window name to just application name
});
//try to force gc to happen //try to force gc to happen
System.gc(); System.gc();

View File

@ -27,6 +27,7 @@ import java.util.logging.Level;import org.sleuthkit.autopsy.coreutils.Logger;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.SwingWorker;
import org.openide.util.HelpCtx; import org.openide.util.HelpCtx;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.util.actions.CallableSystemAction; import org.openide.util.actions.CallableSystemAction;
@ -70,6 +71,26 @@ import org.openide.util.actions.Presenter;
return; return;
} }
new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
try{
Case result = Case.getCurrentCase();
result.closeCase();
} catch (CaseActionException | IllegalStateException ex){
Logger.getLogger(CaseCloseAction.class.getName()).log(Level.SEVERE, "Error closing case.", ex); //NON-NLS
}
return null;
}
@Override
protected void done() {
StartupWindowProvider.getInstance().open();
}
}.execute();
/*
Case result = Case.getCurrentCase(); Case result = Case.getCurrentCase();
try { try {
result.closeCase(); result.closeCase();
@ -82,7 +103,7 @@ import org.openide.util.actions.Presenter;
public void run() { public void run() {
StartupWindowProvider.getInstance().open(); StartupWindowProvider.getInstance().open();
} }
}); });*/
} }
/** /**

View File

@ -23,9 +23,12 @@ import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File; import java.io.File;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
@ -76,7 +79,7 @@ public final class CaseOpenAction implements ActionListener {
int retval = fc.showOpenDialog(WindowManager.getDefault().getMainWindow()); int retval = fc.showOpenDialog(WindowManager.getDefault().getMainWindow());
if (retval == JFileChooser.APPROVE_OPTION) { if (retval == JFileChooser.APPROVE_OPTION) {
String path = fc.getSelectedFile().getPath(); final String path = fc.getSelectedFile().getPath();
String dirPath = fc.getSelectedFile().getParent(); String dirPath = fc.getSelectedFile().getParent();
ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE, dirPath.substring(0, dirPath.lastIndexOf(File.separator))); ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE, dirPath.substring(0, dirPath.lastIndexOf(File.separator)));
// check if the file exists // check if the file exists
@ -96,6 +99,55 @@ public final class CaseOpenAction implements ActionListener {
// no need to show the error message to the user. // no need to show the error message to the user.
logger.log(Level.WARNING, "Error closing startup window.", ex); //NON-NLS logger.log(Level.WARNING, "Error closing startup window.", ex); //NON-NLS
} }
new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
// Create case.
try{
Case.open(path);
} catch (CaseActionException ex) {
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(null,
NbBundle.getMessage(this.getClass(),
"CaseOpenAction.msgDlg.cantOpenCase.msg", path,
ex.getMessage()),
NbBundle.getMessage(this.getClass(),
"CaseOpenAction.msgDlg.cantOpenCase.title"),
JOptionPane.ERROR_MESSAGE);
StartupWindowProvider.getInstance().open();
});
logger.log(Level.WARNING, "Error opening case in folder " + path, ex); //NON-NLS
}
return null;
}
@Override
protected void done() {
try {
get();
} catch (ExecutionException | InterruptedException ex) {
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(null,
NbBundle.getMessage(this.getClass(),
"CaseOpenAction.msgDlg.cantOpenCase.msg", path,
ex.getMessage()),
NbBundle.getMessage(this.getClass(),
"CaseOpenAction.msgDlg.cantOpenCase.title"),
JOptionPane.ERROR_MESSAGE);
StartupWindowProvider.getInstance().open();
});
logger.log(Level.WARNING, "Error opening case in folder " + path, ex); //NON-NLS
}
}
}.execute();
/*
try { try {
Case.open(path); // open the case Case.open(path); // open the case
} catch (CaseActionException ex) { } catch (CaseActionException ex) {
@ -109,7 +161,7 @@ public final class CaseOpenAction implements ActionListener {
logger.log(Level.WARNING, "Error opening case in folder " + path, ex); //NON-NLS logger.log(Level.WARNING, "Error opening case in folder " + path, ex); //NON-NLS
StartupWindowProvider.getInstance().open(); StartupWindowProvider.getInstance().open();
} }*/
} }
} }
} }

View File

@ -24,7 +24,10 @@ import java.awt.Dialog;
import java.io.File; import java.io.File;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.concurrent.ExecutionException;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.SwingWorker;
import javax.swing.SwingUtilities;
import org.openide.DialogDescriptor; import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer; import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor; import org.openide.NotifyDescriptor;
@ -81,7 +84,7 @@ import org.sleuthkit.datamodel.TskData.DbType;
* The method to perform new case creation * The method to perform new case creation
*/ */
private void newCaseAction() { private void newCaseAction() {
WizardDescriptor wizardDescriptor = new WizardDescriptor(getPanels()); final WizardDescriptor wizardDescriptor = new WizardDescriptor(getPanels());
// {0} will be replaced by WizardDesriptor.Panel.getComponent().getName() // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
wizardDescriptor.setTitleFormat(new MessageFormat("{0}")); wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
wizardDescriptor.setTitle(NbBundle.getMessage(this.getClass(), "NewCaseWizardAction.newCase.windowTitle.text")); wizardDescriptor.setTitle(NbBundle.getMessage(this.getClass(), "NewCaseWizardAction.newCase.windowTitle.text"));
@ -89,7 +92,73 @@ import org.sleuthkit.datamodel.TskData.DbType;
dialog.setVisible(true); dialog.setVisible(true);
dialog.toFront(); dialog.toFront();
if(wizardDescriptor.getValue() == WizardDescriptor.FINISH_OPTION){
new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
// Create case.
String caseNumber = (String) wizardDescriptor.getProperty("caseNumber"); //NON-NLS
String examiner = (String) wizardDescriptor.getProperty("caseExaminer"); //NON-NLS
final String caseName = (String) wizardDescriptor.getProperty("caseName"); //NON-NLS
String createdDirectory = (String) wizardDescriptor.getProperty("createdDirectory"); //NON-NLS
CaseType caseType = CaseType.values()[(int)wizardDescriptor.getProperty("caseType")]; //NON-NLS
try {
Case.create(createdDirectory, caseName, caseNumber, examiner, caseType);
} catch (Exception ex) {
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(null, NbBundle.getMessage(this.getClass(),
"CaseCreateAction.msgDlg.cantCreateCase.msg")+" "+caseName,
NbBundle.getMessage(this.getClass(),
"CaseOpenAction.msgDlg.cantOpenCase.title"),
JOptionPane.ERROR_MESSAGE);
});
}
return null;
}
@Override
protected void done() {
try {
get();
CaseType currentCaseType = CaseType.values()[(int)wizardDescriptor.getProperty("caseType")]; //NON-NLS
CaseDbConnectionInfo info = UserPreferences.getDatabaseConnectionInfo();
if ((currentCaseType==CaseType.SINGLE_USER_CASE) || ((info.getDbType() != DbType.SQLITE) && info.canConnect())) {
AddImageAction addImageAction = SystemAction.get(AddImageAction.class);
addImageAction.actionPerformed(null);
} else {
JOptionPane.showMessageDialog(null,
NbBundle.getMessage(this.getClass(), "NewCaseWizardAction.databaseProblem1.text"),
NbBundle.getMessage(this.getClass(), "NewCaseWizardAction.databaseProblem2.text"),
JOptionPane.ERROR_MESSAGE);
doFailedCaseCleanup(wizardDescriptor);
}
} catch (ExecutionException | InterruptedException ex) {
final String caseName = (String) wizardDescriptor.getProperty("caseName"); //NON-NLS
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(null, NbBundle.getMessage(this.getClass(),
"CaseCreateAction.msgDlg.cantCreateCase.msg")+" "+caseName,
NbBundle.getMessage(this.getClass(),
"CaseOpenAction.msgDlg.cantOpenCase.title"),
JOptionPane.ERROR_MESSAGE);
});
doFailedCaseCleanup(wizardDescriptor);
}
}
}.execute();
} else {
new Thread(() -> {
doFailedCaseCleanup(wizardDescriptor);
}).start();
}
/*
boolean finished = wizardDescriptor.getValue() == WizardDescriptor.FINISH_OPTION; // check if it finishes (it's not cancelled) boolean finished = wizardDescriptor.getValue() == WizardDescriptor.FINISH_OPTION; // check if it finishes (it's not cancelled)
boolean isCancelled = wizardDescriptor.getValue() == WizardDescriptor.CANCEL_OPTION; // check if the "Cancel" button is pressed boolean isCancelled = wizardDescriptor.getValue() == WizardDescriptor.CANCEL_OPTION; // check if the "Cancel" button is pressed
@ -125,9 +194,23 @@ import org.sleuthkit.datamodel.TskData.DbType;
Case.deleteCaseDirectory(new File(createdDirectory)); Case.deleteCaseDirectory(new File(createdDirectory));
} }
} }
panels = null; // reset the panel panels = null; // reset the panel*/
} }
private void doFailedCaseCleanup(WizardDescriptor wizardDescriptor){
String createdDirectory = (String) wizardDescriptor.getProperty("createdDirectory"); //NON-NLS
// if there's case opened, close the case
if (Case.existsCurrentCase()) {
// close the previous case if there's any
CaseCloseAction closeCase = SystemAction.get(CaseCloseAction.class);
closeCase.actionPerformed(null);
}
if (createdDirectory != null) {
logger.log(Level.INFO, "Deleting a created case directory due to isCancelled set, dir: " + createdDirectory); //NON-NLS
Case.deleteCaseDirectory(new File(createdDirectory));
}
}
/** /**
* Initialize panels representing individual wizard's steps and sets * Initialize panels representing individual wizard's steps and sets
* various properties for them influencing wizard appearance. * various properties for them influencing wizard appearance.

View File

@ -171,11 +171,14 @@ class NewCaseWizardPanel2 implements WizardDescriptor.ValidatingPanel<WizardDesc
*/ */
@Override @Override
public void storeSettings(WizardDescriptor settings) { public void storeSettings(WizardDescriptor settings) {
NewCaseVisualPanel2 currentComponent = getComponent();
settings.putProperty("caseNumber", currentComponent.getCaseNumber());
settings.putProperty("caseExaminer", currentComponent.getExaminer());
} }
@Override @Override
public void validate() throws WizardValidationException { public void validate() throws WizardValidationException {
/*
NewCaseVisualPanel2 currentComponent = getComponent(); NewCaseVisualPanel2 currentComponent = getComponent();
final String caseNumber = currentComponent.getCaseNumber(); final String caseNumber = currentComponent.getCaseNumber();
final String examiner = currentComponent.getExaminer(); final String examiner = currentComponent.getExaminer();
@ -198,6 +201,6 @@ class NewCaseWizardPanel2 implements WizardDescriptor.ValidatingPanel<WizardDesc
} catch (Exception ex) { } catch (Exception ex) {
throw new WizardValidationException(this.getComponent(), throw new WizardValidationException(this.getComponent(),
NbBundle.getMessage(this.getClass(), "NewCaseWizardPanel2.validate.errCreateCase.msg"), null); NbBundle.getMessage(this.getClass(), "NewCaseWizardPanel2.validate.errCreateCase.msg"), null);
} }*/
} }
} }

View File

@ -24,9 +24,12 @@ import java.awt.EventQueue;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.io.File; import java.io.File;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
@ -187,8 +190,8 @@ class OpenRecentCasePanel extends javax.swing.JPanel {
logger.log(Level.INFO, "No Case paths exist, cannot open the case"); //NON-NLS logger.log(Level.INFO, "No Case paths exist, cannot open the case"); //NON-NLS
return; return;
} }
String casePath = casePaths[imagesTable.getSelectedRow()]; final String casePath = casePaths[imagesTable.getSelectedRow()];
String caseName = caseNames[imagesTable.getSelectedRow()]; final String caseName = caseNames[imagesTable.getSelectedRow()];
if (!casePath.equals("")) { if (!casePath.equals("")) {
// Close the startup menu // Close the startup menu
try { try {
@ -198,34 +201,62 @@ class OpenRecentCasePanel extends javax.swing.JPanel {
logger.log(Level.WARNING, "Error: couldn't open case: " + caseName, ex); //NON-NLS logger.log(Level.WARNING, "Error: couldn't open case: " + caseName, ex); //NON-NLS
} }
// Open the recent cases // Open the recent cases
try { if (caseName.equals("") || casePath.equals("") || (!new File(casePath).exists())) {
if (caseName.equals("") || casePath.equals("") || (!new File(casePath).exists())) { JOptionPane.showMessageDialog(null,
JOptionPane.showMessageDialog(null, NbBundle.getMessage(this.getClass(),
NbBundle.getMessage(this.getClass(), "OpenRecentCasePanel.openCase.msgDlg.caseDoesntExist.msg",
"OpenRecentCasePanel.openCase.msgDlg.caseDoesntExist.msg", caseName),
caseName), NbBundle.getMessage(this.getClass(),
NbBundle.getMessage(this.getClass(), "OpenRecentCasePanel.openCase.msgDlg.err"),
"OpenRecentCasePanel.openCase.msgDlg.err"), JOptionPane.ERROR_MESSAGE);
JOptionPane.ERROR_MESSAGE); RecentCases.getInstance().removeRecentCase(caseName, casePath); // remove the recent case if it doesn't exist anymore
RecentCases.getInstance().removeRecentCase(caseName, casePath); // remove the recent case if it doesn't exist anymore
//if case is not opened, open the start window //if case is not opened, open the start window
if (Case.isCaseOpen() == false) { if (Case.isCaseOpen() == false) {
StartupWindowProvider.getInstance().open(); StartupWindowProvider.getInstance().open();
}
} else {
new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
// Create case.
try{
Case.open(casePath);
} catch (CaseActionException ex) {
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(null,
NbBundle.getMessage(this.getClass(),
"CaseOpenAction.msgDlg.cantOpenCase.msg", caseName,
ex.getMessage()),
NbBundle.getMessage(this.getClass(),
"CaseOpenAction.msgDlg.cantOpenCase.title"),
JOptionPane.ERROR_MESSAGE);
});
logger.log(Level.WARNING, "Error: couldn't open case: " + caseName, ex); //NON-NLS
}
return null;
} }
} else { @Override
Case.open(casePath); // open the case protected void done() {
} try {
} catch (CaseActionException ex) { get();
JOptionPane.showMessageDialog(null, } catch (ExecutionException | InterruptedException ex) {
NbBundle.getMessage(this.getClass(), SwingUtilities.invokeLater(() -> {
"CaseOpenAction.msgDlg.cantOpenCase.msg", caseName, JOptionPane.showMessageDialog(null,
ex.getMessage()), NbBundle.getMessage(this.getClass(),
NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.msg", caseName,
"CaseOpenAction.msgDlg.cantOpenCase.title"), ex.getMessage()),
JOptionPane.ERROR_MESSAGE); NbBundle.getMessage(this.getClass(),
logger.log(Level.WARNING, "Error: couldn't open case: " + caseName, ex); //NON-NLS "CaseOpenAction.msgDlg.cantOpenCase.title"),
JOptionPane.ERROR_MESSAGE);
});
logger.log(Level.WARNING, "Error: couldn't open case: " + caseName, ex); //NON-NLS
}
}
}.execute();
} }
} }
} }

View File

@ -23,9 +23,12 @@ import java.awt.EventQueue;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File; import java.io.File;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
@ -35,8 +38,8 @@ import org.sleuthkit.autopsy.coreutils.Logger;
*/ */
class RecentItems implements ActionListener { class RecentItems implements ActionListener {
String caseName; final String caseName;
String casePath; final String casePath;
private JPanel caller; // for error handling private JPanel caller; // for error handling
/** the constructor */ /** the constructor */
@ -76,6 +79,41 @@ class RecentItems implements ActionListener {
} }
} }
else { else {
new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
// Create case.
try{
Case.open(casePath);
} catch (CaseActionException ex) {
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(null,
NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.msg", casePath,
ex.getMessage()), NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"),
JOptionPane.ERROR_MESSAGE);
});
Logger.getLogger(RecentItems.class.getName()).log(Level.WARNING, "Error: Couldn't open recent case at " + casePath, ex); //NON-NLS
}
return null;
}
@Override
protected void done() {
try {
get();
} catch (ExecutionException | InterruptedException ex) {
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(null,
NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.msg", casePath,
ex.getMessage()), NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"),
JOptionPane.ERROR_MESSAGE);
});
Logger.getLogger(RecentItems.class.getName()).log(Level.WARNING, "Error opening recent case. ", ex); //NON-NLS
}
}
}.execute();
/*
try { try {
Case.open(casePath); // open the case Case.open(casePath); // open the case
} catch (CaseActionException ex) { } catch (CaseActionException ex) {
@ -84,7 +122,7 @@ class RecentItems implements ActionListener {
ex.getMessage()), NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"), ex.getMessage()), NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"),
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
Logger.getLogger(RecentItems.class.getName()).log(Level.WARNING, "Error: Couldn't open recent case at " + casePath, ex); //NON-NLS Logger.getLogger(RecentItems.class.getName()).log(Level.WARNING, "Error: Couldn't open recent case at " + casePath, ex); //NON-NLS
} }*/
} }
} }
} }

View File

@ -24,10 +24,12 @@ import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.concurrent.ExecutionException;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo; import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException; import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.SwingWorker;
import org.netbeans.spi.sendopts.OptionProcessor; import org.netbeans.spi.sendopts.OptionProcessor;
import org.netbeans.swing.tabcontrol.plaf.DefaultTabbedContainerUI; import org.netbeans.swing.tabcontrol.plaf.DefaultTabbedContainerUI;
import org.openide.modules.ModuleInstall; import org.openide.modules.ModuleInstall;
@ -74,13 +76,32 @@ public class Installer extends ModuleInstall {
for (OptionProcessor processor : processors) { for (OptionProcessor processor : processors) {
if (processor instanceof OpenFromArguments) { if (processor instanceof OpenFromArguments) {
OpenFromArguments argsProcessor = (OpenFromArguments) processor; OpenFromArguments argsProcessor = (OpenFromArguments) processor;
String caseFile = argsProcessor.getDefaultArg(); final String caseFile = argsProcessor.getDefaultArg();
if (caseFile != null && !caseFile.equals("") && caseFile.endsWith(".aut") && new File(caseFile).exists()) { //NON-NLS if (caseFile != null && !caseFile.equals("") && caseFile.endsWith(".aut") && new File(caseFile).exists()) { //NON-NLS
try {
Case.open(caseFile); new SwingWorker<Void, Void>() {
return;
} catch (Exception e) { @Override
} protected Void doInBackground() throws Exception {
// Create case.
try{
Case.open(caseFile);
} catch(Exception ex){
logger.log(Level.WARNING, "Error opening case. ", ex); //NON-NLS
}
return null;
}
@Override
protected void done() {
try {
get();
} catch (ExecutionException | InterruptedException ex) {
logger.log(Level.WARNING, "Error opening case. ", ex); //NON-NLS
}
}
}.execute();
return;
} }
} }
} }
@ -99,13 +120,15 @@ public class Installer extends ModuleInstall {
@Override @Override
public void close() { public void close() {
try { new Thread(() -> {
if (Case.isCaseOpen()) try {
Case.getCurrentCase().closeCase(); if (Case.isCaseOpen())
} Case.getCurrentCase().closeCase();
catch (CaseActionException ex) { }
logger.log(Level.WARNING, "Error closing case. ", ex); //NON-NLS catch (CaseActionException | IllegalStateException ex) {
} logger.log(Level.WARNING, "Error closing case. ", ex); //NON-NLS
}
}).start();
} }
private void setupLAF() { private void setupLAF() {