19 package org.sleuthkit.autopsy.casemodule;
21 import java.awt.event.ActionListener;
22 import java.awt.event.KeyEvent;
24 import java.util.logging.Level;
25 import javax.swing.JOptionPane;
26 import javax.swing.JTable;
27 import javax.swing.SwingUtilities;
28 import javax.swing.table.AbstractTableModel;
29 import org.openide.util.NbBundle;
30 import org.openide.windows.WindowManager;
38 @SuppressWarnings(
"PMD.SingularField")
39 class OpenRecentCasePanel extends javax.swing.JPanel {
41 private static final long serialVersionUID = 1L;
42 private static final Logger logger = Logger.getLogger(OpenRecentCasePanel.class.getName());
43 private static OpenRecentCasePanel instance;
44 private static String[] caseNames;
45 private static String[] casePaths;
46 private RecentCasesTableModel model;
52 private OpenRecentCasePanel() {
60 static OpenRecentCasePanel getInstance() {
61 if (instance == null) {
62 instance =
new OpenRecentCasePanel();
64 instance.refreshRecentCasesTable();
73 void setCloseButtonActionListener(ActionListener listener) {
74 this.cancelButton.addActionListener(listener);
80 private void refreshRecentCasesTable() {
81 caseNames = RecentCases.getInstance().getRecentCaseNames();
82 casePaths = RecentCases.getInstance().getRecentCasePaths();
83 model =
new RecentCasesTableModel();
84 imagesTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
85 imagesTable.setModel(model);
87 int width = tableScrollPane.getPreferredSize().width;
88 imagesTable.getColumnModel().getColumn(0).setPreferredWidth((
int) (.30 * width));
89 imagesTable.getColumnModel().getColumn(1).setPreferredWidth((
int) (.70 * width));
91 if (imagesTable.getRowCount() > 0) {
92 imagesTable.setRowSelectionInterval(0, 0);
93 openButton.setEnabled(
true);
95 openButton.setEnabled(
false);
102 @NbBundle.Messages({
"# {0} - case name",
103 "RecentItems.openRecentCase.msgDlg.text=Case {0} no longer exists.",
104 "CaseOpenAction.msgDlg.cantOpenCase.title=Error Opening Case"})
105 @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
106 private void openCase() {
107 if (casePaths.length < 1) {
110 final String caseMetadataFilePath = casePaths[imagesTable.getSelectedRow()];
111 final String caseName = caseNames[imagesTable.getSelectedRow()];
112 if (!caseMetadataFilePath.isEmpty()) {
114 StartupWindowProvider.getInstance().close();
115 CueBannerPanel.closeOpenRecentCasesWindow();
116 }
catch (Exception ex) {
117 logger.log(Level.SEVERE,
"Error closing start up window", ex);
121 if (caseName.isEmpty() || caseMetadataFilePath.isEmpty() || (!
new File(caseMetadataFilePath).exists())) {
123 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
124 RecentItems_openRecentCase_msgDlg_text(caseName),
125 CaseOpenAction_msgDlg_cantOpenCase_title(),
126 JOptionPane.ERROR_MESSAGE);
127 RecentCases.getInstance().removeRecentCase(caseName, caseMetadataFilePath);
128 StartupWindowProvider.getInstance().open();
133 Case.openAsCurrentCase(caseMetadataFilePath);
134 }
catch (CaseActionException ex) {
135 SwingUtilities.invokeLater(() -> {
136 if (!(ex instanceof CaseActionCancelledException)) {
137 logger.log(Level.SEVERE, String.format(
"Error opening case with metadata file path %s", caseMetadataFilePath), ex);
139 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
140 ex.getLocalizedMessage(),
141 CaseOpenAction_msgDlg_cantOpenCase_title(),
142 JOptionPane.ERROR_MESSAGE);
144 StartupWindowProvider.getInstance().open();
157 private static final long serialVersionUID = 1L;
162 for (String s : caseNames) {
177 String colName = null;
180 colName = NbBundle.getMessage(OpenRecentCasePanel.class,
"OpenRecentCasePanel.colName.caseName");
183 colName = NbBundle.getMessage(OpenRecentCasePanel.class,
"OpenRecentCasePanel.colName.path");
194 switch (columnIndex) {
196 ret = caseNames[rowIndex];
199 ret = shortenPath(casePaths[rowIndex]);
202 logger.log(Level.SEVERE,
"Invalid table column index: {0}", columnIndex);
214 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
225 String shortenedPath = path;
226 if (shortenedPath.length() > 50) {
227 shortenedPath = path.substring(0, 10 + path.substring(10).indexOf(File.separator) + 1) +
"..."
228 + path.substring((path.length() - 20) + path.substring(path.length() - 20).indexOf(File.separator));
230 return shortenedPath;
239 @SuppressWarnings(
"unchecked")
241 private
void initComponents() {
243 jLabel1 =
new javax.swing.JLabel();
244 cancelButton =
new javax.swing.JButton();
245 openButton =
new javax.swing.JButton();
246 tableScrollPane =
new javax.swing.JScrollPane();
247 imagesTable =
new javax.swing.JTable();
249 jLabel1.setText(
org.openide.util.NbBundle.getMessage(OpenRecentCasePanel.class,
"OpenRecentCasePanel.jLabel1.text"));
251 cancelButton.setText(
org.openide.util.NbBundle.getMessage(OpenRecentCasePanel.class,
"OpenRecentCasePanel.cancelButton.text"));
253 openButton.setText(
org.openide.util.NbBundle.getMessage(OpenRecentCasePanel.class,
"OpenRecentCasePanel.openButton.text"));
254 openButton.addActionListener(
new java.awt.event.ActionListener() {
255 public void actionPerformed(java.awt.event.ActionEvent evt) {
256 openButtonActionPerformed(evt);
260 imagesTable.setModel(
new javax.swing.table.DefaultTableModel(
268 imagesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
269 imagesTable.setShowHorizontalLines(
false);
270 imagesTable.setShowVerticalLines(
false);
271 imagesTable.getTableHeader().setReorderingAllowed(
false);
272 imagesTable.setUpdateSelectionOnSort(
false);
273 imagesTable.addMouseListener(
new java.awt.event.MouseAdapter() {
274 public void mouseClicked(java.awt.event.MouseEvent evt) {
275 imagesTableMouseClicked(evt);
278 imagesTable.addKeyListener(
new java.awt.event.KeyAdapter() {
279 public void keyPressed(java.awt.event.KeyEvent evt) {
280 imagesTableKeyPressed(evt);
283 tableScrollPane.setViewportView(imagesTable);
285 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
286 this.setLayout(layout);
287 layout.setHorizontalGroup(
288 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
289 .addGroup(layout.createSequentialGroup()
291 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
292 .addGroup(layout.createSequentialGroup()
293 .addComponent(jLabel1)
294 .addGap(292, 414, Short.MAX_VALUE))
295 .addGroup(layout.createSequentialGroup()
296 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
297 .addComponent(tableScrollPane)
298 .addGroup(layout.createSequentialGroup()
299 .addGap(0, 0, Short.MAX_VALUE)
300 .addComponent(openButton)
301 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
302 .addComponent(cancelButton)))
303 .addContainerGap())))
305 layout.setVerticalGroup(
306 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
307 .addGroup(layout.createSequentialGroup()
309 .addComponent(jLabel1)
310 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
311 .addComponent(tableScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
312 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
313 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
314 .addComponent(cancelButton)
315 .addComponent(openButton))
320 private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {
324 private void imagesTableMouseClicked(java.awt.event.MouseEvent evt) {
326 if (evt.getClickCount() == 2) {
331 private void imagesTableKeyPressed(java.awt.event.KeyEvent evt) {
332 if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
338 private javax.swing.JButton cancelButton;
339 private javax.swing.JTable imagesTable;
340 private javax.swing.JLabel jLabel1;
341 private javax.swing.JButton openButton;
342 private javax.swing.JScrollPane tableScrollPane;
String getColumnName(int column)
String shortenPath(String path)
Object getValueAt(int rowIndex, int columnIndex)
boolean isCellEditable(int rowIndex, int columnIndex)
void setValueAt(Object aValue, int rowIndex, int columnIndex)