Bug 367094 - [Compatibility] Programmatically created CommandContributionItems show wrong enablement state
Summary: [Compatibility] Programmatically created CommandContributionItems show wrong ...
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks: 350080 366920 372987
  Show dependency tree
 
Reported: 2011-12-19 11:03 EST by Markus Tiede CLA
Modified: 2019-11-26 05:48 EST (History)
5 users (show)

See Also:


Attachments
Patch (7.54 KB, patch)
2012-03-06 09:27 EST, Remy Suen CLA
no flags Details | Diff
Patch v02 (4.78 KB, patch)
2012-03-06 10:43 EST, Remy Suen CLA
no flags Details | Diff
Testsuite Browser Open and Show Specification (84.96 KB, image/png)
2012-05-03 06:52 EDT, Katrin Hofmann CLA
no flags Details
Testsuite Browser Open with context menu (84.37 KB, image/png)
2012-05-03 06:53 EDT, Katrin Hofmann CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Tiede CLA 2011-12-19 11:03:04 EST
Programmatically created CommandContributionItems do not reflect the enablement state of the corresponding command.

As already mentioned at bug 366920 comment 4 we, the Jubula team, are currently blocked by the wrong enablement state of programmatically created CommandContributionItem which we use for our view and editor context menus.
Comment 1 Paul Webster CLA 2011-12-19 11:30:30 EST
This works for most of our CCI contributions, but not for yours.  I'm investigating.

PW
Comment 2 Paul Webster CLA 2011-12-19 11:36:47 EST
OK, this might be related to the command/handler isEnabled() support.

PW
Comment 3 Paul Webster CLA 2011-12-19 15:06:26 EST
This is fixed in the latest 4.2 I build, I20111216-1500, as part of the fixes for bug 366560.  The problem was Command#isEnabled() was always returning true and that was effecting the state of the CommandContributionItem in popup menus.

I tested it in the Sample view with context menu entries:
CommandContributionItemParameter copyParm = new CommandContributionItemParameter(getSite(), "copy", IWorkbenchCommandConstants.EDIT_COPY, CommandContributionItem.STYLE_PUSH);
manager.add(new CommandContributionItem(copyParm));

and a copy handler that was enabled based on:
selection obj;
obj instanceof TreeObject && !(obj instanceof TreeParent)

PW
Comment 4 Paul Webster CLA 2012-01-24 13:12:06 EST
In I20120123-2200

PW
Comment 5 Markus Tiede CLA 2012-03-05 06:00:14 EST
This issue does not seem to be completely fixed: closing bug 366920 confirmed that the initial UI enablement state for programmatically created CommandContributionItems is now correct when initially opening the menu, but bug 372987 reports that this enablement state does not continuously and correctly reflects the enablement state of the command over time.

Could it be possible that the enablement state does not get updated / reevaluated, e.g. if the selection in a part changes?
Comment 6 Paul Webster CLA 2012-03-05 08:19:35 EST
The handler is what determines the enabled state.  When the state is incorrect, how is the handler determining its state?

I'm also not sure about bug 372987 comment #3

You mention delete is incorrect, but it is enabled in both the before and after image?  Is it supposed to be disabled in the before but not in the after?

PW
Comment 7 Markus Tiede CLA 2012-03-05 09:14:55 EST
Thank you for the quick reply - I hope the inline comments will clarify the problem:

