Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TreeItem ClickHandler in GWT

Tags:

gwt

With the standard GWT 2.0.3 API, how do you add a Clickhandler to the TreeItem? I'm hoping to implement asynchronous calls to the server that will retrieve the resulting TreeItems that are expanded.

Unfortunately FastTree doesn't work in GXT applications. Therefore I'm back to the original step of needing to attach handlers to TreeItems!

Are there any noticeable downfalls with this code:

Tree.addSelectionHandler(new SelectionHandler<TreeItem>()
{
    @Override
    public void onSelection(SelectionEvent event()
    {
        if(event.getSelectedItem == someTreeItem)
        {
            //Something
        }
    }
});
like image 491
Federer Avatar asked Apr 27 '10 14:04

Federer


1 Answers

With GWT's default Tree, there aren't handlers for specific TreeItems, just one SelectionHandler for the entire tree:

tree.addSelectionHandler(new SelectionHandler<TreeItem>() {
  @Override
  public void onSelection(SelectionEvent<TreeItem> event) {
    TreeItem item = event.getSelectedItem();
    // expand the selected item
  }
});

However, the GWT incubator's FastTree was literally built just for what you're trying to do, lazy-load the tree as items are expanded, so I would start there. Feel free to ask more questions if you have any.

like image 171
Jason Hall Avatar answered Sep 28 '22 06:09

Jason Hall