Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataResultTopComponent.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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 obtain 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.corecomponents;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.JComponent;
27 import org.openide.explorer.ExplorerManager;
28 import org.openide.explorer.ExplorerUtils;
29 import org.openide.nodes.Node;
30 import org.openide.util.NbBundle;
31 import org.openide.windows.Mode;
32 import org.openide.windows.RetainLocation;
33 import org.openide.windows.TopComponent;
34 import org.openide.windows.WindowManager;
41 
70 @RetainLocation("editor")
71 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
72 public final class DataResultTopComponent extends TopComponent implements DataResult, ExplorerManager.Provider {
73 
74  private static final Logger logger = Logger.getLogger(DataResultTopComponent.class.getName());
75  private static final List<String> activeComponentIds = Collections.synchronizedList(new ArrayList<String>());
76  private final boolean isMain;
77  private final String customModeName;
78  private final ExplorerManager explorerManager;
80 
99  public static DataResultTopComponent createInstance(String title, String description, Node node, int childNodeCount) {
100  DataResultTopComponent resultViewTopComponent = new DataResultTopComponent(false, title, null, Collections.emptyList(), DataContentTopComponent.findInstance());
101  initInstance(description, node, childNodeCount, resultViewTopComponent);
102  return resultViewTopComponent;
103  }
104 
124  public static DataResultTopComponent createInstance(String title, String description, Node node, int childNodeCount, Collection<DataResultViewer> viewers) {
125  DataResultTopComponent resultViewTopComponent = new DataResultTopComponent(false, title, null, viewers, DataContentTopComponent.findInstance());
126  initInstance(description, node, childNodeCount, resultViewTopComponent);
127  return resultViewTopComponent;
128  }
129 
146  public static DataResultTopComponent createInstance(String title) {
147  DataResultTopComponent resultViewTopComponent = new DataResultTopComponent(false, title, null, Collections.emptyList(), DataContentTopComponent.findInstance());
148  return resultViewTopComponent;
149  }
150 
161  public static void initInstance(String description, Node node, int childNodeCount, DataResultTopComponent resultViewTopComponent) {
162  resultViewTopComponent.setNumberOfChildNodes(childNodeCount);
163  resultViewTopComponent.open();
164  resultViewTopComponent.setNode(node);
165  resultViewTopComponent.setPath(description);
166  resultViewTopComponent.requestActive();
167  }
168 
189  public static DataResultTopComponent createInstance(String title, String mode, String description, Node node, int childNodeCount, DataContentTopComponent contentViewTopComponent) {
190  DataResultTopComponent newDataResult = new DataResultTopComponent(false, title, mode, Collections.emptyList(), contentViewTopComponent);
191  initInstance(description, node, childNodeCount, newDataResult);
192  return newDataResult;
193  }
194 
213  public DataResultTopComponent(String title) {
214  this(true, title, null, Collections.emptyList(), DataContentTopComponent.findInstance());
215  }
216 
235  private DataResultTopComponent(boolean isMain, String title, String mode, Collection<DataResultViewer> viewers, DataContentTopComponent contentViewTopComponent) {
236  this.isMain = isMain;
237  this.explorerManager = new ExplorerManager();
238  associateLookup(ExplorerUtils.createLookup(explorerManager, getActionMap()));
239  this.customModeName = mode;
240  this.dataResultPanel = new DataResultPanel(title, isMain, viewers, contentViewTopComponent);
241  initComponents();
242  customizeComponent(title);
243  }
244 
245  private void customizeComponent(String title) {
246  setToolTipText(NbBundle.getMessage(DataResultTopComponent.class, "HINT_NodeTableTopComponent")); //NON-NLS
247  setTitle(title);
248  setName(title);
249  getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(AddBookmarkTagAction.BOOKMARK_SHORTCUT, "addBookmarkTag"); //NON-NLS
250  getActionMap().put("addBookmarkTag", new AddBookmarkTagAction()); //NON-NLS
251  putClientProperty(TopComponent.PROP_CLOSING_DISABLED, isMain);
252  putClientProperty(TopComponent.PROP_MAXIMIZATION_DISABLED, true);
253  putClientProperty(TopComponent.PROP_DRAGGING_DISABLED, true);
254  activeComponentIds.add(title);
255  }
256 
257  @Override
258  public ExplorerManager getExplorerManager() {
259  return explorerManager;
260  }
261 
268  public static List<String> getActiveComponentIds() {
269  return new ArrayList<>(activeComponentIds);
270  }
271 
272  @Override
273  public int getPersistenceType() {
274  if (customModeName == null) {
275  return TopComponent.PERSISTENCE_NEVER;
276  } else {
277  return TopComponent.PERSISTENCE_ALWAYS;
278  }
279  }
280 
281  @Override
282  public void open() {
283  if (customModeName != null) {
284  Mode mode = WindowManager.getDefault().findMode(customModeName);
285  if (mode != null) {
286  logger.log(Level.INFO, "Found custom mode, setting: {0}", customModeName);//NON-NLS
287  mode.dockInto(this);
288  } else {
289  logger.log(Level.WARNING, "Could not find mode: {0}, will dock into the default one", customModeName);//NON-NLS
290  }
291  }
292  super.open();
293  }
294 
295  @Override
296  public List<DataResultViewer> getViewers() {
297  return dataResultPanel.getViewers();
298  }
299 
300  @Override
301  public void componentOpened() {
302  super.componentOpened();
303  this.dataResultPanel.open();
304  }
305 
306  @Override
307  public void componentActivated() {
308  super.componentActivated();
309 
310  /*
311  * Determine which node the content viewer should be using. If multiple
312  * results are selected, the node used by the content viewer should be
313  * null so no content gets displayed.
314  */
315  final DataContentTopComponent dataContentTopComponent = DataContentTopComponent.findInstance();
316  final Node[] nodeList = explorerManager.getSelectedNodes();
317 
318  Node selectedNode;
319  if (nodeList.length == 1) {
320  selectedNode = nodeList[0];
321  } else {
322  selectedNode = null;
323  }
324 
325  /*
326  * If the selected node of the content viewer is different than that of
327  * the result viewer, the content viewer needs to be updated. Otherwise,
328  * don't perform the update. This check will ensure that clicking the
329  * column headers and scroll bars of the DataResultTopComponent will not
330  * needlessly refresh the content view and cause the tab selection to
331  * change to the default.
332  */
333  if (selectedNode != dataContentTopComponent.getNode()) {
334  dataContentTopComponent.setNode(selectedNode);
335  }
336  }
337 
338  @Override
339  public void componentClosed() {
340  super.componentClosed();
341  activeComponentIds.remove(this.getName());
342  dataResultPanel.close();
343  }
344 
345  @Override
346  protected String preferredID() {
347  return getName();
348  }
349 
350  @Override
351  public String getPreferredID() {
352  return getName();
353  }
354 
355  @Override
356  public void setNode(Node selectedNode) {
357  dataResultPanel.setNode(selectedNode);
358  }
359 
360  @Override
361  public void setTitle(String title) {
362  setName(title);
363  }
364 
365  @Override
366  public void setPath(String pathText) {
367  dataResultPanel.setPath(pathText);
368  }
369 
370  @Override
371  public boolean isMain() {
372  return isMain;
373  }
374 
375  @Override
376  public boolean canClose() {
377  Case openCase;
378  try {
379  openCase = Case.getCurrentCaseThrows();
380  } catch (NoCurrentCaseException unused) {
381  return true;
382  }
383  return (!this.isMain) || openCase.hasData() == false;
384  }
385 
386  public void setSelectedNodes(Node[] selected) {
387  dataResultPanel.setSelectedNodes(selected);
388  }
389 
390  public Node getRootNode() {
391  return dataResultPanel.getRootNode();
392  }
393 
399  private void setNumberOfChildNodes(int childNodeCount) {
400  this.dataResultPanel.setNumberOfChildNodes(childNodeCount);
401  }
402 
408  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
409  private void initComponents() {
410 
411  org.sleuthkit.autopsy.corecomponents.DataResultPanel dataResultPanelLocal = dataResultPanel;
412 
413  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
414  this.setLayout(layout);
415  layout.setHorizontalGroup(
416  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
417  .addComponent(dataResultPanelLocal, javax.swing.GroupLayout.DEFAULT_SIZE, 967, Short.MAX_VALUE)
418  );
419  layout.setVerticalGroup(
420  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
421  .addComponent(dataResultPanelLocal, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)
422  );
423  }// </editor-fold>//GEN-END:initComponents
424  // Variables declaration - do not modify//GEN-BEGIN:variables
425  // End of variables declaration//GEN-END:variables
426 
444  @Deprecated
445  public DataResultTopComponent(boolean isMain, String title) {
446  this(false, title, null, Collections.emptyList(), DataContentTopComponent.findInstance());
447  }
448 
459  @Deprecated
460  public void resetTabs(Node node) {
461  dataResultPanel.setNode(node);
462  }
463 
464 }
void setNumberOfChildNodes(Integer numberOfChildNodes)
static DataResultTopComponent createInstance(String title, String description, Node node, int childNodeCount, Collection< DataResultViewer > viewers)
static DataResultTopComponent createInstance(String title, String description, Node node, int childNodeCount)
static synchronized DataContentTopComponent findInstance()
DataResultTopComponent(boolean isMain, String title, String mode, Collection< DataResultViewer > viewers, DataContentTopComponent contentViewTopComponent)
static void initInstance(String description, Node node, int childNodeCount, DataResultTopComponent resultViewTopComponent)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static DataResultTopComponent createInstance(String title, String mode, String description, Node node, int childNodeCount, DataContentTopComponent contentViewTopComponent)
static DataResultTopComponent createInstance(String title)

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