Add ability to dynamically disable a right click popup menu item for Tree

Hi,

This is my first question at ITMill.

I added a Ticket #2461: “Add ability to dynamically disable a right click popup menu item for Tree”, and then I realized that maybe I should have asked in the forum instead. Please let me know what the guidelines are for creating a ticket or asking a question on a forum.

In any case, here is the text from the ticket, if this is the right place to ask the question:

Currently (as I understand it), right click popup menu items on a Tree popup are rendered, based on the Action getIcon() and getCaption() values. I am unable to find any way to disable the individual menu items, like I can for items in the new MenuBar (by calling MenuItem.setCommand(null).

The only workaround I can think of for the moment, is to use HTML for the caption, and change the caption text colour to be (say grey - to “look” disabled), and perform no processing in the Action.Handler.handleAction() when the right click menu item is clicked.

Are you planning to add an explicit isEnabled(), or similar mechanism to the Action interface, to allow a menu item in the right click popup menu to be dynamically disabled ? If not, can you think of any better workarounds ?

Thanks
Andrew

Hi,

You’re right, currently you have to remove the action if it’s not supposed to do anything, but from a usability standpoint it would in many cases be better to disable the action.

And yes, it’s better to ask on the forum before adding a ticket - it often leads to less duplicates, and better, and sometimes a solution right away. Also, if the ticket is misunderstood, it can be closed as ‘invalid’ or something, even if it’s valid.
However, this is IMO a obvious “ticket, please” :slight_smile:

Best Regards,
Marc

Hi there,

I have a similar issue using Vaadin 6.7.0, and have had a hope for ‘dynamic context menu’ generation especially when doing right-click on a Table’s row entity. So, every table entity can have different set of actions dynamically checking some state talking to Service/DB in realtime.

However, I’m going to implement my own solution rather than waiting forever. Here’s my plan.

As you know, com.vaadin.event.Action is simply a data container focused on UI rendering. However, you can create your own class extended, which includes certain business logic that helps to decide whether to display or not. So, for instance, the ‘MyAction.display()’ returns a boolean value. Of course, you can extend this return value with some available display options specific to your application.

Now, ‘MyActionHandler’ implementing com.vaadin.event.Handler should have ‘Action getActions(Object, Object)’ that will call MyAction.display() for every Action and return only available Action(s). To make this work conveniently, ‘MyActionHandler’ might need to keep all available Actions at its initial instantiation state.

I will try this solution soon, but please let me know also how it works out for you, or at least what you think.

Thanks,
Brendan