Autopsy  4.6.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-18 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 public final class MessageBrowser extends JPanel implements ExplorerManager.Provider, Lookup.Provider {
45 
46  private static final long serialVersionUID = 1L;
47  private final ExplorerManager tableEM;
48  private final ExplorerManager gacExplorerManager;
50  /* lookup that will be exposed through the (Global Actions Context) */
51  private final ModifiableProxyLookup proxyLookup = new ModifiableProxyLookup();
52 
53  private final PropertyChangeListener focusPropertyListener = new PropertyChangeListener() {
76  @Override
77  public void propertyChange(final PropertyChangeEvent focusEvent) {
78  if (focusEvent.getPropertyName().equalsIgnoreCase("focusOwner")) {
79  final Component newFocusOwner = (Component) focusEvent.getNewValue();
80 
81  if (newFocusOwner == null) {
82  return;
83  }
84  if (isDescendingFrom(newFocusOwner, messageDataContent)) {
85  //if the focus owner is within the MessageContentViewer ( the attachments table)
86  proxyLookup.setNewLookups(createLookup(messageDataContent.getExplorerManager(), getActionMap()));
87  } else if (isDescendingFrom(newFocusOwner, messagesResultPanel)) {
88  //... or if it is within the Messages table.
89  proxyLookup.setNewLookups(createLookup(gacExplorerManager, getActionMap()));
90  }
91 
92  }
93  }
94  };
95 
107  @NbBundle.Messages({"MessageBrowser.DataResultViewerTable.title=Messages"})
108  MessageBrowser(final ExplorerManager tableEM, final ExplorerManager gacExplorerManager) {
109  this.tableEM = tableEM;
110  this.gacExplorerManager = gacExplorerManager;
111  initComponents();
112  //create an uninitialized DataResultPanel so we can control the ResultViewers that get added.
113  messagesResultPanel = DataResultPanel.createInstanceUninitialized("Account", "", Node.EMPTY, 0, messageDataContent);
114  splitPane.setTopComponent(messagesResultPanel);
115  splitPane.setBottomComponent(messageDataContent);
116  messagesResultPanel.addResultViewer(new DataResultViewerTable(gacExplorerManager,
117  Bundle.MessageBrowser_DataResultViewerTable_title()));
118  messagesResultPanel.open();
119 
120  this.tableEM.addPropertyChangeListener(new PropertyChangeListener() {
127  @Override
128  public void propertyChange(PropertyChangeEvent pce) {
129  if (pce.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES)) {
130  final Node[] selectedNodes = MessageBrowser.this.tableEM.getSelectedNodes();
131  messagesResultPanel.setNumberOfChildNodes(0);
132  messagesResultPanel.setNode(null);
133  messagesResultPanel.setPath("");
134  if (selectedNodes.length > 0) {
135  Node rootNode;
136  final Node selectedNode = selectedNodes[0];
137 
138  if (selectedNode instanceof AccountDeviceInstanceNode) {
139  rootNode = makeRootNodeFromAccountDeviceInstanceNodes(selectedNodes);
140  } else {
141  rootNode = selectedNode;
142  }
143  messagesResultPanel.setPath(rootNode.getDisplayName());
144  messagesResultPanel.setNode(new TableFilterNode(new DataResultFilterNode(rootNode, gacExplorerManager), true));
145  }
146  }
147  }
148 
149  private Node makeRootNodeFromAccountDeviceInstanceNodes(final Node[] selectedNodes) {
150  //Use lookup here?
151  final AccountDeviceInstanceNode adiNode = (AccountDeviceInstanceNode) selectedNodes[0];
152 
153  final Set<AccountDeviceInstanceKey> accountDeviceInstances = new HashSet<>();
154  for (final Node n : selectedNodes) {
155  //Use lookup here?
156  accountDeviceInstances.add(((AccountDeviceInstanceNode) n).getAccountDeviceInstanceKey());
157  }
158  return SelectionNode.createFromAccounts(accountDeviceInstances, adiNode.getFilter(), adiNode.getCommsManager());
159  }
160  }
161  );
162  }
163 
164  @Override
165  public ExplorerManager getExplorerManager() {
166  return gacExplorerManager;
167  }
168 
169  @Override
170  public Lookup getLookup() {
171  return proxyLookup;
172  }
173 
174  @Override
175  public void addNotify() {
176  super.addNotify();
177  //add listener that maintains correct selection in the Global Actions Context
178  KeyboardFocusManager.getCurrentKeyboardFocusManager()
179  .addPropertyChangeListener("focusOwner", focusPropertyListener);
180  }
181 
182  @Override
183  public void removeNotify() {
184  super.removeNotify();
185  KeyboardFocusManager.getCurrentKeyboardFocusManager()
186  .removePropertyChangeListener("focusOwner", focusPropertyListener);
187  }
188 
194  @SuppressWarnings("unchecked")
195  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
196  private void initComponents() {
197 
198  splitPane = new javax.swing.JSplitPane();
200 
201  splitPane.setDividerLocation(400);
202  splitPane.setDividerSize(10);
203  splitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
204  splitPane.setResizeWeight(0.5);
205  splitPane.setBottomComponent(messageDataContent);
206 
207  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
208  this.setLayout(layout);
209  layout.setHorizontalGroup(
210  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
211  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
212  .addGap(0, 0, 0)
213  .addComponent(splitPane))
214  );
215  layout.setVerticalGroup(
216  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
217  .addGroup(layout.createSequentialGroup()
218  .addGap(0, 0, 0)
219  .addComponent(splitPane, javax.swing.GroupLayout.DEFAULT_SIZE, 1083, Short.MAX_VALUE)
220  .addGap(0, 0, 0))
221  );
222  }// </editor-fold>//GEN-END:initComponents
223 
224 
225  // Variables declaration - do not modify//GEN-BEGIN:variables
227  private javax.swing.JSplitPane splitPane;
228  // End of variables declaration//GEN-END:variables
229 
230 }
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 May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.