Click Handlers for Trees in GXT 3?

I was looking at the GXT3 TreeAPI to do something when I click or double-click on a node in a tree, and I cannot find anything that could work.

I know that it TreeGridhas a handler CellClickHandlerand CellDoubleClick, but for Treeit seems there is nothing similar. There's a generic method addHandlerinherited from Widget, but it looks like it applies to the whole tree, not to a specific node.

Is there something I am missing or another / better way to do this?

+3
source share
4 answers

use the selection model TreePanel:

treePanel.getSelectionModel().addSelectionChangedListener(
        new SelectionChangedListener<BaseTreeModel>() {

            @Override
            public void selectionChanged(SelectionChangedEvent<BaseTreeModel> se) {

                BaseTreeModel selectedItem = se.getSelectedItem();

                // implement functionality
            }
        }
);

see the TreePanelAPI for help.

+2

- Tree onDoubleClick ( onClick):

Tree tree = new Tree<MyModel, String>(store, valueProvider){            
    @Override
    protected void onDoubleClick(Event event) {
        TreeNode<MyModel> node = findNode(event.getEventTarget().<Element> cast());
        Info.display("Double Click", "You double clicked this node!");
        super.onDoubleClick(event);
   }
};
+2

    tree.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    tree.getSelectionModel().addSelectionHandler(new SelectionHandler<MenuView.MenuDto>() {

        public void onSelection(SelectionEvent<MenuDto> event) {
            MenuDto mnu = event.getSelectedItem();
            Info.display("Tree Handler", mnu.getDescripcion());
        }
    });

For multiple choices

    tree.getSelectionModel().addSelectionChangedHandler(new SelectionChangedHandler<MenuView.MenuDto>() {

        public void onSelectionChanged(SelectionChangedEvent<MenuDto> event) {
            List<MenuDto> mnus = event.getSelection();
            Info.display("Tree Handler", mnus.get(0).getDescripcion());
        }
    });
+1
source

Figured it out. This can be achieved using the Cell Action Tree, an implementation of which can be found here: http://www.sencha.com/examples/#ExamplePlace:cellactiontree

0
source

All Articles