Tidy up autopsy.casemodule.OpenRecentCasePanel

This commit is contained in:
Richard Cordovano 2016-01-28 16:17:42 -05:00
parent ae991f5c7a
commit 330ed4b3f5
4 changed files with 151 additions and 149 deletions

View File

@ -114,7 +114,6 @@ Case.open.msgDlg.updated.msg=Updated case database schema.\nA backup copy of the
Case.open.msgDlg.updated.title=Case Database Schema Update Case.open.msgDlg.updated.title=Case Database Schema Update
Case.open.exception.checkFile.msg=Check that you selected the correct case file (usually with {0} extension) Case.open.exception.checkFile.msg=Check that you selected the correct case file (usually with {0} extension)
Case.open.exception.multiUserCaseNotEnabled=Cannot open a multi-user case if multi-user cases are not enabled. See Tools, Options, Multi-user. Case.open.exception.multiUserCaseNotEnabled=Cannot open a multi-user case if multi-user cases are not enabled. See Tools, Options, Multi-user.
Case.open.exception.gen.msg=Error opening the case
Case.checkImgExist.confDlg.doesntExist.msg={0} has detected that one of the images associated with \n\ Case.checkImgExist.confDlg.doesntExist.msg={0} has detected that one of the images associated with \n\
this case are missing. Would you like to search for them now?\n\ this case are missing. Would you like to search for them now?\n\
Previously, the image was located at\:\n\ Previously, the image was located at\:\n\

View File

@ -109,7 +109,6 @@ Case.open.msgDlg.updated.msg=\u30b1\u30fc\u30b9\u30c7\u30fc\u30bf\u30d9\u30fc\u3
{0} {0}
Case.open.msgDlg.updated.title=\u30b1\u30fc\u30b9\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30b9\u30ad\u30fc\u30de\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8 Case.open.msgDlg.updated.title=\u30b1\u30fc\u30b9\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30b9\u30ad\u30fc\u30de\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8
Case.open.exception.checkFile.msg=\u6b63\u3057\u3044\u30b1\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u3092\u9078\u629e\u3057\u305f\u304b\u78ba\u8a8d\u3057\u3066\u4e0b\u3055\u3044\uff08\u901a\u5e38\u62e1\u5f35\u5b50{0}\u3092\u6301\u3064\uff09 Case.open.exception.checkFile.msg=\u6b63\u3057\u3044\u30b1\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u3092\u9078\u629e\u3057\u305f\u304b\u78ba\u8a8d\u3057\u3066\u4e0b\u3055\u3044\uff08\u901a\u5e38\u62e1\u5f35\u5b50{0}\u3092\u6301\u3064\uff09
Case.open.exception.gen.msg=\u30b1\u30fc\u30b9\u3092\u958b\u304f\u306e\u306b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f
Case.checkImgExist.confDlg.doesntExist.msg={0} \u304c\u3053\u306e\u30b1\u30fc\u30b9\u306b\u95a2\u9023\u3059\u308b\u30a4\u30e1\u30fc\u30b8\u306e\uff11\u500b\u304c\u6b20\u843d\u3057\u3066\u3044\u308b\u306e\u3092\u691c\u51fa\u3057\u307e\u3057\u305f\u3002\u305d\u308c\u3089\u3092\u4eca\u304b\u3089\u691c\u7d22\u3057\u307e\u3059\u304b\uff1f\n\n\ Case.checkImgExist.confDlg.doesntExist.msg={0} \u304c\u3053\u306e\u30b1\u30fc\u30b9\u306b\u95a2\u9023\u3059\u308b\u30a4\u30e1\u30fc\u30b8\u306e\uff11\u500b\u304c\u6b20\u843d\u3057\u3066\u3044\u308b\u306e\u3092\u691c\u51fa\u3057\u307e\u3057\u305f\u3002\u305d\u308c\u3089\u3092\u4eca\u304b\u3089\u691c\u7d22\u3057\u307e\u3059\u304b\uff1f\n\n\
\u4ee5\u524d\u3001\u30a4\u30e1\u30fc\u30b8\u306f\u4e0b\u8a18\u306b\u3042\u308a\u307e\u3057\u305f\uff1a\n\ \u4ee5\u524d\u3001\u30a4\u30e1\u30fc\u30b8\u306f\u4e0b\u8a18\u306b\u3042\u308a\u307e\u3057\u305f\uff1a\n\
{1}\n\ {1}\n\

View File

