TreeItem ClickHandler in GWT

gwt

Solution

With GWT's default `Tree`, there aren't handlers for specific `TreeItem`s, 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.

Problem

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 `TreeItem`s! Are there any noticeable downfalls with this code: ``` Tree.addSelectionHandler(new SelectionHandler<TreeItem>() { @Override public void onSelection(SelectionEvent event() { if(event.getSelectedItem == someTreeItem) { //Something } } }); ```

Original source