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;
 
   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;
 
   51 final class DataSourceBrowser 
extends javax.swing.JPanel implements ExplorerManager.Provider {
 
   53     private static final long serialVersionUID = 1L;
 
   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();
 
   68     DataSourceBrowser(Map<Long, String> usageMap, Map<Long, Long> fileCountsMap) {
 
   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();
 
   82         outline.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 
   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);
 
  100                 column.setPreferredWidth(DATA_SOURCE_COLUMN_WIDTH);
 
  103         this.setVisible(
true);
 
  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) {
 
  120                             explorerManager.setExploredContextAndSelection(node, 
new Node[]{node});
 
  122                         } 
catch (PropertyVetoException ex) {
 
  123                             logger.log(Level.WARNING, 
"Failed to select the datasource in the explorer view", ex); 
 
  129             if (explorerManager.getRootContext().getChildren().getNodes().length > 0) {
 
  130                 outline.getSelectionModel().setSelectionInterval(0, 0);
 
  141     void addObserver(Observer observer) {
 
  142         ((DataSourceSummaryNode) explorerManager.getRootContext()).addObserver(observer);
 
  152     private List<DataSourceSummary> getDataSourceSummaryList(Map<Long, String> usageMap, Map<Long, Long> fileCountsMap) {
 
  153         List<DataSourceSummary> summaryList = 
new ArrayList<>();
 
  155         final Map<Long, Long> artifactCountsMap = DataSourceInfoUtilities.getCountsOfArtifacts();
 
  156         final Map<Long, Long> tagCountsMap = DataSourceInfoUtilities.getCountsOfTags();
 
  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())));
 
  164             logger.log(Level.WARNING, 
"Unable to datasources or their counts, providing empty results", ex);
 
  174     void addListSelectionListener(ListSelectionListener listener) {
 
  175         outline.getSelectionModel().addListSelectionListener(listener);
 
  183     DataSource getSelectedDataSource() {
 
  184         Node selectedNode[] = explorerManager.getSelectedNodes();
 
  185         if (selectedNode.length == 1 && selectedNode[0] instanceof DataSourceSummaryEntryNode) {
 
  186             return ((DataSourceSummaryEntryNode) selectedNode[0]).getDataSource();
 
  198     void refresh(
long dataSourceId, IngestJobInfo.IngestJobStatusType newStatus) {
 
  201         for (DataSourceSummary summary : dataSourceSummaryList) {
 
  202             if (summary.getDataSource().getId() == dataSourceId) {
 
  203                 summary.setIngestStatus(newStatus);
 
  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) {
 
  214                     for (Node selectedNode : selectedNodes) {
 
  215                         if (((DataSourceSummaryEntryNode) node).getDataSource().equals(((DataSourceSummaryEntryNode) selectedNode).getDataSource())) {
 
  216                             nodesToSelect.add(node);
 
  223                 explorerManager.setSelectedNodes(nodesToSelect.toArray(
new Node[nodesToSelect.size()]));
 
  224             } 
catch (PropertyVetoException ex) {
 
  225                 logger.log(Level.WARNING, 
"Error selecting previously selected nodes", ex);
 
  237     @SuppressWarnings(
"unchecked")
 
  239     private void initComponents() {
 
  241         setLayout(
new java.awt.BorderLayout());
 
  245     public ExplorerManager getExplorerManager() {
 
  246         return explorerManager;
 
SleuthkitCase getSleuthkitCase()
 
synchronized static Logger getLogger(String name)
 
static Case getCurrentCaseThrows()