GWT Tree, opening event
I'm using the tree control in GWT. I have a custom widget that I add as a TreeItem:
Tree testTree = new Tr开发者_C百科ee();
testTree.addItem(myWidget);
I would like to retrieve myWidget instance on the node opening event. Is it possible ? Does anybody knows which event should I be using ?
I tried the openHandler<TreeItem>
but what I retrieve is the... tree item.
In almost every case in which you're using GWT's Tree
, you really want to be using the GWT Incubator's FastTree
, which has an addBeforeOpenHandler()
method, which takes a BeforeOpenHandler<FastTreeItem>
which passes a BeforeOpenEvent
to onBeforeOpen()
making available the source
of the event (that was a mouthful...)
Long story short, FastTree
> Tree
, and you want to use addBeforeOpenHandler()
on the FastTree
itself.
To add widgets to your tree (instead of just FastTreeItem
s) you can add your widget to the enclosing FastTreeItem
, or just subclass FastTreeItem
to do what you want.
I was looking to far.
To answer my original question: The event we retrieve in the openHandler has all the info I needed.
public void onOpen(OpenEvent<TreeItem> event) {
// The TreeItem
TreeItem ti = event.getTarget();
// The widget added in the treeItem
CustomWidget cw = (CustomWidget)event.getTarget().getWidget();
}
Just for info:
Instead of adding a widget (which I didn't use anywhere else) to my TreeItem I extended TreeItem to create my own Widget. So I simply needed event.getTarget()
to access it.
About FastTree:
For what I read people working with GWT usually go straight to using FastTree which, as Jason said, offers more possibilities and better performances. I had problem running FastTree in my configuration (even with the examples code) and little time to deal with it so that's why I sticked with the native Tree widget.
精彩评论