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();
79 jSplitPane1.setResizeWeight(0.5);
80 jSplitPane1.setDividerLocation(0.75);
82 outline = outlineView.getOutline();
83 outlineView.setPropertyColumns(
84 "device", Bundle.AccountNode_device(),
85 "type", Bundle.AccountNode_accountType(),
86 "count", Bundle.AccountNode_messageCount()
89 outline.setRootVisible(
false);
90 ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel(Bundle.AccountNode_accountName());
91 outline.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
92 outline.setColumnSorted(3,
false, 1);
95 jSplitPane1.setRightComponent(relationshipBrowser);
97 accountsTableEM.addPropertyChangeListener(evt -> {
98 if (ExplorerManager.PROP_ROOT_CONTEXT.equals(evt.getPropertyName())) {
99 SwingUtilities.invokeLater(this::setColumnWidths);
100 }
else if (ExplorerManager.PROP_EXPLORED_CONTEXT.equals(evt.getPropertyName())) {
101 SwingUtilities.invokeLater(this::setColumnWidths);
102 }
else if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
103 final Node[] selectedNodes = accountsTableEM.getSelectedNodes();
104 final Set<AccountDeviceInstance> accountDeviceInstances =
new HashSet<>();
106 CommunicationsFilter filter = null;
107 for (
final Node node : selectedNodes) {
108 accountDeviceInstances.add(((AccountDeviceInstanceNode) node).getAccountDeviceInstance());
109 filter = ((AccountDeviceInstanceNode)node).getFilter();
115 proxyLookup =
new ProxyLookup(relationshipBrowser.
getLookup(),
116 ExplorerUtils.createLookup(accountsTableEM, getActionMap()));
123 final int rows = Math.min(100, outline.getRowCount());
125 for (
int column = 0; column < outline.getColumnCount(); column++) {
126 int columnWidthLimit = 500;
130 for (
int row = 0; row < rows; row++) {
131 TableCellRenderer renderer = outline.getCellRenderer(row, column);
132 Component comp = outline.prepareRenderer(renderer, row, column);
133 columnWidth = Math.max(comp.getPreferredSize().width, columnWidth);
136 columnWidth += 2 * margin + padding;
137 columnWidth = Math.min(columnWidth, columnWidthLimit);
139 outline.getColumnModel().getColumn(column).setPreferredWidth(columnWidth);
144 void handleFilterEvent(CVTEvents.FilterChangeEvent filterChangeEvent) {
147 accountsTableEM.setRootContext(
new AbstractNode(Children.create(
new AccountDeviceInstanceNodeFactory(commsManager, filterChangeEvent.getNewFilter()),
true)));
148 }
catch (TskCoreException ex) {
149 logger.log(Level.SEVERE,
"There was an error getting the CommunicationsManager for the current case.", ex);
150 }
catch (NoCurrentCaseException ex) {
156 void historyChange(CVTEvents.StateChangeEvent event) {
158 final CommunicationsManager commsManager = Case.getCurrentCaseThrows().getSleuthkitCase().getCommunicationsManager();
159 accountsTableEM.setRootContext(
new AbstractNode(Children.create(
new AccountDeviceInstanceNodeFactory(commsManager, event.getCommunicationsState().getCommunicationsFilter()),
true)));
160 }
catch (TskCoreException ex) {
161 logger.log(Level.SEVERE,
"There was an error getting the CommunicationsManager for the current case.", ex);
162 }
catch (NoCurrentCaseException ex) {
173 @SuppressWarnings(
"unchecked")
175 private
void initComponents() {
177 jSplitPane1 =
new javax.swing.JSplitPane();
178 outlineView =
new org.openide.explorer.view.OutlineView();
180 setLayout(
new java.awt.BorderLayout());
182 jSplitPane1.setDividerLocation(500);
183 jSplitPane1.setLeftComponent(outlineView);
185 add(jSplitPane1, java.awt.BorderLayout.CENTER);
196 return accountsTableEM;
void setSelectionInfo(SelectionInfo info)
ExplorerManager getExplorerManager()
org.openide.explorer.view.OutlineView outlineView
javax.swing.JSplitPane jSplitPane1
SleuthkitCase getSleuthkitCase()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
final ProxyLookup proxyLookup