TreeItem ClickHandler in GWT

With the standard GWT 2.0.3 API, how do you add a Clickhandler to a TreeItem? I hope to implement asynchronous calls on the server that will retrieve the received TreeItems that have been extended.

Unfortunately, it FastTreedoes not work in GXT applications. Therefore, I will return to the initial stage when you need to bind handlers to TreeItems!

Are there any noticeable drops with this code:

Tree.addSelectionHandler(new SelectionHandler<TreeItem>()
{
    @Override
    public void onSelection(SelectionEvent event()
    {
        if(event.getSelectedItem == someTreeItem)
        {
            //Something
        }
    }
});
+5
source share
2 answers

When using GWT, by default Treefor specific TreeItems, handlers are not used, but SelectionHandlerfor the whole tree:

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

GWT FastTree , , lazy-load , , . , .

+12
// First create a new treeitem-class with a new method:
public class TreeItemAdv extends TreeItem {
    protected void doSelectionAction() {
        // TODO: The child should overwrite this method!
        System.out.println("The child should overwrite this method!");
    }
}

...
    // define your tree:
    Tree tree = new Tree();
    tree.addSelectionHandler(new SelectionHandler<TreeItem>() {
        @Override
        public void onSelection(SelectionEvent<TreeItem> event) {               
            TreeItemAdv item = (TreeItemAdv) event.getSelectedItem();
            item.doSelectionAction(); // do item-specific stuff
        }
    });

    // define and add your items:
    TreeItemAdv ti1 = new TreeItemAdv() {
        @Override
        protected void doSelectionAction() {
            // TODO: Do some stuff.
            System.out.println("1: Here I am.");
        }           
    };      
    ti1.setText("Item 1");      
    tree.addItem(ti1);
    // and an other item:
    TreeItemAdv ti2 = new TreeItemAdv() {
        @Override
        protected void doSelectionAction() {
            // TODO: Do some stuff.
            System.out.println("2: Here I am.");
        }           
    };      
    ti2.setText("Item 2");      
    tree.addItem(ti2);
...
-1

All Articles