Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourceBrowser.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019 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.datasourcesummary.ui;
20 
22 import java.awt.EventQueue;
23 import java.beans.PropertyVetoException;
24 import javax.swing.ListSelectionModel;
25 import org.netbeans.swing.outline.DefaultOutlineModel;
26 import org.netbeans.swing.outline.Outline;
27 import org.openide.explorer.ExplorerManager;
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.Observer;
33 import java.util.logging.Level;
35 import javax.swing.event.ListSelectionListener;
36 import org.openide.nodes.Node;
40 import static javax.swing.SwingConstants.RIGHT;
41 import javax.swing.SwingUtilities;
42 import javax.swing.table.TableColumn;
44 import org.sleuthkit.datamodel.DataSource;
45 import org.sleuthkit.datamodel.IngestJobInfo;
46 import org.sleuthkit.datamodel.SleuthkitCase;
47 import org.sleuthkit.datamodel.TskCoreException;
48 
53 final class DataSourceBrowser extends javax.swing.JPanel implements ExplorerManager.Provider {
54 
55  private static final long serialVersionUID = 1L;
56  private static final Logger logger = Logger.getLogger(DataSourceBrowser.class.getName());
57  private static final int COUNT_COLUMN_WIDTH = 20;
58  private static final int INGEST_STATUS_WIDTH = 50;
59  private static final int USAGE_COLUMN_WIDTH = 110;
60  private static final int DATA_SOURCE_COLUMN_WIDTH = 280;
61  private final Outline outline;
62  private final org.openide.explorer.view.OutlineView outlineView;
63  private final ExplorerManager explorerManager;
64  private final List<DataSourceSummary> dataSourceSummaryList;
65  private final RightAlignedTableCellRenderer rightAlignedRenderer = new RightAlignedTableCellRenderer();
66 
70  DataSourceBrowser(Map<Long, String> usageMap, Map<Long, Long> fileCountsMap) {
71  initComponents();
72  rightAlignedRenderer.setHorizontalAlignment(RIGHT);
73  explorerManager = new ExplorerManager();
74  outlineView = new org.openide.explorer.view.OutlineView();
75  this.setVisible(true);
76  outlineView.setPropertyColumns(
77  Bundle.DataSourceSummaryNode_column_status_header(), Bundle.DataSourceSummaryNode_column_status_header(),
78  Bundle.DataSourceSummaryNode_column_type_header(), Bundle.DataSourceSummaryNode_column_type_header(),
79  Bundle.DataSourceSummaryNode_column_files_header(), Bundle.DataSourceSummaryNode_column_files_header(),
80  Bundle.DataSourceSummaryNode_column_results_header(), Bundle.DataSourceSummaryNode_column_results_header(),
81  Bundle.DataSourceSummaryNode_column_tags_header(), Bundle.DataSourceSummaryNode_column_tags_header());
82  outline = outlineView.getOutline();
83 
84  outline.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
85 
86  dataSourceSummaryList = getDataSourceSummaryList(usageMap, fileCountsMap);
87  outline.setRootVisible(false);
88  add(outlineView, java.awt.BorderLayout.CENTER);
89  explorerManager.setRootContext(new DataSourceSummaryNode(dataSourceSummaryList));
90  ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel(Bundle.DataSourceSummaryNode_column_dataSourceName_header());
91  for (TableColumn column : Collections.list(outline.getColumnModel().getColumns())) {
92  if (column.getHeaderValue().toString().equals(Bundle.DataSourceSummaryNode_column_files_header())
93  || column.getHeaderValue().toString().equals(Bundle.DataSourceSummaryNode_column_results_header())
94  || column.getHeaderValue().toString().equals(Bundle.DataSourceSummaryNode_column_tags_header())) {
95  column.setCellRenderer(rightAlignedRenderer);
96  column.setPreferredWidth(COUNT_COLUMN_WIDTH);
97  } else if (column.getHeaderValue().toString().equals(Bundle.DataSourceSummaryNode_column_type_header())) {
98  column.setPreferredWidth(USAGE_COLUMN_WIDTH);
99  } else if (column.getHeaderValue().toString().equals(Bundle.DataSourceSummaryNode_column_status_header())) {
100  column.setPreferredWidth(INGEST_STATUS_WIDTH);
101  } else {
102  column.setPreferredWidth(DATA_SOURCE_COLUMN_WIDTH);
103  }
104  }
105  this.setVisible(true);
106  }
107 
116  void selectDataSource(Long dataSourceId) {
117  EventQueue.invokeLater(() -> {
118  if (dataSourceId != null) {
119  for (Node node : explorerManager.getRootContext().getChildren().getNodes()) {
120  if (node instanceof DataSourceSummaryEntryNode && ((DataSourceSummaryEntryNode) node).getDataSource().getId() == dataSourceId) {
121  try {
122  explorerManager.setExploredContextAndSelection(node, new Node[]{node});
123  return;
124  } catch (PropertyVetoException ex) {
125  logger.log(Level.WARNING, "Failed to select the datasource in the explorer view", ex); //NON-NLS
126  }
127  }
128  }
129  }
130  //if no data source was selected and there are data sources to select select the first one
131  if (explorerManager.getRootContext().getChildren().getNodes().length > 0) {
132  outline.getSelectionModel().setSelectionInterval(0, 0);
133  }
134  });
135  }
136 
143  void addObserver(Observer observer) {
144  ((DataSourceSummaryNode) explorerManager.getRootContext()).addObserver(observer);
145  }
146 
154  private List<DataSourceSummary> getDataSourceSummaryList(Map<Long, String> usageMap, Map<Long, Long> fileCountsMap) {
155  List<DataSourceSummary> summaryList = new ArrayList<>();
156 
157  final Map<Long, Long> artifactCountsMap = CaseDataSourcesSummary.getCountsOfArtifacts();
158  final Map<Long, Long> tagCountsMap = CaseDataSourcesSummary.getCountsOfTags();
159  try {
160  SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
161  for (DataSource dataSource : skCase.getDataSources()) {
162  summaryList.add(new DataSourceSummary(dataSource, usageMap.get(dataSource.getId()),
163  fileCountsMap.get(dataSource.getId()), artifactCountsMap.get(dataSource.getId()), tagCountsMap.get(dataSource.getId())));
164  }
165  } catch (TskCoreException | NoCurrentCaseException ex) {
166  logger.log(Level.WARNING, "Unable to datasources or their counts, providing empty results", ex);
167  }
168  return summaryList;
169  }
170 
176  void addListSelectionListener(ListSelectionListener listener) {
177  outline.getSelectionModel().addListSelectionListener(listener);
178  }
179 
185  DataSource getSelectedDataSource() {
186  Node selectedNode[] = explorerManager.getSelectedNodes();
187  if (selectedNode.length == 1 && selectedNode[0] instanceof DataSourceSummaryEntryNode) {
188  return ((DataSourceSummaryEntryNode) selectedNode[0]).getDataSource();
189  }
190  return null;
191  }
192 
200  void refresh(long dataSourceId, IngestJobInfo.IngestJobStatusType newStatus) {
201 
202  //attempt to update the status of any datasources that had status which was STARTED
203  for (DataSourceSummary summary : dataSourceSummaryList) {
204  if (summary.getDataSource().getId() == dataSourceId) {
205  summary.setIngestStatus(newStatus);
206  }
207  }
208  //figure out which nodes were previously selected
209  Node[] selectedNodes = explorerManager.getSelectedNodes();
210  SwingUtilities.invokeLater(() -> {
211  explorerManager.setRootContext(new DataSourceSummaryNode(dataSourceSummaryList));
212  List<Node> nodesToSelect = new ArrayList<>();
213  for (Node node : explorerManager.getRootContext().getChildren().getNodes()) {
214  if (node instanceof DataSourceSummaryEntryNode) {
215  //there should only be one selected node as multi-select is disabled
216  for (Node selectedNode : selectedNodes) {
217  if (((DataSourceSummaryEntryNode) node).getDataSource().equals(((DataSourceSummaryEntryNode) selectedNode).getDataSource())) {
218  nodesToSelect.add(node);
219  }
220  }
221  }
222  }
223  //reselect the previously selected Nodes
224  try {
225  explorerManager.setSelectedNodes(nodesToSelect.toArray(new Node[nodesToSelect.size()]));
226  } catch (PropertyVetoException ex) {
227  logger.log(Level.WARNING, "Error selecting previously selected nodes", ex);
228  }
229 
230  });
231 
232  }
233 
239  @SuppressWarnings("unchecked")
240  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
241  private void initComponents() {
242 
243  setLayout(new java.awt.BorderLayout());
244  }// </editor-fold>//GEN-END:initComponents
245 
246  @Override
247  public ExplorerManager getExplorerManager() {
248  return explorerManager;
249  }
250 
251  // Variables declaration - do not modify//GEN-BEGIN:variables
252  // End of variables declaration//GEN-END:variables
253 }

Copyright © 2012-2020 Basis Technology. Generated on: Tue Sep 22 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.