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

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.