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