19 package org.sleuthkit.autopsy.casemodule.datasourcesummary;
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;
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;
49 final class DataSourceBrowser
extends javax.swing.JPanel implements ExplorerManager.Provider {
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();
62 DataSourceBrowser(Map<Long, String> usageMap, Map<Long, Long> fileCountsMap) {
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();
75 outline.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
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);
89 this.setVisible(
true);
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) {
106 explorerManager.setExploredContextAndSelection(node,
new Node[]{node});
108 }
catch (PropertyVetoException ex) {
109 logger.log(Level.WARNING,
"Failed to select the datasource in the explorer view", ex);
115 if (explorerManager.getRootContext().getChildren().getNodes().length > 0) {
116 outline.getSelectionModel().setSelectionInterval(0, 0);
127 void addObserver(Observer observer) {
128 ((DataSourceSummaryNode) explorerManager.getRootContext()).addObserver(observer);
138 private List<DataSourceSummary> getDataSourceSummaryList(Map<Long, String> usageMap, Map<Long, Long> fileCountsMap) {
139 List<DataSourceSummary> summaryList =
new ArrayList<>();
141 final Map<Long, Long> artifactCountsMap = DataSourceInfoUtilities.getCountsOfArtifacts();
142 final Map<Long, Long> tagCountsMap = DataSourceInfoUtilities.getCountsOfTags();
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())));
150 logger.log(Level.WARNING,
"Unable to datasources or their counts, providing empty results", ex);
160 void addListSelectionListener(ListSelectionListener listener) {
161 outline.getSelectionModel().addListSelectionListener(listener);
169 DataSource getSelectedDataSource() {
170 Node selectedNode[] = explorerManager.getSelectedNodes();
171 if (selectedNode.length == 1 && selectedNode[0] instanceof DataSourceSummaryEntryNode) {
172 return ((DataSourceSummaryEntryNode) selectedNode[0]).getDataSource();
182 @SuppressWarnings(
"unchecked")
184 private void initComponents() {
186 setLayout(
new java.awt.BorderLayout());
190 public ExplorerManager getExplorerManager() {
191 return explorerManager;
SleuthkitCase getSleuthkitCase()
static Case getCurrentCaseThrows()