Hi Josh,
Yes, this is by design. The right-click doesn't "select" a node, so
the right way to figure out what node was clicked on is to use the
"getNodeAt(y)".
Thanks for the code example and for using Pivot!
~Roger Whitcomb
-----Original Message-----
From: Josh R [mailto:[email protected]]
Sent: Wednesday, August 08, 2012 9:25 AM
To: [email protected]
Subject: getSelectedNode from within configureContextMenu could return null
Hi,
I've added a context-menu to my TreeView. Now, if I just
hover(position) the mouse over a tree-node and right click on that node(without
selecting that node with a left-click) then
TreeView.getSelectedNode() returns null. But I can certainly get the node by
using Tree.get(). So just wanted to check if this is as designed. Anyways, just
wanted to share my test-case so that other beginners like myself can save some
time.
here's my existing code(Note: In this particular code-path I'm going to stop
using getSelectedNode and just use Tree.get):
my_tree.setMenuHandler(new MenuHandler.Adapter() {
public boolean configureContextMenu( Component component, Menu menu, int x, int
y ) {
Path nodePath = my_tree.getNodeAt(y);
Object obj = my_tree.getSelectedNode();
if (obj == null) {
obj = Tree.get(my_tree.getTreeData(), nodePath);
if (obj == null)
return true;
}
// use obj ...
return false;
}
thanks