Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
RecentItems.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2016 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.casemodule;
20 
21 import java.awt.EventQueue;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.io.File;
25 import javax.swing.JOptionPane;
26 import javax.swing.SwingUtilities;
27 import org.openide.util.NbBundle;
28 import org.openide.windows.WindowManager;
29 import java.awt.Cursor;
30 import java.util.logging.Level;
31 import org.openide.DialogDescriptor;
32 import org.openide.DialogDisplayer;
33 import org.openide.NotifyDescriptor;
36 
40 class RecentItems implements ActionListener {
41 
42  private static final Logger logger = Logger.getLogger(RecentItems.class.getName());
43  private final String caseName;
44  private final String caseMetaDataFilePath;
45 
52  public RecentItems(String caseName, String caseMetaDataFilePath) {
53  this.caseName = caseName;
54  this.caseMetaDataFilePath = caseMetaDataFilePath;
55  }
56 
62  @Override
63  public void actionPerformed(ActionEvent e) {
64  /*
65  * If ingest is running, do a dialog to warn the user and confirm the
66  * intent to close the current case and leave the ingest process
67  * incomplete.
68  */
69  if (IngestManager.getInstance().isIngestRunning()) {
70  NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(
71  NbBundle.getMessage(this.getClass(), "CloseCaseWhileIngesting.Warning"),
72  NbBundle.getMessage(this.getClass(), "CloseCaseWhileIngesting.Warning.title"),
73  NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
74  descriptor.setValue(NotifyDescriptor.NO_OPTION);
75  Object res = DialogDisplayer.getDefault().notify(descriptor);
76  if (res != null && res == DialogDescriptor.YES_OPTION) {
77  Case currentCase = null;
78  try {
79  currentCase = Case.getCurrentCase();
80  currentCase.closeCase();
81  } catch (IllegalStateException ignored) {
82  /*
83  * No current case.
84  */
85  } catch (CaseActionException ex) {
86  logger.log(Level.SEVERE, String.format("Error closing case at %s while ingest was running", (null!= currentCase ? currentCase.getCaseDirectory() : "?")),ex); //NON-NLS
87  }
88  } else {
89  return;
90  }
91  }
92 
93  /*
94  * Open the case.
95  */
96  if (caseName.equals("") || caseMetaDataFilePath.equals("") || (!new File(caseMetaDataFilePath).exists())) {
97  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
98  NbBundle.getMessage(this.getClass(), "RecentItems.openRecentCase.msgDlg.text", caseName),
99  NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"),
100  JOptionPane.ERROR_MESSAGE);
101  RecentCases.getInstance().removeRecentCase(caseName, caseMetaDataFilePath);
102  if (Case.isCaseOpen() == false) {
103  EventQueue.invokeLater(() -> {
104  StartupWindowProvider.getInstance().open();
105  });
106  }
107  } else {
108  SwingUtilities.invokeLater(() -> {
109  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
110  });
111  new Thread(() -> {
112  try {
113  Case.open(caseMetaDataFilePath);
114  } catch (CaseActionException ex) {
115  SwingUtilities.invokeLater(() -> {
116  logger.log(Level.SEVERE, String.format("Error opening case with metadata file path %s", caseMetaDataFilePath), ex); //NON-NLS
117  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
118  JOptionPane.showMessageDialog(
119  WindowManager.getDefault().getMainWindow(),
120  ex.getMessage(), // Should be user-friendly
121  NbBundle.getMessage(RecentItems.this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"), //NON-NLS
122  JOptionPane.ERROR_MESSAGE);
123  if (!Case.isCaseOpen()) {
124  StartupWindowProvider.getInstance().open();
125  }
126  });
127  }
128  }).start();
129  }
130  }
131 }
static synchronized IngestManager getInstance()

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.