19 package org.sleuthkit.autopsy.casemodule;
21 import java.lang.reflect.InvocationTargetException;
22 import javax.swing.ListSelectionModel;
23 import javax.swing.event.ListSelectionListener;
24 import javax.swing.table.TableColumnModel;
25 import org.netbeans.swing.etable.ETableColumn;
26 import org.netbeans.swing.etable.ETableColumnModel;
27 import org.netbeans.swing.outline.DefaultOutlineModel;
28 import org.netbeans.swing.outline.Outline;
29 import org.openide.nodes.Node;
30 import java.awt.EventQueue;
32 import java.io.IOException;
33 import java.nio.file.LinkOption;
34 import java.nio.file.Path;
35 import java.nio.file.Paths;
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.logging.Level;
39 import javax.swing.SwingWorker;
40 import org.openide.explorer.ExplorerManager;
41 import org.openide.util.NbBundle;
53 @SuppressWarnings(
"PMD.SingularField")
54 class CaseBrowser extends javax.swing.JPanel implements ExplorerManager.Provider {
56 private static final long serialVersionUID = 1L;
57 private final Outline outline;
58 private ExplorerManager em;
59 private final org.openide.explorer.view.OutlineView outlineView;
60 private int originalPathColumnIndex = 0;
61 private static final Logger LOGGER = Logger.getLogger(CaseBrowser.class.getName());
62 private LoadCaseListWorker tableWorker;
65 public ExplorerManager getExplorerManager() {
73 outlineView =
new org.openide.explorer.view.OutlineView();
76 outline = outlineView.getOutline();
77 outlineView.setPropertyColumns(
78 Bundle.CaseNode_column_createdTime(), Bundle.CaseNode_column_createdTime(),
79 Bundle.CaseNode_column_metadataFilePath(), Bundle.CaseNode_column_metadataFilePath());
80 ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel(Bundle.CaseNode_column_name());
88 private void customize() {
89 outline.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
90 TableColumnModel columnModel = outline.getColumnModel();
91 int dateColumnIndex = 0;
92 for (
int index = 0; index < columnModel.getColumnCount(); index++) {
94 if (columnModel.getColumn(index).getHeaderValue().toString().equals(Bundle.CaseNode_column_metadataFilePath())) {
95 originalPathColumnIndex = index;
96 }
else if (columnModel.getColumn(index).getHeaderValue().toString().equals(Bundle.CaseNode_column_createdTime())) {
97 dateColumnIndex = index;
101 ETableColumn column = (ETableColumn) columnModel.getColumn(originalPathColumnIndex);
102 ((ETableColumnModel) columnModel).setColumnHidden(column,
true);
103 outline.setRootVisible(
false);
106 outline.setColumnSorted(dateColumnIndex,
false, 1);
108 em =
new ExplorerManager();
110 caseTableScrollPane.setViewportView(outlineView);
111 this.setVisible(
true);
112 outline.setRowSelectionAllowed(
false);
120 void addListSelectionListener(ListSelectionListener listener) {
121 outline.getSelectionModel().addListSelectionListener(listener);
129 String getCasePath() {
130 int[] selectedRows = outline.getSelectedRows();
131 if (selectedRows.length == 1) {
133 return ((Node.Property) outline.getModel().getValueAt(outline.convertRowIndexToModel(selectedRows[0]), originalPathColumnIndex)).getValue().toString();
134 }
catch (IllegalAccessException | InvocationTargetException ex) {
135 LOGGER.log(Level.SEVERE,
"Unable to get case path from table.", ex);
146 boolean isRowSelected() {
147 return outline.getRowSelectionAllowed() && outline.getSelectedRows().length > 0;
150 @NbBundle.Messages({
"CaseBrowser.caseListLoading.message=Please Wait..."})
156 if (tableWorker == null || tableWorker.isDone()) {
157 outline.setRowSelectionAllowed(
false);
160 EmptyNode emptyNode =
new EmptyNode(Bundle.CaseBrowser_caseListLoading_message());
161 em.setRootContext(emptyNode);
162 tableWorker =
new LoadCaseListWorker();
163 tableWorker.execute();
173 @SuppressWarnings(
"unchecked")
175 private
void initComponents() {
177 caseTableScrollPane =
new javax.swing.JScrollPane();
179 setMinimumSize(
new java.awt.Dimension(0, 5));
180 setPreferredSize(
new java.awt.Dimension(5, 5));
181 setLayout(
new java.awt.BorderLayout());
183 caseTableScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
184 caseTableScrollPane.setMinimumSize(
new java.awt.Dimension(0, 5));
185 caseTableScrollPane.setOpaque(
false);
186 caseTableScrollPane.setPreferredSize(
new java.awt.Dimension(5, 5));
187 add(caseTableScrollPane, java.awt.BorderLayout.CENTER);
190 private javax.swing.JScrollPane caseTableScrollPane;
208 List<CaseMetadata> caseList =
new ArrayList<>();
211 for (String node : nodeList) {
214 casePath = Paths.get(node).toRealPath(LinkOption.NOFOLLOW_LINKS);
216 File caseFolder = casePath.toFile();
217 if (caseFolder.exists()) {
221 File[] fileArray = caseFolder.listFiles();
222 if (fileArray == null) {
225 String autFilePath = null;
226 for (File file : fileArray) {
227 String name = file.getName().toLowerCase();
228 if (autFilePath == null && name.endsWith(
".aut")) {
230 caseList.add(
new CaseMetadata(Paths.get(file.getAbsolutePath())));
232 LOGGER.log(Level.SEVERE, String.format(
"Error reading case metadata file '%s'.", autFilePath), ex);
238 }
catch (IOException ignore) {
251 LOGGER.log(Level.SEVERE,
"Unexpected exception while refreshing the table.", ex);
258 EventQueue.invokeLater(() -> {
259 MultiUserNode caseListNode =
new MultiUserNode(cases);
260 em.setRootContext(caseListNode);
261 outline.setRowSelectionAllowed(
true);
List< CaseMetadata > cases
List< CaseMetadata > getCases()
static synchronized CoordinationService getInstance()
List< String > getNodeList(CategoryNode category)