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