Autopsy  4.14.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 @ServiceProvider(service = RelationshipsViewer.class)
49 public final class ContactsViewer extends JPanel implements RelationshipsViewer{
50 
51 // private final ExplorerManager tableEM;
52  private final Outline outline;
54  private final PropertyChangeListener focusPropertyListener;
55  private final ContactsChildNodeFactory nodeFactory;
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  public ContactsViewer() {
69  initComponents();
70 
71  outlineViewPanel.hideOutlineView(Bundle.ContactsViewer_noContacts_message());
72 
73  proxyLookup = new ModifiableProxyLookup(createLookup(outlineViewPanel.getExplorerManager(), getActionMap()));
74  nodeFactory = new ContactsChildNodeFactory(null);
75 
76  // See org.sleuthkit.autopsy.timeline.TimeLineTopComponent for a detailed
77  // explaination of focusPropertyListener
78  focusPropertyListener = (final PropertyChangeEvent focusEvent) -> {
79  if (focusEvent.getPropertyName().equalsIgnoreCase("focusOwner")) {
80  final Component newFocusOwner = (Component) focusEvent.getNewValue();
81 
82  if (newFocusOwner == null) {
83  return;
84  }
85  if (isDescendingFrom(newFocusOwner, contactPane)) {
86  //if the focus owner is within the MessageContentViewer (the attachments table)
87  proxyLookup.setNewLookups(createLookup(contactPane.getExplorerManager(), getActionMap()));
88  } else if (isDescendingFrom(newFocusOwner, ContactsViewer.this)) {
89  //... or if it is within the Results table.
90  proxyLookup.setNewLookups(createLookup(outlineViewPanel.getExplorerManager(), getActionMap()));
91 
92  }
93  }
94  };
95 
96  outline = outlineViewPanel.getOutlineView().getOutline();
97  outlineViewPanel.getOutlineView().setPropertyColumns(
98  "TSK_EMAIL", BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL.getDisplayName(),
99  "TSK_PHONE_NUMBER", BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER.getDisplayName()
100  );
101  outline.setRootVisible(false);
102  ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel(Bundle.ContactsViewer_columnHeader_Name());
103 
104  outlineViewPanel.hideOutlineView("<No contacts for selected account>");
105 
106  outlineViewPanel.getExplorerManager().addPropertyChangeListener((PropertyChangeEvent evt) -> {
107  if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
108  final Node[] nodes = outlineViewPanel.getExplorerManager().getSelectedNodes();
109  contactPane.setNode(nodes);
110  }
111  });
112 
113  outlineViewPanel.getExplorerManager().setRootContext(new TableFilterNode(new DataResultFilterNode(new AbstractNode(Children.create(nodeFactory, true)), outlineViewPanel.getExplorerManager()), true));
114 
115  // When a new set of nodes are added to the OutlineView the childrenAdded
116  // seems to be fired before the childrenRemoved.
117  outlineViewPanel.getExplorerManager().getRootContext().addNodeListener(new NodeAdapter(){
118  @Override
119  public void childrenAdded(NodeMemberEvent nme) {
120  updateOutlineViewPanel();
121  }
122 
123  @Override
124  public void childrenRemoved(NodeMemberEvent nme) {
125  updateOutlineViewPanel();
126  }
127  });
128 
129  splitPane.setResizeWeight(0.5);
130  splitPane.setDividerLocation(0.5);
131  }
132 
133  @Override
134  public String getDisplayName() {
135  return Bundle.ContactsViewer_tabTitle();
136  }
137 
138  @Override
139  public JPanel getPanel() {
140  return this;
141  }
142 
143  @Override
144  public void setSelectionInfo(SelectionInfo info) {
145  nodeFactory.refresh(info);
146  }
147 
148  @Override
149  public Lookup getLookup() {
150  return proxyLookup;
151  }
152 
153  @Override
154  public void addNotify() {
155  super.addNotify();
156  //add listener that maintains correct selection in the Global Actions Context
157  KeyboardFocusManager.getCurrentKeyboardFocusManager()
158  .addPropertyChangeListener("focusOwner", focusPropertyListener); //NON-NLS
159  }
160 
161  @Override
162  public void removeNotify() {
163  super.removeNotify();
164  KeyboardFocusManager.getCurrentKeyboardFocusManager()
165  .removePropertyChangeListener("focusOwner", focusPropertyListener); //NON-NLS
166  }
167 
168  private void updateOutlineViewPanel() {
169  int nodeCount = outlineViewPanel.getExplorerManager().getRootContext().getChildren().getNodesCount();
170  if(nodeCount == 0) {
171  outlineViewPanel.hideOutlineView(Bundle.ContactsViewer_noContacts_message());
172  } else {
173  outlineViewPanel.showOutlineView();
174  }
175  }
176 
182  @SuppressWarnings("unchecked")
183  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
184  private void initComponents() {
185  java.awt.GridBagConstraints gridBagConstraints;
186 
187  splitPane = new javax.swing.JSplitPane();
190 
191  setLayout(new java.awt.GridBagLayout());
192 
193  splitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
194  splitPane.setRightComponent(contactPane);
195  splitPane.setLeftComponent(outlineViewPanel);
196 
197  gridBagConstraints = new java.awt.GridBagConstraints();
198  gridBagConstraints.gridx = 0;
199  gridBagConstraints.gridy = 0;
200  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
201  gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
202  gridBagConstraints.weightx = 1.0;
203  gridBagConstraints.weighty = 1.0;
204  add(splitPane, gridBagConstraints);
205  }// </editor-fold>//GEN-END:initComponents
206 
207 
208  // Variables declaration - do not modify//GEN-BEGIN:variables
211  private javax.swing.JSplitPane splitPane;
212  // End of variables declaration//GEN-END:variables
213 }
org.sleuthkit.autopsy.communications.relationships.OutlineViewPanel outlineViewPanel
org.sleuthkit.autopsy.communications.relationships.ContactDetailsPane contactPane

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.