Autopsy  4.10.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.table.TableColumn;
41 import org.sleuthkit.datamodel.DataSource;
42 import org.sleuthkit.datamodel.SleuthkitCase;
43 import org.sleuthkit.datamodel.TskCoreException;
44 
49 final class DataSourceBrowser extends javax.swing.JPanel implements ExplorerManager.Provider {
50 
51  private static final long serialVersionUID = 1L;
52  private static final Logger logger = Logger.getLogger(DataSourceBrowser.class.getName());
53  private final Outline outline;
54  private final org.openide.explorer.view.OutlineView outlineView;
55  private final ExplorerManager explorerManager;
56  private final List<DataSourceSummary> dataSourceSummaryList;
57  private final RightAlignedTableCellRenderer rightAlignedRenderer = new RightAlignedTableCellRenderer();
58 
62  DataSourceBrowser(Map<Long, String> usageMap, Map<Long, Long> fileCountsMap) {
63  initComponents();
64  rightAlignedRenderer.setHorizontalAlignment(RIGHT);
65  explorerManager = new ExplorerManager();
66  outlineView = new org.openide.explorer.view.OutlineView();
67  this.setVisible(true);
68  outlineView.setPropertyColumns(
69  Bundle.DataSourceSummaryNode_column_type_header(), Bundle.DataSourceSummaryNode_column_type_header(),
70  Bundle.DataSourceSummaryNode_column_files_header(), Bundle.DataSourceSummaryNode_column_files_header(),
71  Bundle.DataSourceSummaryNode_column_results_header(), Bundle.DataSourceSummaryNode_column_results_header(),
72  Bundle.DataSourceSummaryNode_column_tags_header(), Bundle.DataSourceSummaryNode_column_tags_header());
73  outline = outlineView.getOutline();
74 
75  outline.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
76 
77  dataSourceSummaryList = getDataSourceSummaryList(usageMap, fileCountsMap);
78  outline.setRootVisible(false);
79  add(outlineView, java.awt.BorderLayout.CENTER);
80  explorerManager.setRootContext(new DataSourceSummaryNode(dataSourceSummaryList));
81  ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel(Bundle.DataSourceSummaryNode_column_dataSourceName_header());
82  for (TableColumn column : Collections.list(outline.getColumnModel().getColumns())) {
83  if (column.getHeaderValue().toString().equals(Bundle.DataSourceSummaryNode_column_files_header())
84  || column.getHeaderValue().toString().equals(Bundle.DataSourceSummaryNode_column_results_header())
85  || column.getHeaderValue().toString().equals(Bundle.DataSourceSummaryNode_column_tags_header())) {
86  column.setCellRenderer(rightAlignedRenderer);
87  }
88  }
89  this.setVisible(true);
90  }
91 
100  void selectDataSource(Long dataSourceId) {
101  EventQueue.invokeLater(() -> {
102  if (dataSourceId != null) {
103  for (Node node : explorerManager.getRootContext().getChildren().getNodes()) {
104  if (node instanceof DataSourceSummaryEntryNode && ((DataSourceSummaryEntryNode) node).getDataSource().getId() == dataSourceId) {
105  try {
106  explorerManager.setExploredContextAndSelection(node, new Node[]{node});
107  return;
108  } catch (PropertyVetoException ex) {
109  logger.log(Level.WARNING, "Failed to select the datasource in the explorer view", ex); //NON-NLS
110  }
111  }
112  }
113  }
114  //if no data source was selected and there are data sources to select select the first one
115  if (explorerManager.getRootContext().getChildren().getNodes().length > 0) {
116  outline.getSelectionModel().setSelectionInterval(0, 0);
117  }
118  });
119  }
120 
127  void addObserver(Observer observer) {
128  ((DataSourceSummaryNode) explorerManager.getRootContext()).addObserver(observer);
129  }
130 
138  private List<DataSourceSummary> getDataSourceSummaryList(Map<Long, String> usageMap, Map<Long, Long> fileCountsMap) {
139  List<DataSourceSummary> summaryList = new ArrayList<>();
140 
141  final Map<Long, Long> artifactCountsMap = DataSourceInfoUtilities.getCountsOfArtifacts();
142  final Map<Long, Long> tagCountsMap = DataSourceInfoUtilities.getCountsOfTags();
143  try {
144  SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
145  for (DataSource dataSource : skCase.getDataSources()) {
146  summaryList.add(new DataSourceSummary(dataSource, usageMap.get(dataSource.getId()),
147  fileCountsMap.get(dataSource.getId()), artifactCountsMap.get(dataSource.getId()), tagCountsMap.get(dataSource.getId())));
148  }
149  } catch (TskCoreException | NoCurrentCaseException ex) {
150  logger.log(Level.WARNING, "Unable to datasources or their counts, providing empty results", ex);
151  }
152  return summaryList;
153  }
154 
160  void addListSelectionListener(ListSelectionListener listener) {
161  outline.getSelectionModel().addListSelectionListener(listener);
162  }
163 
169  DataSource getSelectedDataSource() {
170  Node selectedNode[] = explorerManager.getSelectedNodes();
171  if (selectedNode.length == 1 && selectedNode[0] instanceof DataSourceSummaryEntryNode) {
172  return ((DataSourceSummaryEntryNode) selectedNode[0]).getDataSource();
173  }
174  return null;
175  }
176 
182  @SuppressWarnings("unchecked")
183  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
184  private void initComponents() {
185 
186  setLayout(new java.awt.BorderLayout());
187  }// </editor-fold>//GEN-END:initComponents
188 
189  @Override
190  public ExplorerManager getExplorerManager() {
191  return explorerManager;
192  }
193 
194  // Variables declaration - do not modify//GEN-BEGIN:variables
195  // End of variables declaration//GEN-END:variables
196 }

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