PDA

View Full Version : Single-click Expand of Tree Node Causes Issue


ccocco
04-30-2008, 02:06 PM
I'm trying to expand a parent TreeItem programmatically when it is single-clicked. I do this by adding a Listener to the Tree to detect an Events.Click event. In the handleEvent() method of the listener, I call TreeItem.setExpanded(true, false) and the TreeItem expands fine. But then when I use the arrow expansion handle to collapse the tree node, I can no longer expand it using a single-click, double-click, or expansion handle. It expands and collapses immediately. If I don't expand it programmatically, it works fine. I've also tried expanding it using Tree.expandPath(TreeItm.getPath()) but it yields the same results. Does anyone know if this is a bug or whether there is a different way to simulate a single-click expansion of a tree node. It seems like a pretty basic thing to do...

darrellmeyer
04-30-2008, 02:45 PM
If you post some sample code I will take a look.

ccocco
04-30-2008, 02:52 PM
Sure, this definitely looks like a timing issue as when I step through the code in the debugger, the problem doesn't seem to occur. Here's the code:


public class ODSTreeListener implements Listener

{
public void handleEvent(BaseEvent event)
{
event.getEventType());




if (event.getEventType() == Events.Click)
{




if (event.widgetinstanceof TreeItem)
{
TreeItem treeItem = (TreeItem) event.widget;





if (!treeItem.isLeaf())
{
if (!treeItem.isExpanded())
{
treeItem.setExpanded(true);
}
}
}
}
}
}




public MyTree extends Panel
{
public MyTree()
{
...




Tree tree =


new Tree();

tree.setAnimate(true);




ODSTreeListener listener = new ODSTreeListener();
tree.addListener(Events.Click, listener);
tree.addListener(Events.DoubleClick, listener);





TreeViewer viewer = new TreeViewer(tree);
viewer.setContentProvider(new ODSModelContentProvider());
viewer.setLabelProvider(new ODSModelLabelProvider());
add(tree);




...
}

ccocco
04-30-2008, 03:07 PM
Using a DeferredCommand to expand the TreeItem seems to resolve this issue:

publicvoid handleEvent(BaseEvent event)
{
if (event.getEventType() == Events.Click)
{
if (event.widgetinstanceof TreeItem)
{
final TreeItem treeItem = (TreeItem) event.widget;

if (!treeItem.isLeaf())
{
if (!treeItem.isExpanded())
{
DeferredCommand.addCommand(new Command()
{
publicvoid execute()
{
treeItem.setExpanded(true);
}
});
}
}
}
}
}
}