Tree

0 views
Skip to first unread message

dmcreyno

unread,
May 17, 2006, 10:58:26 AM5/17/06
to Google Web Toolkit
I've only done the basic hello world stuff and am looking into adding
event listeners of one type or another. I've noticed that the
onTreeItemStateChanged method fires twice when opening or closing a
node.

The reason I am looking into this is because I want a tree that I can
dynamically fill out based on which item the user clicks on. I do not
want to return the entire tree. I've looked at both onTreeItemSelected
and onTreeItemStateChanged. "onTreeItemStateChanged" seems, so far, to
be the most logical place. However, with onTreeItemStateChanged firing
twice, its kind of hard to manage.

Glenn

unread,
May 31, 2006, 6:22:03 PM5/31/06
to Google Web Toolkit
Yes, I also just figured out that onTreeItemStateChanged fires twice:
(1) click on plus sign - fires event, this results in my code
retrieving information to create new TreeItems and add those items to
the TreeItem that just got clicked.
(2) another event. Does this happen because I've just added TreeItems
in #1?

My solution is derived from the KitchenSink tree example. When I create
a new TreeItem, immediately addItem of class PendingItem (extends
TreeItem). Then in method onTreeItemStateChanged:

if (TreeItem.getChild(0) instanceof PendingItem) {
<remove child(0)>
<get child items>
}
The second onTreeItemStateChanged will then skip item retrieval because
the PendingItem is gone.

j...@google.com

unread,
Jun 2, 2006, 12:23:27 PM6/2/06
to Google Web Toolkit
Good catch. Adding this one to the issues list. If you want to patch
it for the moment, the only line that needs to change is Tree.java:478
:

item.setState(!item.getState(), false);

joel.

Reply all
Reply to author
Forward
0 new messages