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 if ((tabToSelect == NO_TAB_SELECTED) || (!resultViewerTabs.isEnabledAt(tabToSelect))) {
465 for (
int i = 0; i < resultViewerTabs.getTabCount(); ++i) {
466 if (resultViewerTabs.isEnabledAt(i)) {
478 if (tabToSelect != NO_TAB_SELECTED) {
479 resultViewerTabs.setSelectedIndex(tabToSelect);
480 resultViewers.get(tabToSelect).setNode(selectedNode);
492 JTabbedPane pane = (JTabbedPane) event.getSource();
493 int currentTab = pane.getSelectedIndex();
496 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
498 currentViewer.
setNode(currentRootNode);
500 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
522 return (!this.isMain) || openCase.
hasData() ==
false;
530 if (explorerManager != null && explorerManagerListener != null) {
531 explorerManager.removePropertyChangeListener(explorerManagerListener);
532 explorerManager = null;
535 this.resultViewers.forEach((viewer) -> viewer.setNode(null));
539 this.descriptionLabel.removeAll();
540 this.numberOfChildNodesLabel.removeAll();
541 this.matchLabel.removeAll();
542 this.setLayout(null);
544 this.setVisible(
false);
550 return explorerManager;
568 if (evt.getPropertyName().equals(ExplorerManager.PROP_SELECTED_NODES) && contentView != null) {
577 Node[] selectedNodes = explorerManager.getSelectedNodes();
578 if (selectedNodes.length == 1) {
579 contentView.
setNode(selectedNodes[0]);
596 private volatile boolean waitingForData =
true;
599 waitingForData =
true;
604 Node[] delta = nme.getDelta();
615 if (waitingForData && containsReal(delta)) {
616 waitingForData =
false;
617 if (SwingUtilities.isEventDispatchThread()) {
618 setupTabs(nme.getNode());
620 SwingUtilities.invokeLater(() -> {
621 setupTabs(nme.getNode());
628 for (Node n : delta) {
629 if (!n.getDisplayName().equals(PLEASE_WAIT_NODE_DISPLAY_NAME)) {
641 if (currentRootNode != null && currentRootNode.getChildren() != null) {
642 setNumMatches(currentRootNode.getChildren().getNodesCount());
669 @SuppressWarnings(
"unchecked")
671 private
void initComponents() {
673 descriptionLabel =
new javax.swing.JLabel();
674 numberOfChildNodesLabel =
new javax.swing.JLabel();
675 matchLabel =
new javax.swing.JLabel();
676 resultViewerTabs =
new javax.swing.JTabbedPane();
678 setMinimumSize(
new java.awt.Dimension(0, 5));
679 setPreferredSize(
new java.awt.Dimension(5, 5));
681 org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel,
org.openide.util.NbBundle.getMessage(
DataResultPanel.class,
"DataResultPanel.descriptionLabel.text"));
682 descriptionLabel.setMinimumSize(
new java.awt.Dimension(5, 14));
684 org.openide.awt.Mnemonics.setLocalizedText(numberOfChildNodesLabel,
org.openide.util.NbBundle.getMessage(
DataResultPanel.class,
"DataResultPanel.numberOfChildNodesLabel.text"));
686 org.openide.awt.Mnemonics.setLocalizedText(matchLabel,
org.openide.util.NbBundle.getMessage(
DataResultPanel.class,
"DataResultPanel.matchLabel.text"));
688 resultViewerTabs.setMinimumSize(
new java.awt.Dimension(0, 5));
690 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
691 this.setLayout(layout);
692 layout.setHorizontalGroup(
693 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
694 .addGroup(layout.createSequentialGroup()
695 .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
696 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
697 .addComponent(numberOfChildNodesLabel)
698 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
699 .addComponent(matchLabel))
700 .addComponent(resultViewerTabs, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
702 layout.setVerticalGroup(
703 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
704 .addGroup(layout.createSequentialGroup()
705 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
706 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
707 .addComponent(numberOfChildNodesLabel)
708 .addComponent(matchLabel))
709 .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
711 .addComponent(resultViewerTabs, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
747 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)