Skip to content

Commit

Permalink
added tooltip to specific node
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul-Biju committed Jan 10, 2024
1 parent 7da95da commit ff32a13
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/main/java/io/openliberty/tools/intellij/LibertyExplorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreePath;
import javax.xml.parsers.ParserConfigurationException;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -220,6 +222,33 @@ public static Tree buildTree(Project project, Color backgroundColor) {
}
});

tree.addMouseMotionListener(new MouseMotionAdapter() {
private String currentTooltipText = null;

@Override
public void mouseMoved(MouseEvent e) {
super.mouseMoved(e);

TreePath path = tree.getPathForLocation(e.getX(), e.getY());
if (path == null ) {
if (currentTooltipText != null) {
tree.setToolTipText(null);
currentTooltipText = null;
}
} else {
Object node = path.getLastPathComponent();
if (node instanceof LibertyModuleNode) {
LibertyModuleNode treeNode = (LibertyModuleNode) node;
String tooltipText = getBuildPath(treeNode);
if (!tooltipText.equals(currentTooltipText)) {
tree.setToolTipText(tooltipText);
currentTooltipText = tooltipText;
}
}
}
}
});

tree.addMouseListener(new PopupHandler() {
@Override
public void invokePopup(Component comp, int x, int y) {
Expand Down Expand Up @@ -308,7 +337,6 @@ public Component getTreeCellRendererComponent(
/**
* modification to get tooltiptext for liberty module tree
*/
tree.setToolTipText(getBuildPath(value));
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
// assign gear icon to action nodes
if (leaf) {
Expand Down

0 comments on commit ff32a13

Please sign in to comment.