(In reply to comment #6)
> The handler is what determines the enabled state.  When the state is incorrect,
> how is the handler determining its state?

I assume that the state of the handler is "disabled / not active". E.g. clicking on the wrongly enabled entry of the mentioned "delete"-command menu does not execute the corresponding handler.

> I'm also not sure about bug 372987 comment #3
> 
> You mention delete is incorrect, but it is enabled in both the before and after
> image?  Is it supposed to be disabled in the before but not in the after?

Not exactly - the delete command is supposed to be disabled for this kind of tree node (non-editable == non-deletable child node). I assume that our tester initially selected a deletable node (which caused the command to have an active handler [==enable it's UI state]) and after that a non-deletable node (which is then shown in the screenshot). 

I am also able to manually reproduce this behavior, first selecting a node for which a certain command has an active handler (context menu gets correctly enabled) - after that selecting another node for which the command has no active handler (context menu stays enabled) and vice versa.

> PW
Comment 8 Paul Webster CLA 2012-03-05 09:48:14 EST
(In reply to comment #7)
> 
> I assume that the state of the handler is "disabled / not active". E.g.
> clicking on the wrongly enabled entry of the mentioned "delete"-command menu
> does not execute the corresponding handler.

That's the code I'm interested in.  You are clicking on a node and depending on if it is read-only or not you expect the handler to enabled/disabled.  Where does the handler determine its active state? 

PW
Comment 9 Markus Tiede CLA 2012-03-05 10:07:16 EST
One of the most basic <activeWhen>...-statements can be found here

http://git.eclipse.org/c/jubula/org.eclipse.jubula.core.git/tree/org.eclipse.jubula.client.ui.rcp/plugin.xml#n1739

It shows the enablement / activeWhen for a "rename"-handler (which should also be disabled in the context menu for a non-editable tree node).

The enablement logic is this: renaming should only be possible for a single selected element which is either an editable category or an editable (so called) SpecTestCase. Though there are multiple handlers for this command "org.eclipse.ui.edit.rename" non of them enables via <instanceof ...> for a (in the UI selected) ExecTestCase node.
Comment 10 Remy Suen CLA 2012-03-05 10:13:05 EST
I tried running Jubula on 3.8M5 to compare the behaviour but got this error. What did I do wrong, Markus?

Caused by: org.osgi.framework.BundleException: Exception in org.eclipse.jubula.client.core.Activator.start() of bundle org.eclipse.jubula.client.core.
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
	at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
	at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:263)
	at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
	... 47 more
Caused by: java.lang.ClassCastException: org.slf4j.helpers.NOPLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext
	at org.eclipse.jubula.client.core.Activator.start(Activator.java:53)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
	... 53 more
Comment 11 Markus Tiede CLA 2012-03-05 10:30:41 EST
We currently experience major inter-project issues which prevents Jubula from working. The one you experience is bug 370807. As a manual workaround for that please see bug 370807 comment #1.

You may also modify your environment as mentioned in bug 371350 - EclipseLink also currently contains a blocking issue for Jubula.

The easiest way to reproduce this issue is to
 - download the Juno M5 version of "Eclipse for Testers" : http://build.eclipse.org/technology/epp/epp_build/juno/download/20120202-1517/
 - unpack the package and manually remove the bundles
  - javax.persistence_2.1.0.v201201251030.jar
  - org.slf4j.api_1.6.4.v20111214-2030
 - start eclipse
 - open "Test --> Open..."
 - wait for auto db-connection and project import; after that open the preselected project "unbound_modules_concrete"
 - verify the behavior in the "Test Case Browser" when opening the context menu for: "Test Cases: --> Actions (basic) --> Activate Application --> ub_app_activate_AUTDefault" this node should be rename-able, but non of his children.
Comment 12 Remy Suen CLA 2012-03-05 16:22:47 EST
I've reproduced the problem with Jubula and have also reproduced the issue with a smaller plug-in project. Unfortunately, I haven't yet figured out the cause yet.

Moving to M6 since M5 has shipped.
Comment 13 Remy Suen CLA 2012-03-05 16:56:12 EST
First problem is that we don't track the variable access of the selection. This explains why the handler proxy never got an enablement change. Even when it gets this change, no events are fired because the handler proxy itself has no listeners attached to it.
Comment 14 Remy Suen CLA 2012-03-06 09:27:36 EST
Created attachment 212132 [details]
Patch

I've made changes to the EvaluationService so that accesses to the default variable are actually tracked and to the HandlerProxy so that handler change events will be propagated to the MHG that is connected to the command. This will allow the command to receive notifications should the HandlerProxy change.
Comment 15 Remy Suen CLA 2012-03-06 10:43:05 EST
Created attachment 212137 [details]
Patch v02

Changed to wrap the logic in E4HandlerProxy.
Comment 16 Remy Suen CLA 2012-03-06 13:53:31 EST
(In reply to comment #15)
> Created attachment 212137 [details]
> Patch v02

Patch pushed to master.
http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=844bbce93cf313a819b87c3ed48d1b5ff4a47e21

Thanks for the bug reports, Markus!
Comment 17 Remy Suen CLA 2012-03-08 08:02:56 EST
The 'Rename' menu item is now enabled/disabled correctly with the latest  I20120307-2200 build.
Comment 18 Paul Webster CLA 2012-03-13 11:28:54 EDT
In I20120313-0610
PW
Comment 19 Markus Tiede CLA 2012-04-17 02:55:23 EDT
Unfortunately I am only able to partially agree - though (framework defined) commands like 'Rename' or 'Delete' do now seem to (in Juno M6 Eclipse for Testers) enable / disable correctly, there are still some (the only difference I am sure of is that they are not pre-defined) commands which does not correctly enable / disable e.g. in the our "Test Suite Browser"-view the command 'show specification'.

The activeWhen-status of one of the handler can be found here: http://git.eclipse.org/c/jubula/org.eclipse.jubula.core.git/tree/org.eclipse.jubula.client.ui.rcp/plugin.xml#n2920

It's based on various states (variable, selection count, selection type) which are all "ANDed" and at least the instanceof should be *false* for "Test Suites" being selected in our "Test Suite Browser". This commands menu enablement state gets as well falsely enabled as well as disabled.

There are also some other commands which are affected by this. In a 3.x environment these commands do not show any problems.
Comment 20 Paul Webster CLA 2012-04-17 07:56:00 EDT
Michael, could you have a look at this?

Markus, where's a good site to get the version of Jubula you're working with?  We'll need to install it into our latest 4.2 I build as there have been a lot of code changes since M6.

PW
Comment 21 Markus Tiede CLA 2012-04-17 08:16:23 EDT
I used the EPP version of Jubula "Eclipse for Testers" - available from http://www.eclipse.org/downloads/index-developer.php

If you're looking for the most recent installable Jubula feature you could just use the last successful build artifact from our jubula-juno hudson job:
https://hudson.eclipse.org/hudson/job/jubula-juno/lastSuccessfulBuild/artifact/jubula/org.eclipse.jubula.site/target/packed/site_assembly.zip

The one which is currently included in M6 can be found here:
http://download.eclipse.org/jubula/milestones/juno-m6
Comment 22 Michael Rennie CLA 2012-04-17 11:31:12 EDT
(In reply to comment #20)
> Michael, could you have a look at this?
> 

Sure, I have just installed Jubula, now I just have to figure out how to use it :)
Comment 23 Michael Rennie CLA 2012-04-18 10:34:01 EDT
(In reply to comment #22)
> (In reply to comment #20)
> > Michael, could you have a look at this?
> > 
> 
> Sure, I have just installed Jubula, now I just have to figure out how to use it
> :)

Markus, I managed to get Jubula installed, but once installed I could not do anything with it. Is there a simple tutorial, etc that you could point me to so that I can test?
Comment 24 Markus Tiede CLA 2012-04-18 12:05:59 EDT
I am not sure how and what you've currently installed from Jubula - but you could try to perform the "First steps"-cheatsheet or the steps from comment 11: verify the behavior in the "Test Case Browser" when opening the context menu
for: "Test Cases: --> Actions (basic) --> Activate Application -->
ub_app_activate_AUTDefault" this node should *not* show the entry "Show specification" as enabled, but all of his children. Based on which element gets selected first either the enablement or disablement for the node itself or it's children is wrong.
Comment 25 Michael Rennie CLA 2012-04-18 14:32:32 EDT
(In reply to comment #24)
> I am not sure how and what you've currently installed from Jubula - 

I installed everything that was available from: 
https://hudson.eclipse.org/hudson/job/jubula-juno/lastSuccessfulBuild/artifact/jubula/org.eclipse.jubula.site/target/packed/site_assembly.zip


> could try to perform the "First steps"-cheatsheet or the steps from comment 11:
> verify the behavior in the "Test Case Browser" when opening the context menu
> for: "Test Cases: --> Actions (basic) --> Activate Application -->
> ub_app_activate_AUTDefault" 

The problem was that I had to open the "Functional Test Execution" perspective to have the 'Test' main menu item show up. Once opened and selecting a variety of elements the 'Open Specification' command appeared to correctly enable / disable.

Markus can you confirm?

Note I was testing using:
Version: 4.2.0
Build id: N20120417-2000
Comment 26 Markus Tiede CLA 2012-04-27 04:10:55 EDT
I am not sure which actual components (Version: 4.2.0 Build id: N20120417-2000) and installation path you used to confirm this. Could you please provide more information how to setup the configuration (eclipse version) you used to verify this?
Comment 27 Paul Webster CLA 2012-04-27 07:55:22 EDT
(In reply to comment #26)
> I am not sure which actual components (Version: 4.2.0 Build id: N20120417-2000)
> and installation path you used to confirm this. Could you please provide more
> information how to setup the configuration (eclipse version) you used to verify
> this?

To confirm, you would use one of our warm-up I builds, like http://download.eclipse.org/eclipse/downloads/drops4/I20120426-0800/

+ the Jubula link mentioned in comment #25

PW
Comment 28 Katrin Hofmann CLA 2012-05-03 06:52:12 EDT
Created attachment 214984 [details]
Testsuite Browser Open and Show Specification
Comment 29 Katrin Hofmann CLA 2012-05-03 06:53:00 EDT
Markus asked me to repeat the test for this bug with following installation:
- Eclipse SDK	4.2.0.I20120426-0800	
- Jubula 1.2.1.201204271118
- Jubula Database Drivers 1.0.0.201106151822

Unfortunately the wrong enablement of context menu items still persists, e.g. for Testsuite Browser context menu(s.attachments of Test Suite Browser context menu).

Following items have a wrong state:
- Open Specification
- Show Specification
- Open with Testsuite Editor
- Open with Objectmapping Editor

Furthermore I miss the keyboard shortcuts in Open Specification and Show Specificaton item. 

The enablement of delete item in Test Suite Browser seems to be alright now.

I plan to test further scenarios next days.
Comment 30 Katrin Hofmann CLA 2012-05-03 06:53:53 EDT
Created attachment 214985 [details]
Testsuite Browser Open with context menu
Comment 31 Katrin Hofmann CLA 2012-05-03 06:56:05 EDT
Is there any new version of Eclipse SDK integration build I could test?
Comment 32 Paul Webster CLA 2012-05-03 07:17:42 EDT
(In reply to comment #31)
> Is there any new version of Eclipse SDK integration build I could test?

Our integration builds are here: http://download.eclipse.org/eclipse/downloads/

The latest build which is our M7 candidate is http://download.eclipse.org/eclipse/downloads/drops4/I20120502-1800/

PW
Comment 33 Katrin Hofmann CLA 2012-05-04 03:25:13 EDT
Multiple problems with wrong enablement state also occurs with M7 candidate Eclipse SDK 4.2.0.I20120502-1800.

I will create single tickets for each topic.
Comment 34 Paul Webster CLA 2012-05-04 07:42:08 EDT
(In reply to comment #33)
> 
> I will create single tickets for each topic.

That's not necessary unless we determine they are caused by different problems.

In the last context menu snpatshot you attached, 3 of the menu items were disabled.  Are they created by this code: http://git.eclipse.org/c/jubula/org.eclipse.jubula.core.git/tree/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/views/TestSuiteBrowser.java#n157

PW
Comment 35 Zeb Ford-Reitz CLA 2012-05-04 08:15:35 EDT
> In the last context menu snpatshot you attached, 3 of the menu items were
> disabled.  Are they created by this code:
> http://git.eclipse.org/c/jubula/org.eclipse.jubula.core.git/tree/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/views/TestSuiteBrowser.java#n157
> 
> PW

Yes, all 4 context menu contributions (also the enabled one) are created with the referenced code.
Comment 36 Zeb Ford-Reitz CLA 2012-05-07 05:37:06 EDT
bug 378467 (applied to Test Suite Browser) seems to be a simple way to reproduce the error. Essentially:
 0. Functional Test Specification Perspective is active, and a Project with Test Suites containing references to Test Cases is open.
 1. Open a Test Suite in the Test Suite Editor.
 2. Open context menu on a Test Suite in the Test Suite Browser. Menu item enablement is correct. Do *not* close context menu.
 3. (Left) click on Test Suite in Test Suite Editor. The "Add Test Case Reference" dialog appears. This should not occur, but this error is captured in bug 378467.
 4. Cancel the dialog.
 5. Open context menu on a Test Suite in the Test Suite Browser. Several items that should be enabled are instead disabled.

The enablement state can be corrected by closing the Test Suite Browser and then opening it again.
Comment 37 Eric Moffatt CLA 2012-05-07 10:15:19 EDT
Moving to RC1...
Comment 38 Paul Webster CLA 2012-05-23 07:49:18 EDT
(In reply to comment #34)
> In the last context menu snpatshot you attached, 3 of the menu items were
> disabled.  Are they created by this code:
> http://git.eclipse.org/c/jubula/org.eclipse.jubula.core.git/tree/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/views/TestSuiteBrowser.java#n157


This code has changed (because of a fix in Jubula).  I can't reproduce this problem with my example CommandContributionItem (it's enabled/disabled by my handler).  Is it no longer an issue?

PW
Comment 39 Zeb Ford-Reitz CLA 2012-05-23 08:08:42 EDT
(In reply to comment #38)
> This code has changed (because of a fix in Jubula).  I can't reproduce this
> problem with my example CommandContributionItem (it's enabled/disabled by my
> handler).  Is it no longer an issue?
> 
> PW

We've been converting Jubula's context menus from programmatic to declarative as a mitigation strategy in case this bug is not resolved in time for Juno. I've performed this conversion for the Test Suite Browser, Test Case Browser, and Object Mapping Editor (the places where the error was reliably reproducible). Those changes are documented on bug 372987. As we seem to have found a functioning workaround, I'd say this is no longer an issue for Jubula. I don't know whether other projects are having similar difficulties and just haven't noticed yet (as it can be tricky to reproduce).
Comment 40 Eclipse Genie CLA 2019-11-26 05:48:39 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.