19 package org.sleuthkit.autopsy.communications;
 
   21 import com.google.common.eventbus.Subscribe;
 
   22 import java.awt.Component;
 
   23 import java.util.HashSet;
 
   25 import java.util.logging.Level;
 
   26 import javax.swing.JPanel;
 
   27 import javax.swing.ListSelectionModel;
 
   28 import javax.swing.SwingUtilities;
 
   29 import javax.swing.table.TableCellRenderer;
 
   30 import org.netbeans.swing.outline.DefaultOutlineModel;
 
   31 import org.netbeans.swing.outline.Outline;
 
   32 import org.openide.explorer.ExplorerManager;
 
   33 import org.openide.explorer.ExplorerUtils;
 
   34 import org.openide.nodes.AbstractNode;
 
   35 import org.openide.nodes.Children;
 
   36 import org.openide.nodes.Node;
 
   37 import org.openide.util.Lookup;
 
   38 import org.openide.util.lookup.ProxyLookup;
 
   58 @SuppressWarnings(
"PMD.SingularField") 
 
   59 public final class 
AccountsBrowser extends JPanel implements ExplorerManager.Provider, Lookup.Provider {
 
   61     private static final long serialVersionUID = 1L;
 
   66     private final ExplorerManager accountsTableEM = 
new ExplorerManager();
 
   77         outline = outlineView.getOutline();
 
   78         outlineView.setPropertyColumns(
 
   79                 "device", Bundle.AccountNode_device(),
 
   80                 "type", Bundle.AccountNode_accountType(),
 
   81                 "count", Bundle.AccountNode_messageCount()
 
   84         outline.setRootVisible(
false);
 
   85         ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel(Bundle.AccountNode_accountName());
 
   86         outline.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
 
   87         outline.setColumnSorted(3, 
false, 1); 
 
   89         accountsTableEM.addPropertyChangeListener(evt -> {
 
   90             if (ExplorerManager.PROP_ROOT_CONTEXT.equals(evt.getPropertyName())) {
 
   91                 SwingUtilities.invokeLater(this::setColumnWidths);
 
   92             } 
else if (ExplorerManager.PROP_EXPLORED_CONTEXT.equals(evt.getPropertyName())) {
 
   93                 SwingUtilities.invokeLater(this::setColumnWidths);
 
   94             } 
else if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
 
   95                 final Node[] selectedNodes = accountsTableEM.getSelectedNodes();
 
   96                 final Set<AccountDeviceInstance> accountDeviceInstances = 
new HashSet<>();
 
   98                 CommunicationsFilter filter = null;
 
   99                 for (
final Node node : selectedNodes) {
 
  100                     accountDeviceInstances.add(((AccountDeviceInstanceNode) node).getAccountDeviceInstance());
 
  101                     filter = ((AccountDeviceInstanceNode)node).getFilter();
 
  107         proxyLookup = 
new ProxyLookup(relationshipBrowser.
getLookup(),
 
  108                         ExplorerUtils.createLookup(accountsTableEM, getActionMap()));
 
  115         final int rows = Math.min(100, outline.getRowCount());
 
  117         for (
int column = 0; column < outline.getColumnCount(); column++) {
 
  118             int columnWidthLimit = 500;
 
  122             for (
int row = 0; row < rows; row++) {
 
  123                 TableCellRenderer renderer = outline.getCellRenderer(row, column);
 
  124                 Component comp = outline.prepareRenderer(renderer, row, column);
 
  125                 columnWidth = Math.max(comp.getPreferredSize().width, columnWidth);
 
  128             columnWidth += 2 * margin + padding; 
 
  129             columnWidth = Math.min(columnWidth, columnWidthLimit);
 
  131             outline.getColumnModel().getColumn(column).setPreferredWidth(columnWidth);
 
  136     void handleFilterEvent(CVTEvents.FilterChangeEvent filterChangeEvent) {
 
  139             accountsTableEM.setRootContext(
new AbstractNode(Children.create(
new AccountDeviceInstanceNodeFactory(commsManager, filterChangeEvent.getNewFilter()), 
true)));
 
  140         } 
catch (TskCoreException ex) {
 
  141             logger.log(Level.SEVERE, 
"There was an error getting the CommunicationsManager for the current case.", ex);
 
  142         } 
catch (NoCurrentCaseException ex) { 
 
  148     void historyChange(CVTEvents.StateChangeEvent event) {
 
  150             final CommunicationsManager commsManager = Case.getCurrentCaseThrows().getSleuthkitCase().getCommunicationsManager();
 
  151             accountsTableEM.setRootContext(
new AbstractNode(Children.create(
new AccountDeviceInstanceNodeFactory(commsManager, event.getCommunicationsState().getCommunicationsFilter()), 
true)));
 
  152         } 
catch (TskCoreException ex) {
 
  153             logger.log(Level.SEVERE, 
"There was an error getting the CommunicationsManager for the current case.", ex);
 
  154         } 
catch (NoCurrentCaseException ex) { 
 
  165     @SuppressWarnings(
"unchecked")
 
  167     private 
void initComponents() {
 
  169         outlineView = 
new org.openide.explorer.view.OutlineView();
 
  171         setLayout(
new java.awt.BorderLayout());
 
  172         add(outlineView, java.awt.BorderLayout.CENTER);
 
  182         return accountsTableEM;
 
void setSelectionInfo(SelectionInfo info)
ExplorerManager getExplorerManager()
org.openide.explorer.view.OutlineView outlineView
SleuthkitCase getSleuthkitCase()
AccountsBrowser(RelationshipBrowser relationshipBrowser)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
final ProxyLookup proxyLookup