Bug 465893 - @CanExecute not evaluated for rendering of MDirectToolItems
Summary: @CanExecute not evaluated for rendering of MDirectToolItems
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.5   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.6 M1   Edit
Assignee: Dirk Fauth CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
: 410087 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-04-30 04:37 EDT by Dirk Fauth CLA
Modified: 2015-08-04 09:05 EDT (History)
5 users (show)

See Also:


Attachments
Eclipse 4 based application with part toolbar example (8.40 KB, application/x-zip-compressed)
2015-07-16 07:03 EDT, Dirk Fauth CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Fauth CLA 2015-04-30 04:37:35 EDT
I have created a handled menu item that evaluates @CanExecute for a modifiable value in the context.

@CanExecute
public boolean canExecute(@Optional @Named("EXIT_ENABLED") Boolean enabled) {
        return enabled != null ? enabled : false;
}

I have a menu item for enabling/disabling the handler by setting the value in the context, and sending the event for updating the menu items via event broker:

context.modify("EXIT_ENABLED", Boolean.FALSE);
broker.post(UIEvents.REQUEST_ENABLEMENT_UPDATE_TOPIC, UIEvents.ALL_ELEMENT_ID);

In a pure E4 application, this works fine. When the compatibility layer is involved, it doesn't work. 

On debugging we noticed that on pure e4 sending the event triggers the execution of @CanExecute, in compat mode it isn't.
Comment 1 Dirk Fauth CLA 2015-07-16 06:59:33 EDT
I need to correct this ticket. It is not related to the compatibility layer and does appear always.

The issue is related to MDirectToolItems. @CanExecute is never called for them, therefore the enabled state is not correctly evaluated on rendering tool items in a part toolbar.

This happens for Eclipse 4 applications aswell as for Eclipse 3 applications in compatibility mode.
Comment 2 Dirk Fauth CLA 2015-07-16 07:03:38 EDT
Created attachment 255240 [details]
Eclipse 4 based application with part toolbar example

This application is based on the Eclipse 4 template in PDE. The part has two menu items in the part toolbar, a handled menu item and a direct menu item. Both are connected to the same handler class.

Selecting item "One" in the viewer should disable the toolbar items, selecting the other should enable them.

The handled menu item is rendered disabled/enabled correctly, while the direct menu item is not. Note that the direct menu item is not executed if it is disabled, so regarding the functionality it is correct, but it is not rendered correctly according to the enabled state.
Comment 3 Thomas Schindl CLA 2015-07-16 07:08:11 EDT
IIRC e4 on SWT never supported @CanExecute on MDirect* - what I don't get is why it should not work for e3 compat mode apps? Are extension points really translated into MDirect*?
Comment 4 Dirk Fauth CLA 2015-07-16 07:21:06 EDT
(In reply to Thomas Schindl from comment #3)
> IIRC e4 on SWT never supported @CanExecute on MDirect* - what I don't get is
> why it should not work for e3 compat mode apps? Are extension points really
> translated into MDirect*?

Forget about the compat mode stuff. It appeared on migrating from E3 to E4. So currently we are in a mixed mode with e4views that create the toolbar programmatically, as the contribution of toolbar items via fragment is not working correctly. I just mentioned it because of the initial report.

So this ticket is invalid because it was never supported that way? Or is this a missing feature? I can see that for MDirectToolItems never an update is performed in the REQUEST_ENABLEMENT_UPDATE_TOPIC event handler.
Comment 5 Thomas Schindl CLA 2015-07-16 07:49:54 EDT
There's no reason why MDirect should not support @CanExecute and eg efxclipse does support it so it is perfectly valid to request the same from SWT
Comment 6 Lars Vogel CLA 2015-07-16 07:51:39 EDT
(In reply to Thomas Schindl from comment #5)
> There's no reason why MDirect should not support @CanExecute and eg
> efxclipse does support it so it is perfectly valid to request the same from
> SWT

+1
Comment 7 Eclipse Genie CLA 2015-07-16 07:58:40 EDT
New Gerrit change created: https://git.eclipse.org/r/52064
Comment 9 Dirk Fauth CLA 2015-07-16 16:29:29 EDT
Fixed with the above patch.

One question, can this be downported for SR1?
Comment 10 Thomas Schindl CLA 2015-07-16 16:37:18 EDT
Well this no regression so i think this is not suitable for SR
Comment 11 Lars Vogel CLA 2015-07-16 22:49:34 EDT
(In reply to Thomas Schindl from comment #10)
> Well this no regression so i think this is not suitable for SR

This is currently under discussion, the foundation thinks about a higher frequency of Eclipse releases. But as of now, we do not downport new functionality to SR, so Toms statement is correct.
Comment 12 Dirk Fauth CLA 2015-07-20 03:00:54 EDT
*** Bug 410087 has been marked as a duplicate of this bug. ***
Comment 13 Brian de Alwis CLA 2015-07-30 23:11:59 EDT
(In reply to Thomas Schindl from comment #3)
> IIRC e4 on SWT never supported @CanExecute on MDirect* - what I don't get is
> why it should not work for e3 compat mode apps? Are extension points really
> translated into MDirect*?

So just a point: Direct* supported @CanExecute but it was only evaluation on execution rather than properly used to determine the enablement status of the corresponding UI item.