Right Click ContextMenu on Tree

Hey people,

I’ve been trying to implement a ContextMenu opening when right clicking on a node in a tree, but to no avail. There were snippets of this in other threads regarding the ContextMenu component, but nothing substantial. My current implementation is below:

ContextMenu contextMenu = new ContextMenu();
                ContextMenuItem settings = contextMenu.addItem("Settings");
                ContextMenuItem start = contextMenu.addItem("Start Engine");
                ContextMenuItem stop = contextMenu.addItem("Stop Engine");
                contextMenu.setOpenAutomatically(true);
                contextMenu.setAsContextMenuOf(tree);

I also added a TreeListener, and found the code executed within it, but still a ContextMenu was never opened.
I also tried using contextMenu.open(x, y) but this still produced no results.

I’m sure there’s something small and silly that I’m missing, but I just can’t figure it out. Any help would be much appreciated.

Thanks,

Patrick

How about using action handlers?

tree.addActionHandler(new Handler() {

            @Override
            public void handleAction(Action action, Object sender, Object target) {
                if ("Settings".equals(action.getCaption())) {
                    Notification.show("Hello there");
                }
            }

            @Override
            public Action[] getActions(Object target, Object sender) {
                Action act1 = new Action("Settings");
                Action act2 = new Action("Start Engine");
                Action act3 = new Action("Stop Engine");

                return new Action[] { act1, act2, act3 };

            }

        });