View Full Version : Strange TreeNode behavious

18 Jun 2009, 7:11 AM
Using GXT 2 M3 (TreePanel)

I have a simple click listener set for the TreePanel (because I want to have the treenode expand on single-click but not vice-versa unless the ARROW to the left is clicked).

In the listener I check if the node is expanded and then do the stuff required as follows :

// This is how I set the listener on the tree panel
tree.addListener(Events.OnClick, new TreeClickListener());

// The Listener class
public class TreeClickListener implements Listener<TreePanelEvent<GenericTreeModel>>{

public void handleEvent(TreePanelEvent<GenericTreeModel> be) {

TreeNode node = be.getNode();
GenericTreeModel model = (GenericTreeModel) be.getItem();

if(be.getType() == Events.OnClick){




Now when a node is expanded and I click on a node's text the node.isExpanded() returns true (checking it in the listener), but when I click the arrow to the left, it returns false !!!

Wonder if this is a bug ?

18 Jun 2009, 7:19 AM
No, it is not a bug. If you click the arrow, the node collapse/expands and than your listener is called. So you get the new state.

18 Jun 2009, 7:24 AM
And is it different if you click the text instead ?

PS: Is there a better way to achieve this (may be) ?

18 Jun 2009, 7:32 AM
Clicking the arrow invokes expanding, clicking else where doesnt invoke it by default. So in your click listener check if the target was the arrow, and if it was the arrow, dont do anything, as normal actions are taking place.

18 Jun 2009, 7:38 AM
Great !!! thanks. That works :)