@ -632,22 +632,22 @@ public class Case implements SleuthkitCase.ErrorObserver {
} catch (CaseMetadataException ex) { } catch (CaseMetadataException ex) {
/** /**
* Clean-up the case if it was actually opened. TODO: Do this * Attempt clean up.
* better.
*/ */
try { try {
Case badCase = Case.getCurrentCase(); Case badCase = Case.getCurrentCase();
badCase.closeCase(); badCase.closeCase();
} catch (IllegalStateException unused) { } catch (IllegalStateException ignored) {
// Already logged.
} }
throw new CaseActionException(NbBundle.getMessage(Case.class, "Case.open.exception.gen.msg") + ": " + ex.getMessage(), ex); //NON-NLS throw new CaseActionException(ex.getMessage(), ex); //NON-NLS
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
/**
* Attempt clean up.
*/
try { try {
Case badCase = Case.getCurrentCase(); Case badCase = Case.getCurrentCase();
badCase.closeCase(); badCase.closeCase();
} catch (CaseActionException | IllegalStateException unused) { } catch (IllegalStateException ignored) {
// Already logged.
} }
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

View File

@ -1,7 +1,7 @@
/* /*
* Autopsy Forensic Browser * Autopsy Forensic Browser
* *
* Copyright 2011-2015 Basis Technology Corp. * Copyright 2011-2016 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org * Contact: carrier <at> sleuthkit <dot> org
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -35,12 +35,13 @@ import java.awt.Cursor;
* Panel show from the splash dialog that shows recent cases and allows them to * Panel show from the splash dialog that shows recent cases and allows them to
* be opened. * be opened.
*/ */
class OpenRecentCasePanel extends javax.swing.JPanel { final class OpenRecentCasePanel extends javax.swing.JPanel {
static String[] caseNames; private static final long serialVersionUID = 1L;
static String[] casePaths;
private static final Logger logger = Logger.getLogger(OpenRecentCasePanel.class.getName());
private static OpenRecentCasePanel instance; private static OpenRecentCasePanel instance;
private static String[] caseNames;
private static String[] casePaths;
private static final Logger logger = Logger.getLogger(OpenRecentCasePanel.class.getName());
private RecentCasesTableModel model; private RecentCasesTableModel model;
private OpenRecentCasePanel() { private OpenRecentCasePanel() {
@ -77,6 +78,144 @@ class OpenRecentCasePanel extends javax.swing.JPanel {
return instance; return instance;
} }
// Open the selected case
private void openCase() {
if (casePaths.length < 1) {
logger.log(Level.INFO, "No Case paths exist, cannot open the case"); //NON-NLS
return;
}
final String casePath = casePaths[imagesTable.getSelectedRow()];
final String caseName = caseNames[imagesTable.getSelectedRow()];
if (!casePath.equals("")) {
// Close the startup menu
try {
StartupWindowProvider.getInstance().close();
CueBannerPanel.closeOpenRecentCasesWindow();
} catch (Exception ex) {
logger.log(Level.WARNING, "Error: couldn't open case: " + caseName, ex); //NON-NLS
}
// Open the recent cases
if (caseName.equals("") || casePath.equals("") || (!new File(casePath).exists())) {
JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
NbBundle.getMessage(this.getClass(),
"OpenRecentCasePanel.openCase.msgDlg.caseDoesntExist.msg",
caseName),
NbBundle.getMessage(this.getClass(),
"OpenRecentCasePanel.openCase.msgDlg.err"),
JOptionPane.ERROR_MESSAGE);
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.isCaseOpen() == false) {
StartupWindowProvider.getInstance().open();
}
} else {
SwingUtilities.invokeLater(() -> {
WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
});
new Thread(() -> {
try {
Case.open(casePath);
} catch (CaseActionException ex) {
SwingUtilities.invokeLater(() -> {
WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), ex.getMessage(),
NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"), JOptionPane.ERROR_MESSAGE); //NON-NLS
if (!Case.isCaseOpen()) {
StartupWindowProvider.getInstance().open();
}
});
}
}).start();
}
}
}
/**
* Sets the Close button action listener.
*
* @param e the action listener
*/
public void setCloseButtonActionListener(ActionListener e) {
this.cancelButton.addActionListener(e);
}
/**
* Table model to keep track of recent cases.
*/
private class RecentCasesTableModel extends AbstractTableModel {
private static final long serialVersionUID = 1L;
@Override
public int getRowCount() {
int count = 0;
for (String s : caseNames) {
if (!s.equals("")) {
count++;
}
}
return count;
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public String getColumnName(int column) {
String colName = null;
switch (column) {
case 0:
colName = NbBundle.getMessage(OpenRecentCasePanel.class, "OpenRecentCasePanel.colName.caseName");
break;
case 1:
colName = NbBundle.getMessage(OpenRecentCasePanel.class, "OpenRecentCasePanel.colName.path");
break;
default:
break;
}
return colName;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Object ret = null;
switch (columnIndex) {
case 0:
ret = caseNames[rowIndex];
break;
case 1:
ret = shortenPath(casePaths[rowIndex]);
break;
default:
logger.log(Level.SEVERE, "Invalid table column index: {0}", columnIndex); //NON-NLS
break;
}
return ret;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
}
private String shortenPath(String path) {
String shortenedPath = path;
if (shortenedPath.length() > 50) {
shortenedPath = path.substring(0, 10 + path.substring(10).indexOf(File.separator) + 1) + "..."
+ path.substring((path.length() - 20) + path.substring(path.length() - 20).indexOf(File.separator));
}
return shortenedPath;
}
}
/** /**
* This method is called from within the constructor to initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always * WARNING: Do NOT modify this code. The content of this method is always
@ -180,59 +319,6 @@ class OpenRecentCasePanel extends javax.swing.JPanel {
} }
}//GEN-LAST:event_imagesTableKeyPressed }//GEN-LAST:event_imagesTableKeyPressed
// Open the selected case
private void openCase() {
if (casePaths.length < 1) {
logger.log(Level.INFO, "No Case paths exist, cannot open the case"); //NON-NLS
return;
}
final String casePath = casePaths[imagesTable.getSelectedRow()];
final String caseName = caseNames[imagesTable.getSelectedRow()];
if (!casePath.equals("")) {
// Close the startup menu
try {
StartupWindowProvider.getInstance().close();
CueBannerPanel.closeOpenRecentCasesWindow();
} catch (Exception ex) {
logger.log(Level.WARNING, "Error: couldn't open case: " + caseName, ex); //NON-NLS
}
// Open the recent cases
if (caseName.equals("") || casePath.equals("") || (!new File(casePath).exists())) {
JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
NbBundle.getMessage(this.getClass(),
"OpenRecentCasePanel.openCase.msgDlg.caseDoesntExist.msg",
caseName),
NbBundle.getMessage(this.getClass(),
"OpenRecentCasePanel.openCase.msgDlg.err"),
JOptionPane.ERROR_MESSAGE);
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.isCaseOpen() == false) {
StartupWindowProvider.getInstance().open();
}
} else {
SwingUtilities.invokeLater(() -> {
WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
});
new Thread(() -> {
try {
Case.open(casePath);
} catch (CaseActionException ex) {
SwingUtilities.invokeLater(() -> {
WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), ex.getMessage(),
NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"), JOptionPane.ERROR_MESSAGE); //NON-NLS
if (!Case.isCaseOpen()) {
StartupWindowProvider.getInstance().open();
}
});
}
}).start();
}
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton; private javax.swing.JButton cancelButton;
private javax.swing.JTable imagesTable; private javax.swing.JTable imagesTable;
@ -241,86 +327,4 @@ class OpenRecentCasePanel extends javax.swing.JPanel {
private javax.swing.JScrollPane tableScrollPane; private javax.swing.JScrollPane tableScrollPane;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
/**
* Sets the Close button action listener.
*
* @param e the action listener
*/
public void setCloseButtonActionListener(ActionListener e) {
this.cancelButton.addActionListener(e);
}
/**
* Table model to keep track of recent cases.
*/
private class RecentCasesTableModel extends AbstractTableModel {
@Override
public int getRowCount() {
int count = 0;
for (String s : caseNames) {
if (!s.equals("")) {
count++;
}
}
return count;
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public String getColumnName(int column) {
String colName = null;
switch (column) {
case 0:
colName = NbBundle.getMessage(OpenRecentCasePanel.class, "OpenRecentCasePanel.colName.caseName");
break;
case 1:
colName = NbBundle.getMessage(OpenRecentCasePanel.class, "OpenRecentCasePanel.colName.path");
break;
default:
;
}
return colName;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Object ret = null;
switch (columnIndex) {
case 0:
ret = caseNames[rowIndex];
break;
case 1:
ret = shortenPath(casePaths[rowIndex]);
break;
default:
logger.log(Level.SEVERE, "Invalid table column index: {0}", columnIndex); //NON-NLS
break;
}
return ret;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
}
private String shortenPath(String path) {
if (path.length() > 50) {
path = path.substring(0, 10 + path.substring(10).indexOf(File.separator) + 1) + "..."
+ path.substring((path.length() - 20) + path.substring(path.length() - 20).indexOf(File.separator));
}
return path;
}
}
} }