19 package org.sleuthkit.autopsy.corecomponents;
21 import java.awt.Cursor;
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.List;
28 import javax.swing.JTabbedPane;
29 import javax.swing.SwingWorker;
30 import javax.swing.event.ChangeEvent;
31 import javax.swing.event.ChangeListener;
32 import org.openide.explorer.ExplorerManager;
33 import org.openide.nodes.Node;
34 import org.openide.nodes.NodeEvent;
35 import org.openide.nodes.NodeListener;
36 import org.openide.nodes.NodeMemberEvent;
37 import org.openide.nodes.NodeReorderEvent;
38 import org.openide.util.Lookup;
39 import org.openide.util.NbBundle;
75 @SuppressWarnings(
"PMD.SingularField")
78 private static final long serialVersionUID = 1L;
79 private static final int NO_TAB_SELECTED = -1;
80 private static final String PLEASE_WAIT_NODE_DISPLAY_NAME = NbBundle.getMessage(
DataResultPanel.class,
"DataResultPanel.pleasewaitNodeDisplayName");
109 createInstanceCommon(title, description, currentRootNode, childNodeCount, resultPanel);
134 public static DataResultPanel createInstance(String title, String description, Node currentRootNode,
int childNodeCount, Collection<DataResultViewer> viewers) {
136 createInstanceCommon(title, description, currentRootNode, childNodeCount, resultPanel);
165 createInstanceCommon(title, description, currentRootNode, childNodeCount, resultPanel);
191 createInstanceCommon(title, description, currentRootNode, childNodeCount, resultPanel);
208 resultViewPanel.setName(title);
210 resultViewPanel.
setNode(currentRootNode);
211 resultViewPanel.
setPath(description);
232 this.setTitle(title);
233 this.isMain = isMain;
234 this.contentView = contentView;
235 this.resultViewers =
new ArrayList<>(viewers);
236 this.explorerManagerListener =
new ExplorerManagerListener();
237 this.rootNodeListener =
new RootNodeListener();
270 this.descriptionLabel.setText(description);
279 resultViewers.add(resultViewer);
290 return Collections.unmodifiableList(resultViewers);
301 this.contentView = customContentView;
318 if (this.explorerManager == null) {
319 this.explorerManager = ExplorerManager.find(
this);
320 this.explorerManager.addPropertyChangeListener(this.explorerManagerListener);
329 if (this.resultViewerTabs.getTabCount() == 0) {
330 if (this.resultViewers.isEmpty()) {
333 this.resultViewers.add(resultViewer);
335 this.resultViewers.add(resultViewer.createInstance());
339 this.resultViewers.forEach((resultViewer) -> resultViewerTabs.addTab(resultViewer.getTitle(), resultViewer.getComponent()));
342 this.setVisible(
true);
357 if (this.currentRootNode != null) {
358 this.currentRootNode.removeNodeListener(rootNodeListener);
366 if (listeningToTabbedPane ==
false) {
367 resultViewerTabs.addChangeListener(
this);
368 listeningToTabbedPane =
true;
371 this.currentRootNode = rootNode;
372 if (this.currentRootNode != null) {
373 rootNodeListener.
reset();
374 this.currentRootNode.addNodeListener(rootNodeListener);
377 this.resultViewers.forEach((viewer) -> {
378 viewer.resetComponent();
380 setupTabs(this.currentRootNode);
382 if (this.currentRootNode != null) {
383 int childrenCount = this.currentRootNode.getChildren().getNodesCount();
384 this.numberOfChildNodesLabel.setText(Integer.toString(childrenCount));
386 this.numberOfChildNodesLabel.setVisible(
true);
397 return currentRootNode;
407 this.numberOfChildNodesLabel.setText(Integer.toString(numberOfChildNodes));
417 this.resultViewers.forEach((viewer) -> viewer.setSelectedNodes(selectedNodes));
431 for (
int i = 0; i < resultViewerTabs.getTabCount(); i++) {
432 if (resultViewers.get(i).isSupported(selectedNode)) {
433 resultViewerTabs.setEnabledAt(i,
true);
435 resultViewerTabs.setEnabledAt(i,
false);
445 int tabToSelect = NO_TAB_SELECTED;
447 NodeSelectionInfo selectedChildInfo = ((TableFilterNode) selectedNode).getChildNodeSelectionInfo();
448 if (null != selectedChildInfo) {
449 for (
int i = 0; i < resultViewers.size(); ++i) {
456 if (tabToSelect == NO_TAB_SELECTED) {
457 tabToSelect = resultViewerTabs.getSelectedIndex();
458 if ((tabToSelect == NO_TAB_SELECTED) || (!resultViewerTabs.isEnabledAt(tabToSelect))) {
459 for (
int i = 0; i < resultViewerTabs.getTabCount(); ++i) {
460 if (resultViewerTabs.isEnabledAt(i)) {
472 if (tabToSelect != NO_TAB_SELECTED) {
473 resultViewerTabs.setSelectedIndex(tabToSelect);
474 resultViewers.get(tabToSelect).setNode(selectedNode);
486 JTabbedPane pane = (JTabbedPane) event.getSource();
487 int currentTab = pane.getSelectedIndex();
490 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
492 currentViewer.
setNode(currentRootNode);
494 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
516 return (!this.isMain) || openCase.
hasData() ==
false;
525 if (explorerManager != null && explorerManagerListener != null) {
526 explorerManager.removePropertyChangeListener(explorerManagerListener);
527 explorerManager = null;
530 this.resultViewers.forEach((viewer) -> viewer.setNode(null));
534 this.descriptionLabel.removeAll();
535 this.numberOfChildNodesLabel.removeAll();
536 this.matchLabel.removeAll();
537 this.setLayout(null);
539 this.setVisible(
false);
545 return explorerManager;
563 if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES) && contentView != null) {
572 Node[] selectedNodes = explorerManager.getSelectedNodes();
573 if (selectedNodes.length == 1) {
574 contentView.
setNode(selectedNodes[0]);
585 class SetupTabsChildrenWorker
extends SwingWorker<Void, Void> {
587 private final Node childNode;
589 SetupTabsChildrenWorker(Node aChildNode) {
590 childNode = aChildNode;
594 protected Void doInBackground() throws Exception {
595 setupTabs(childNode);
600 protected void done() {
601 setupTabs(childNode);
612 private volatile boolean waitingForData =
true;
615 waitingForData =
true;
620 Node[] delta = nme.getDelta();
629 if (waitingForData && containsReal(delta)) {
630 waitingForData =
false;
631 Node childNode = nme.getNode();
632 new SetupTabsChildrenWorker(childNode).execute();
637 for (Node n : delta) {
638 if (!n.getDisplayName().equals(PLEASE_WAIT_NODE_DISPLAY_NAME)) {
650 if (currentRootNode != null && currentRootNode.getChildren() != null) {
651 setNumMatches(currentRootNode.getChildren().getNodesCount());
678 @SuppressWarnings(
"unchecked")
680 private
void initComponents() {
682 descriptionLabel =
new javax.swing.JLabel();
683 numberOfChildNodesLabel =
new javax.swing.JLabel();
684 matchLabel =
new javax.swing.JLabel();
685 resultViewerTabs =
new javax.swing.JTabbedPane();
687 setMinimumSize(
new java.awt.Dimension(0, 5));
688 setPreferredSize(
new java.awt.Dimension(5, 5));
690 org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel,
org.openide.util.NbBundle.getMessage(
DataResultPanel.class,
"DataResultPanel.descriptionLabel.text"));
691 descriptionLabel.setMinimumSize(
new java.awt.Dimension(5, 14));
693 org.openide.awt.Mnemonics.setLocalizedText(numberOfChildNodesLabel,
org.openide.util.NbBundle.getMessage(
DataResultPanel.class,
"DataResultPanel.numberOfChildNodesLabel.text"));
695 org.openide.awt.Mnemonics.setLocalizedText(matchLabel,
org.openide.util.NbBundle.getMessage(
DataResultPanel.class,
"DataResultPanel.matchLabel.text"));
697 resultViewerTabs.setMinimumSize(
new java.awt.Dimension(0, 5));
699 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
700 this.setLayout(layout);
701 layout.setHorizontalGroup(
702 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
703 .addGroup(layout.createSequentialGroup()
704 .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
705 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
706 .addComponent(numberOfChildNodesLabel)
707 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
708 .addComponent(matchLabel))
709 .addComponent(resultViewerTabs, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
711 layout.setVerticalGroup(
712 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
713 .addGroup(layout.createSequentialGroup()
714 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
715 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
716 .addComponent(numberOfChildNodesLabel)
717 .addComponent(matchLabel))
718 .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
720 .addComponent(resultViewerTabs, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
756 this.setNumberOfChildNodes(numberOfChildNodes);
void setupTabs(Node selectedNode)
void propertyChange(PropertyChangeEvent evt)
void setNumberOfChildNodes(Integer numberOfChildNodes)
static DataResultPanel createInstance(String title, String description, Node currentRootNode, int childNodeCount, Collection< DataResultViewer > viewers)
static DataResultPanel createInstance(String title, String description, Node currentRootNode, int childNodeCount, DataContent customContentView)
javax.swing.JLabel numberOfChildNodesLabel
static void createInstanceCommon(String title, String description, Node currentRootNode, int childNodeCount, DataResultPanel resultViewPanel)
javax.swing.JTabbedPane resultViewerTabs
void propertyChange(PropertyChangeEvent evt)
ExplorerManager explorerManager
final ExplorerManagerListener explorerManagerListener
static final int NO_TAB_SELECTED
void setNumMatches(Integer numberOfChildNodes)
void childrenReordered(NodeReorderEvent nre)
void setPath(String description)
ExplorerManager getExplorerManager()
void setNode(Node rootNode)
List< DataResultViewer > getViewers()
void stateChanged(ChangeEvent event)
static synchronized DataContentTopComponent findInstance()
void childrenRemoved(NodeMemberEvent nme)
void setSelectedNodes(Node[] selectedNodes)
static DataResultPanel createInstanceUninitialized(String title, String description, Node currentRootNode, int childNodeCount, DataContent customContentView)
void setContentViewer(DataContent customContentView)
final List< DataResultViewer > resultViewers
void addResultViewer(DataResultViewer resultViewer)
void nodeDestroyed(NodeEvent ne)
void setNode(Node selectedNode)
default void clearComponent()
void childrenAdded(final NodeMemberEvent nme)
static DataResultPanel createInstance(String title, String description, Node currentRootNode, int childNodeCount)
boolean listeningToTabbedPane
javax.swing.JLabel descriptionLabel
boolean containsReal(Node[] delta)
javax.swing.JLabel matchLabel
static Case getCurrentCaseThrows()
final RootNodeListener rootNodeListener
void setTitle(String title)
void resetTabs(Node unusedSelectedNode)