Autopsy  4.19.1
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-2021 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;
41 import org.sleuthkit.datamodel.BlackboardAttribute;
42 
47 final class ContactsViewer extends JPanel implements RelationshipsViewer {
48 
49  private static final long serialVersionUID = 1L;
50 
51  private final Outline outline;
52  private final ModifiableProxyLookup proxyLookup;
53  private PropertyChangeListener focusPropertyListener;
54  private final ContactsChildNodeFactory nodeFactory;
55  private final ContactDataViewer contactPane;
56 
57  @NbBundle.Messages({
58  "ContactsViewer_tabTitle=Contacts",
59  "ContactsViewer_columnHeader_Name=Name",
60  "ContactsViewer_columnHeader_Phone=Phone",
61  "ContactsViewer_columnHeader_Email=Email",
62  "ContactsViewer_noContacts_message=<No contacts found for selected account>"
63  })
64 
68  ContactsViewer() {
69  initComponents();
70 
71  contactPane = new ContactDataViewer();
72  splitPane.setRightComponent(contactPane);
73 
74  outlineViewPanel.hideOutlineView(Bundle.ContactsViewer_noContacts_message());
75 
76  proxyLookup = new ModifiableProxyLookup(createLookup(outlineViewPanel.getExplorerManager(), getActionMap()));
77  nodeFactory = new ContactsChildNodeFactory(null);
78 
79  outline = outlineViewPanel.getOutlineView().getOutline();
80  outlineViewPanel.getOutlineView().setPropertyColumns(
81  "TSK_EMAIL", BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL.getDisplayName(),
82  "TSK_PHONE_NUMBER", BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER.getDisplayName()
83  );
84  outline.setRootVisible(false);
85  ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel(Bundle.ContactsViewer_columnHeader_Name());
86 
87  outlineViewPanel.hideOutlineView("<No contacts for selected account>");
88 
89  outlineViewPanel.getExplorerManager().addPropertyChangeListener((PropertyChangeEvent evt) -> {
90  if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
91  final Node[] nodes = outlineViewPanel.getExplorerManager().getSelectedNodes();
92  contactPane.setNode(nodes != null && nodes.length > 0 ? nodes[0] : null);
93  }
94  });
95 
96  outlineViewPanel.getExplorerManager().setRootContext(new TableFilterNode(new DataResultFilterNode(new AbstractNode(Children.create(nodeFactory, true)), outlineViewPanel.getExplorerManager()), true));
97 
98  // When a new set of nodes are added to the OutlineView the childrenAdded
99  // seems to be fired before the childrenRemoved.
100  outlineViewPanel.getExplorerManager().getRootContext().addNodeListener(new NodeAdapter() {
101  @Override
102  public void childrenAdded(NodeMemberEvent nme) {
103  updateOutlineViewPanel();
104  }
105 
106  @Override
107  public void childrenRemoved(NodeMemberEvent nme) {
108  updateOutlineViewPanel();
109  }
110  });
111 
112  splitPane.setResizeWeight(0.5);
113  splitPane.setDividerLocation(0.5);
114  }
115 
116  @Override
117  public String getDisplayName() {
118  return Bundle.ContactsViewer_tabTitle();
119  }
120 
121  @Override
122  public JPanel getPanel() {
123  return this;
124  }
125 
126  @Override
127  public void setSelectionInfo(SelectionInfo info) {
128  contactPane.setNode(null);
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: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.