Autopsy  4.7.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
MessageBrowser.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2017-2018 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;
20 
21 import java.awt.Component;
22 import java.awt.KeyboardFocusManager;
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
25 import java.util.HashSet;
26 import java.util.Set;
27 import javax.swing.JPanel;
28 import static javax.swing.SwingUtilities.isDescendingFrom;
29 import org.openide.explorer.ExplorerManager;
30 import static org.openide.explorer.ExplorerUtils.createLookup;
31 import org.openide.nodes.Node;
32 import org.openide.util.Lookup;
33 import org.openide.util.NbBundle;
38 
44 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
45 public final class MessageBrowser extends JPanel implements ExplorerManager.Provider, Lookup.Provider {
46 
47  private static final long serialVersionUID = 1L;
48  private final ExplorerManager tableEM;
49  private final ExplorerManager gacExplorerManager;
51  /* lookup that will be exposed through the (Global Actions Context) */
52  private final ModifiableProxyLookup proxyLookup = new ModifiableProxyLookup();
53 
54  private final PropertyChangeListener focusPropertyListener = new PropertyChangeListener() {
77  @Override
78  public void propertyChange(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, messageDataContent)) {
86  //if the focus owner is within the MessageContentViewer ( the attachments table)
87  proxyLookup.setNewLookups(createLookup(messageDataContent.getExplorerManager(), getActionMap()));
88  } else if (isDescendingFrom(newFocusOwner, messagesResultPanel)) {
89  //... or if it is within the Messages table.
90  proxyLookup.setNewLookups(createLookup(gacExplorerManager, getActionMap()));
91  }
92 
93  }
94  }
95  };
96 
108  @NbBundle.Messages({"MessageBrowser.DataResultViewerTable.title=Messages"})
109  MessageBrowser(final ExplorerManager tableEM, final ExplorerManager gacExplorerManager) {
110  this.tableEM = tableEM;
111  this.gacExplorerManager = gacExplorerManager;
112  initComponents();
113  //create an uninitialized DataResultPanel so we can control the ResultViewers that get added.
114  messagesResultPanel = DataResultPanel.createInstanceUninitialized("Account", "", Node.EMPTY, 0, messageDataContent);
115  splitPane.setTopComponent(messagesResultPanel);
116  splitPane.setBottomComponent(messageDataContent);
117  messagesResultPanel.addResultViewer(new DataResultViewerTable(gacExplorerManager,
118  Bundle.MessageBrowser_DataResultViewerTable_title()));
119  messagesResultPanel.open();
120 
121  this.tableEM.addPropertyChangeListener(new PropertyChangeListener() {
128  @Override
129  public void propertyChange(PropertyChangeEvent pce) {
130  if (pce.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
131  final Node[] selectedNodes = MessageBrowser.this.tableEM.getSelectedNodes();
132  messagesResultPanel.setNumberOfChildNodes(0);
133  messagesResultPanel.setNode(null);
134  messagesResultPanel.setPath("");
135  if (selectedNodes.length > 0) {
136  Node rootNode;
137  final Node selectedNode = selectedNodes[0];
138 
139  if (selectedNode instanceof AccountDeviceInstanceNode) {
140  rootNode = makeRootNodeFromAccountDeviceInstanceNodes(selectedNodes);
141  } else {
142  rootNode = selectedNode;
143  }
144  messagesResultPanel.setPath(rootNode.getDisplayName());
145  messagesResultPanel.setNode(new TableFilterNode(new DataResultFilterNode(rootNode, gacExplorerManager), true));
146  }
147  }
148  }
149 
150  private Node makeRootNodeFromAccountDeviceInstanceNodes(final Node[] selectedNodes) {
151  //Use lookup here?
152  final AccountDeviceInstanceNode adiNode = (AccountDeviceInstanceNode) selectedNodes[0];
153 
154  final Set<AccountDeviceInstanceKey> accountDeviceInstances = new HashSet<>();
155  for (final Node n : selectedNodes) {
156  //Use lookup here?
157  accountDeviceInstances.add(((AccountDeviceInstanceNode) n).getAccountDeviceInstanceKey());
158  }
159  return SelectionNode.createFromAccounts(accountDeviceInstances, adiNode.getFilter(), adiNode.getCommsManager());
160  }
161  }
162  );
163  }
164 
165  @Override
166  public ExplorerManager getExplorerManager() {
167  return gacExplorerManager;
168  }
169 
170  @Override
171  public Lookup getLookup() {
172  return proxyLookup;
173  }
174 
175  @Override
176  public void addNotify() {
177  super.addNotify();
178  //add listener that maintains correct selection in the Global Actions Context
179  KeyboardFocusManager.getCurrentKeyboardFocusManager()
180  .addPropertyChangeListener("focusOwner", focusPropertyListener);
181  }
182 
183  @Override
184  public void removeNotify() {
185  super.removeNotify();
186  KeyboardFocusManager.getCurrentKeyboardFocusManager()
187  .removePropertyChangeListener("focusOwner", focusPropertyListener);
188  }
189 
195  @SuppressWarnings("unchecked")
196  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
197  private void initComponents() {
198 
199  splitPane = new javax.swing.JSplitPane();
200  messageDataContent = new org.sleuthkit.autopsy.communications.MessageDataContent();
201 
202  splitPane.setDividerLocation(400);
203  splitPane.setDividerSize(10);
204  splitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
205  splitPane.setResizeWeight(0.5);
206  splitPane.setBottomComponent(messageDataContent);
207 
208  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
209  this.setLayout(layout);
210  layout.setHorizontalGroup(
211  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
212  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
213  .addGap(0, 0, 0)
214  .addComponent(splitPane))
215  );
216  layout.setVerticalGroup(
217  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
218  .addGroup(layout.createSequentialGroup()
219  .addGap(0, 0, 0)
220  .addComponent(splitPane, javax.swing.GroupLayout.DEFAULT_SIZE, 1083, Short.MAX_VALUE)
221  .addGap(0, 0, 0))
222  );
223  }// </editor-fold>//GEN-END:initComponents
224 
225 
226  // Variables declaration - do not modify//GEN-BEGIN:variables
228  private javax.swing.JSplitPane splitPane;
229  // End of variables declaration//GEN-END:variables
230 
231 }
void setNumberOfChildNodes(Integer numberOfChildNodes)
static DataResultPanel createInstanceUninitialized(String title, String description, Node currentRootNode, int childNodeCount, DataContent customContentView)
void addResultViewer(DataResultViewer resultViewer)
org.sleuthkit.autopsy.communications.MessageDataContent messageDataContent

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.