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.SwingUtilities;
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) {
380 rootNodeListener.
reset();
381 this.currentRootNode.addNodeListener(rootNodeListener);
384 this.resultViewers.forEach((viewer) -> {
385 viewer.resetComponent();
387 setupTabs(this.currentRootNode);
389 if (this.currentRootNode != null) {
390 int childrenCount = this.currentRootNode.getChildren().getNodesCount();
391 this.numberOfChildNodesLabel.setText(Integer.toString(childrenCount));
393 this.numberOfChildNodesLabel.setVisible(
true);
404 return currentRootNode;
414 this.numberOfChildNodesLabel.setText(Integer.toString(numberOfChildNodes));
424 this.resultViewers.forEach((viewer) -> viewer.setSelectedNodes(selectedNodes));
438 for (
int i = 0; i < resultViewerTabs.getTabCount(); i++) {
439 if (resultViewers.get(i).isSupported(selectedNode)) {
440 resultViewerTabs.setEnabledAt(i,
true);
442 resultViewerTabs.setEnabledAt(i,
false);
452 int tabToSelect = NO_TAB_SELECTED;
454 NodeSelectionInfo selectedChildInfo = ((TableFilterNode) selectedNode).getChildNodeSelectionInfo();
455 if (null != selectedChildInfo) {
456 for (
int i = 0; i < resultViewers.size(); ++i) {
463 if (tabToSelect == NO_TAB_SELECTED) {
464 tabToSelect = resultViewerTabs.getSelectedIndex();
465 if ((tabToSelect == NO_TAB_SELECTED) || (!resultViewerTabs.isEnabledAt(tabToSelect))) {
466 for (
int i = 0; i < resultViewerTabs.getTabCount(); ++i) {
467 if (resultViewerTabs.isEnabledAt(i)) {
479 if (tabToSelect != NO_TAB_SELECTED) {
480 resultViewerTabs.setSelectedIndex(tabToSelect);
481 resultViewers.get(tabToSelect).setNode(selectedNode);
493 JTabbedPane pane = (JTabbedPane) event.getSource();
494 int currentTab = pane.getSelectedIndex();
497 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
499 currentViewer.
setNode(currentRootNode);
501 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
523 return (!this.isMain) || openCase.
hasData() ==
false;
531 if (explorerManager != null && explorerManagerListener != null) {
532 explorerManager.removePropertyChangeListener(explorerManagerListener);
533 explorerManager = null;
536 this.resultViewers.forEach((viewer) -> viewer.setNode(null));
540 this.descriptionLabel.removeAll();
541 this.numberOfChildNodesLabel.removeAll();
542 this.matchLabel.removeAll();
543 this.setLayout(null);
545 this.setVisible(
false);
551 return explorerManager;
569 if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES) && contentView != null) {
578 Node[] selectedNodes = explorerManager.getSelectedNodes();
579 if (selectedNodes.length == 1) {
580 contentView.
setNode(selectedNodes[0]);
597 private volatile boolean waitingForData =
true;
600 waitingForData =
true;
605 Node[] delta = nme.getDelta();
616 if (waitingForData && containsReal(delta)) {
617 waitingForData =
false;
618 if (SwingUtilities.isEventDispatchThread()) {
619 setupTabs(nme.getNode());
621 SwingUtilities.invokeLater(() -> {
622 setupTabs(nme.getNode());
629 for (Node n : delta) {
630 if (!n.getDisplayName().equals(PLEASE_WAIT_NODE_DISPLAY_NAME)) {
642 if (currentRootNode != null && currentRootNode.getChildren() != null) {
643 setNumMatches(currentRootNode.getChildren().getNodesCount());
670 @SuppressWarnings(
"unchecked")
672 private
void initComponents() {
674 descriptionLabel =
new javax.swing.JLabel();
675 numberOfChildNodesLabel =
new javax.swing.JLabel();
676 matchLabel =
new javax.swing.JLabel();
677 resultViewerTabs =
new javax.swing.JTabbedPane();
679 setMinimumSize(
new java.awt.Dimension(0, 5));
680 setPreferredSize(
new java.awt.Dimension(5, 5));
682 org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel,
org.openide.util.NbBundle.getMessage(
DataResultPanel.class,
"DataResultPanel.descriptionLabel.text"));
683 descriptionLabel.setMinimumSize(
new java.awt.Dimension(5, 14));
685 org.openide.awt.Mnemonics.setLocalizedText(numberOfChildNodesLabel,
org.openide.util.NbBundle.getMessage(
DataResultPanel.class,
"DataResultPanel.numberOfChildNodesLabel.text"));
687 org.openide.awt.Mnemonics.setLocalizedText(matchLabel,
org.openide.util.NbBundle.getMessage(
DataResultPanel.class,
"DataResultPanel.matchLabel.text"));
689 resultViewerTabs.setMinimumSize(
new java.awt.Dimension(0, 5));
691 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
692 this.setLayout(layout);
693 layout.setHorizontalGroup(
694 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
695 .addGroup(layout.createSequentialGroup()
696 .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
697 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
698 .addComponent(numberOfChildNodesLabel)
699 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
700 .addComponent(matchLabel))
701 .addComponent(resultViewerTabs, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
703 layout.setVerticalGroup(
704 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
705 .addGroup(layout.createSequentialGroup()
706 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
707 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
708 .addComponent(numberOfChildNodesLabel)
709 .addComponent(matchLabel))
710 .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
712 .addComponent(resultViewerTabs, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
748 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)