(Tree component) How to get action from a specific tree item

Following these example, I would like to know how to get action from individual items from a tree, so they can be used invoke other events when clicked.?

final Object[][]
 planets = new Object[][]
{
        new Object[]{"Mercury"}, 
        new Object[]{"Venus"},
        new Object[]{"Earth", "The Moon"},    
        new Object[]{"Mars", "Phobos", "Deimos"},
        new Object[]{"Jupiter", "Io", "Europa", "Ganymedes", "Callisto"},
        new Object[]{"Saturn", "Titan", "Tethys", "Dione", "Rhea", "Iapetus"},
        new Object[]{"Uranus", "Miranda", "Ariel", "Umbriel", "Titania", "Oberon"},
        new Object[]{"Neptune", "Triton", "Proteus", "Nereid", "Larissa"}};
        
Tree tree = new Tree("The Planets and Major Moons");

/* Add planets as root items in the tree. */
for (int i=0; i<planets.length; i++) {
    String planet = (String) (planets[i]
[0]
);
    tree.addItem(planet);
    
    if (planets[i]
.length == 1) {
        /* The planet has no moons so make it a leaf. */
        tree.setChildrenAllowed(planet, false);
    } else {
        /* Add children (moons) under the planets. */
        for (int j=1; j<planets[i]
.length; j++) {
            String moon = (String) planets[i]
[j]
;
            
            /* Add the item as a regular item. */
            tree.addItem(moon);
            
            /* Set it to be a child. */
            tree.setParent(moon, planet);
            
            /* Make the moons look like leaves. */
            tree.setChildrenAllowed(moon, false);
        }

        /* Expand the subtree. */
        tree.expandItemsRecursively(planet);
    }
}

main.addComponent(tree);

There are two ways:

  1. Activate selections for three so that you can get en event each time some tree item is selected (clicked with mouse): http://toolkit.itmill.com/demo/doc/api/com/itmill/toolkit/ui/Tree.html#setSelectable(boolean)
    And then just add an value change listener for the tree.

  2. Add actions for the tree. This allows clicking each tree item with right-mouse button to get popup-menu that sends action events to your code:http://toolkit.itmill.com/demo/doc/api/com/itmill/toolkit/event/Action.Container.html#addActionHandler(com.itmill.toolkit.event.Action.Handler)
    This way you can show different popup-menu options for each tree item and get both the clicked item as well as selected popup menu action in the action event.