Bug 378591 - [Contributions] Popupmenu: hide menu item by evaluating outcome of @CanExecute-annotated method
Summary: [Contributions] Popupmenu: hide menu item by evaluating outcome of @CanExecut...
Status: REOPENED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: All All
: P3 enhancement with 4 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-05 17:09 EDT by Heike Winkelvoß CLA
Modified: 2020-06-19 03:05 EDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Heike Winkelvoß CLA 2012-05-05 17:09:27 EDT
Build Identifier: Version: 4.2.0 Build id: I20120315-1300

In the e4xmi it should be possible to add a "Visible-When condition" to HandledMenuItems which evaluates the outcome of the @CanExecute-annotated method in the Handler-Class.

This should work in an similar manner as in Eclipse 3.x with the 
<visibleWhen checkEnabled="true"></visibleWhen>
part of the command-menu-contribution.

Reproducible: Always

Steps to Reproduce:
1.open the Application.e4xmi
2.select some popup menu -> HandledMenuItem
3.select a @CanExecute = true in the Combo "Visible-When Expression"
Comment 1 Christoph Keimel CLA 2012-05-07 07:43:47 EDT
I would prefer an additional @CanBeDisplayed (or @IsVisible) annotation which can optionally by applied to a handler method. I think this would be more flexible and straight forward to use.
 
- Next to the normal use cases, I can also think of the want to hide a menu item, but still have the command accessible through the key binding (i.e. user customization).
- It makes the handling similar to "@CanExecute". Higher level functions could use EHandlerService.canBeDisplayed() for processing.

The possibility to use core expressions should be an additional or alternative option.
Comment 2 Paul Webster CLA 2012-05-07 07:46:20 EDT
In general the handler is not responsible for UI element visibility, that has to be specified at the UI level when the menu or tool item is placed.

PW
Comment 3 Thomas Schindl CLA 2012-05-07 08:04:14 EDT
I would vote for a general solution to dynamic java visible-when calculations which are not only needed on HandleItems (Toolitem/MenuItem) but also on:
* Menu 
* Toolbar

The application model already has a notion of it (one has derive from MExpression). The renderer though can currently only work with MCoreExpression (they even blindly cast to it!).

In think in 4.3 we could make this more flexible by adding an abstraction
Comment 4 Lars Vogel CLA 2020-06-18 08:33:49 EDT
I think we have visible-when expressions since a while.

Rolf, can this one be closed?
Comment 5 Rolf Theunissen CLA 2020-06-18 14:29:07 EDT
Yes we have visible-when expressions. However, I am not aware of any expression that can be used to hide the menu item when the handler cannot execute. Furthermore, I don't think there is any tag on the item that could be added to accomplish similar behavior.
Comment 6 Lars Vogel CLA 2020-06-18 14:34:52 EDT
We do have code expressions which could define similar conditions as the can method so IMHO we have one way of solving the requirements here.

Marking as works for me.
Comment 7 Rolf Theunissen CLA 2020-06-18 14:39:35 EDT
Can you please provide me with an example how I could do this. I would be happily apply that in the products we are developing.
Note that there is no one-to-one relation between menu items and handlers, that is what the command infra structure is for. So what should my programmatic visible-when expression look like to call the @CanExecute of the current active handler?
Comment 8 Lars Vogel CLA 2020-06-18 15:23:30 EDT
(In reply to Rolf Theunissen from comment #7)
> Can you please provide me with an example how I could do this. I would be
> happily apply that in the products we are developing.
> Note that there is no one-to-one relation between menu items and handlers,
> that is what the command infra structure is for. So what should my
> programmatic visible-when expression look like to call the @CanExecute of
> the current active handler?

I think Bug 484398 implemented that, but tbh. I never used it in real projects. IIRC I tested it and it worked.
Comment 9 Rolf Theunissen CLA 2020-06-19 03:05:41 EDT
Bug 484398 provides another way to provide a visibility expression.

To accomplish hiding of menu items that do not have an handler that is active:
1. For direct menu items, you could add @CanExecute and @Evaluate on the same method. Then add the class-uri both to the DirectItem and to the Imperative active-when expression.
2. For handled menu items, an class should be created with an @Evaluate. In this method you should inject the handled menu item, get the command for the item, ask the handler service if the command is active (i.e. all that is needed to do the evaluation to decide if the menu item is active)

This all is clumsy, inconsistent and slow (due to multiple execution of the same code). I think that introducing a TAG for this would make more sense. The tag is similar to a check-mark on the menu item that states if it should be shown if it is inactive.