Right click does not seem to be supported correctly in Trees.
If the tree.setImmediate(false) is set (the default), then right click works just fine.
However, if tree.setImmediate(true) is set, then right click does not work properly. The click event is added to the event queue but does not get sent until another event occurs.
Sample application
public class TestApplication extends com.vaadin.Application {
@Override
public void init() {
final Window mainWindow = new Window("Test");
mainWindow.getContent().setSizeFull();
Tree tree = new Tree("Test");
tree.addContainerProperty("caption", String.class, "");
for (int i = 1; i <= 10; i++) {
String item = "Node " + i;
tree.addItem(item);
tree.getContainerProperty(item, "caption").setValue("Caption " + i);
tree.setChildrenAllowed(item, false);
}
tree.setItemCaptionMode(Tree.ITEM_CAPTION_MODE_PROPERTY);
tree.setItemCaptionPropertyId("caption");
//THIS IS THE PROBLEM. CHANGING THIS TO FALSE WILL MAKE RIGHT CLICK WORK
//BUT POTENTIALLY BREAK OTHER THINGS
tree.setImmediate(true);
tree.addListener(new ItemClickEvent.ItemClickListener() {
@Override
public void itemClick(ItemClickEvent event) {
switch (event.getButton()) {
case ItemClickEvent.BUTTON_LEFT:
mainWindow.showNotification("Left Click");
break;
case ItemClickEvent.BUTTON_MIDDLE:
mainWindow.showNotification("Middle Click");
break;
case ItemClickEvent.BUTTON_RIGHT:
mainWindow.showNotification("Right Click");
break;
}
}
});
mainWindow.addComponent(tree);
setMainWindow(mainWindow);
}
}
If I’m not mistaken, the problem is in fireClick(Event evt) method of the VTree.TreeNode class:
We experienced something similar, but found we didn’t need it to work if right click was supposed to open an action handler menu of items.
That is, our Tree subclass implements both ItemClickListener and Action.Hanlder. We then created two distinct Action arrays, one for our non-views (parent nodes that do not themselves do anything in our navigation tree) and one for nodes that do trigger a view to be opened (with our handing Open in Tab, Open in Window or Open in Browser New Window).
Then in the getActions method, if the item is defined to open a view, we return the array with the 3 open choices, otherwise we return our “no actions” (couldn’t figure out a way to just not have any actions associated since return null or "new Action[0]
" would result in “splotch” appearing, so we return a 1 element array with “(n/a)” in it and ignore it be chosen).
Then in our handleAction method, we do the appropriate thing based on which of the item actions was selected.
Before the handleAction is called, somehow the right click event arrives only after the action is chosen (with a left click of course!) and does call our itemClicked() method, but we just ignore right click since it doesn’t do anything itself and we wait for the handleAction to be called right after.
Maybe that will help in your case since a right click by itself rarely does an action but produces a context menu choice.
I worked around it, but it wasn’t an ideal solution.
My plan was to use the ContextMenu add-on from the directory so that I could use nested context menus as opposed to the single level that is supported out of the box.
It would be nice to add that feature to the main distribution.
Instead, the choice that would have expanded to a sub-context menu now opens a dialog box. Not nearly as elegant but it does the job.
The reason for that is explained in my previous post. The right click is being added to the queue of data to be sent to the server, but isn’t sent until another action (in your case the left click) takes place.
I’m experiencing also this issue (Vaadin 6.5.3). Setting setImmediate to false solves the problem, but that is not an option. Should I create a ticket or is there already one?
Does anyone know if this issue is fixed in 6.7.8?
According to http://dev.vaadin.com/ticket/6845 this should be the case, but I’m still having the problem that if immediate is true, the right click event is not noticed.