Bug 377884 - @CanExecute is not executed using DirectItems
Summary: @CanExecute is not executed using DirectItems
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.2.2   Edit
Assignee: Paul Webster CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-27 05:36 EDT by Kai Toedter CLA
Modified: 2013-06-06 10:55 EDT (History)
4 users (show)

See Also:


Attachments
Example to demonstrate the bug (12.26 KB, application/zip)
2012-04-30 04:13 EDT, Kai Toedter CLA
no flags Details
Proposed patch (4.15 KB, patch)
2012-06-20 19:25 EDT, Nobody - feel free to take it CLA
no flags Details | Diff
DirectTool Item example (16.61 KB, application/zip)
2013-06-06 10:44 EDT, Jonas Helming CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kai Toedter CLA 2012-04-27 05:36:12 EDT
When you have a DirectMenuItem, @CanExecute is not executed before the item is displayecd. Only after clicking.
Comment 1 Paul Webster CLA 2012-04-27 08:00:44 EDT
It's supposed to be called on SWT.Show by org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRendererFilter.updateElementVisibility(MMenu, MenuManagerRenderer, MenuManager, IEclipseContext, int, boolean)

:351 } else if (updateEnablement && element instanceof MDirectMenuItem) {

it will only be called if it has been instantiated already.

PW
Comment 2 Kai Toedter CLA 2012-04-30 04:13:44 EDT
Created attachment 214787 [details]
Example to demonstrate the bug

@Paul

attached you find an example project. It has a DirectMenuItem and a HandledMenuItem in the File menu. The corresponding handler returns always "false" on the method that is annotated with @CanExecute.

While the HandledMenuItem behaves correctly, I would expect the DirectMenuItem being disabled, too. But it is enabled and only when you click on it, it will be disabled. This is a very confusing behavior and I consider it a bug.
Comment 3 Paul Webster CLA 2012-04-30 07:55:59 EDT
(In reply to comment #2)
> 
> While the HandledMenuItem behaves correctly, I would expect the DirectMenuItem
> being disabled, too. But it is enabled and only when you click on it, it will
> be disabled. This is a very confusing behavior and I consider it a bug.

OK, this is the lazy loading behaviour, where it's only called if instantiated already.

It differs slightly from the default platform behaviour, because DirectContribuitonItem doesn't force loading of the contribution for a @CanExecute if its contributing bundle is already active.

We should align this with the platform strategy.

PW
Comment 4 Nobody - feel free to take it CLA 2012-06-20 19:25:39 EDT
Created attachment 217657 [details]
Proposed patch
Comment 5 Marco Descher CLA 2012-09-24 07:29:51 EDT
Facing the same problem, will the patch make it into the next release?
Comment 6 Nobody - feel free to take it CLA 2012-09-24 07:31:36 EDT
The target milestone is 4.3 so it should be on Kepler.

Paul, what do you think?
Comment 7 Paul Webster CLA 2012-09-24 08:01:51 EDT
Yes, this will definitely be in Kepler.

PW
Comment 9 Paul Webster CLA 2013-01-17 13:51:11 EST
In M20130116-1800

PW
Comment 10 Paul Webster CLA 2013-01-17 13:55:49 EST
.
Comment 11 Jonas Helming CLA 2013-06-06 10:44:20 EDT
I think this is still valid for DirectToolItems, see attached example. The first ToolItem in the example is a direct, the second one a handled. If you click the save button, both should toggle their enabled state.
Comment 12 Jonas Helming CLA 2013-06-06 10:44:55 EDT
Created attachment 232046 [details]
DirectTool Item example
Comment 13 Paul Webster CLA 2013-06-06 10:46:13 EDT
Please open a new bug.

PW
Comment 14 Paul Webster CLA 2013-06-06 10:46:22 EDT
.