How to disable a context menu item?


Please see demo link
. Right click the tree, a context menu is displayed.

Is it possible to disable a menu item? e,g, if I know a node is a leaf, it shouldn’t do the action of “Add child item”.



I don’t think you’re able to disable an item from the menu; disable as in having it visible but grayed out. However, you can remove some actions for the item IDs you want. In the following method of the action handler, the target parameter will be the itemId from the container of the tree. You can return the actions you want based on this itemId.

public Action[] getActions(Object target, Object sender) { ... }


For better user experience, it’s usual to set menu item grey. So I really wonder whether the feature can be realized in vaadin. If cannot, removing grey items from action list look like the only option.

What is better depends on the situation - graying them out lets you keep the same menu structure at all times and gives information about what actions might be available in another context, but at the same time can make scanning through and using long menus quite tedious.

You could
create an enhancement request
about having that option available.

FYI, I created an issue for this.

Is there another/better way to have getActions() called from handleAction() besides table.refreshRowCache()?