Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ContactsViewer.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 obt ain 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.communications.relationships;
20 
21 import java.awt.Component;
22 import java.awt.KeyboardFocusManager;
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
25 import javax.swing.JPanel;
26 import static javax.swing.SwingUtilities.isDescendingFrom;
27 import org.netbeans.swing.outline.DefaultOutlineModel;
28 import org.netbeans.swing.outline.Outline;
29 import org.openide.explorer.ExplorerManager;
30 import static org.openide.explorer.ExplorerUtils.createLookup;
31 import org.openide.nodes.AbstractNode;
32 import org.openide.nodes.Children;
33 import org.openide.nodes.Node;
34 import org.openide.nodes.NodeAdapter;
35 import org.openide.nodes.NodeMemberEvent;
36 import org.openide.util.Lookup;
37 import org.openide.util.NbBundle;
38 import org.openide.util.lookup.ServiceProvider;
42 import org.sleuthkit.datamodel.BlackboardAttribute;
43 
48 final class ContactsViewer extends JPanel implements RelationshipsViewer {
49 
50  private static final long serialVersionUID = 1L;
51 
52  private final Outline outline;
53  private final ModifiableProxyLookup proxyLookup;
54  private PropertyChangeListener focusPropertyListener;
55  private final ContactsChildNodeFactory nodeFactory;
56  private final ContactDataViewer contactPane;
57 
58  @NbBundle.Messages({
59  "ContactsViewer_tabTitle=Contacts",
60  "ContactsViewer_columnHeader_Name=Name",
61  "ContactsViewer_columnHeader_Phone=Phone",
62  "ContactsViewer_columnHeader_Email=Email",
63  "ContactsViewer_noContacts_message=<No contacts found for selected account>"
64  })
65 
69  ContactsViewer() {
70  initComponents();
71 
72  contactPane = new ContactDataViewer();
73  splitPane.setRightComponent(contactPane);
74 
75  outlineViewPanel.hideOutlineView(Bundle.ContactsViewer_noContacts_message());
76 
77  proxyLookup = new ModifiableProxyLookup(createLookup(outlineViewPanel.getExplorerManager(), getActionMap()));
78  nodeFactory = new ContactsChildNodeFactory(null);
79 
80  outline = outlineViewPanel.getOutlineView().getOutline();
81  outlineViewPanel.getOutlineView().setPropertyColumns(
82  "TSK_EMAIL", BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL.getDisplayName(),
83  "TSK_PHONE_NUMBER", BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER.getDisplayName()
84  );
85  outline.setRootVisible(false);
86  ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel(Bundle.ContactsViewer_columnHeader_Name());
87 
88  outlineViewPanel.hideOutlineView("<No contacts for selected account>");
89 
90  outlineViewPanel.getExplorerManager().addPropertyChangeListener((PropertyChangeEvent evt) -> {
91  if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
92  final Node[] nodes = outlineViewPanel.getExplorerManager().getSelectedNodes();
93  contactPane.setNode(nodes != null && nodes.length > 0 ? nodes[0] : null);
94  }
95  });
96 
97  outlineViewPanel.getExplorerManager().setRootContext(new TableFilterNode(new DataResultFilterNode(new AbstractNode(Children.create(nodeFactory, true)), outlineViewPanel.getExplorerManager()), true));
98 
99  // When a new set of nodes are added to the OutlineView the childrenAdded
100  // seems to be fired before the childrenRemoved.
101  outlineViewPanel.getExplorerManager().getRootContext().addNodeListener(new NodeAdapter() {
102  @Override
103  public void childrenAdded(NodeMemberEvent nme) {
104  updateOutlineViewPanel();
105  }
106 
107  @Override
108  public void childrenRemoved(NodeMemberEvent nme) {
109  updateOutlineViewPanel();
110  }
111  });
112 
113  splitPane.setResizeWeight(0.5);
114  splitPane.setDividerLocation(0.5);
115  }
116 
117  @Override
118  public String getDisplayName() {
119  return Bundle.ContactsViewer_tabTitle();
120  }
121 
122  @Override
123  public JPanel getPanel() {
124  return this;
125  }
126 
127  @Override
128  public void setSelectionInfo(SelectionInfo info) {
129  nodeFactory.refresh(info);
130  }
131 
132  @Override
133  public Lookup getLookup() {
134  return proxyLookup;
135  }
136 
137  @Override
138  public void addNotify() {
139  super.addNotify();
140 
141  if (focusPropertyListener == null) {
142  // See org.sleuthkit.autopsy.timeline.TimeLineTopComponent for a detailed
143  // explaination of focusPropertyListener
144  focusPropertyListener = (final PropertyChangeEvent focusEvent) -> {
145  if (focusEvent.getPropertyName().equalsIgnoreCase("focusOwner")) {
146  handleFocusChange((Component) focusEvent.getNewValue());
147  }
148  };
149  }
150 
151  //add listener that maintains correct selection in the Global Actions Context
152  KeyboardFocusManager.getCurrentKeyboardFocusManager()
153  .addPropertyChangeListener("focusOwner", focusPropertyListener); //NON-NLS
154  }
155 
161  private void handleFocusChange(Component newFocusOwner) {
162  if (newFocusOwner == null) {
163  return;
164  }
165  if (isDescendingFrom(newFocusOwner, contactPane)) {
166  //if the focus owner is within the MessageContentViewer (the attachments table)
167  proxyLookup.setNewLookups(createLookup(contactPane.getExplorerManager(), getActionMap()));
168  } else if (isDescendingFrom(newFocusOwner, this)) {
169  //... or if it is within the Results table.
170  proxyLookup.setNewLookups(createLookup(outlineViewPanel.getExplorerManager(), getActionMap()));
171 
172  }
173  }
174 
175  @Override
176  public void removeNotify() {
177  super.removeNotify();
178  if (focusPropertyListener != null) {
179  KeyboardFocusManager.getCurrentKeyboardFocusManager()
180  .removePropertyChangeListener("focusOwner", focusPropertyListener); //NON-NLS
181  }
182  }
183 
184  private void updateOutlineViewPanel() {
185  int nodeCount = outlineViewPanel.getExplorerManager().getRootContext().getChildren().getNodesCount();
186  if (nodeCount == 0) {
187  outlineViewPanel.hideOutlineView(Bundle.ContactsViewer_noContacts_message());
188  } else {
189  outlineViewPanel.showOutlineView();
190  }
191  }
192 
198  @SuppressWarnings("unchecked")
199  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
200  private void initComponents() {
201  java.awt.GridBagConstraints gridBagConstraints;
202 
203  splitPane = new javax.swing.JSplitPane();
205 
206  setLayout(new java.awt.GridBagLayout());
207 
208  splitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
209  splitPane.setLeftComponent(outlineViewPanel);
210 
211  gridBagConstraints = new java.awt.GridBagConstraints();
212  gridBagConstraints.gridx = 0;
213  gridBagConstraints.gridy = 0;
214  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
215  gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
216  gridBagConstraints.weightx = 1.0;
217  gridBagConstraints.weighty = 1.0;
218  add(splitPane, gridBagConstraints);
219  }// </editor-fold>//GEN-END:initComponents
220 
221 
222  // Variables declaration - do not modify//GEN-BEGIN:variables
224  private javax.swing.JSplitPane splitPane;
225  // End of variables declaration//GEN-END:variables
226 }

Copyright © 2012-2021 Basis Technology. Generated on: Tue Jan 19 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.