This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 383815 - <visibleWhen> has no effect for dynamic menu contributions
Summary: <visibleWhen> has no effect for dynamic menu contributions
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 4.2.2   Edit
Assignee: Paul Elder CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 387657 (view as bug list)
Depends on:
Blocks: 358936
  Show dependency tree
 
Reported: 2012-06-28 10:50 EDT by Hristo Bojilov CLA
Modified: 2013-01-29 11:42 EST (History)
6 users (show)

See Also:


Attachments
Proposed Fix (780 bytes, patch)
2013-01-10 14:24 EST, Paul Elder CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Hristo Bojilov CLA 2012-06-28 10:50:23 EDT
Build Identifier: I20120608-1400

I have popup menu extension which has custom property tester for controlling visibility.

Reproducible: Always

Steps to Reproduce:
Let say:

<extension point="org.eclipse.ui.menus">
 <menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions">
         <dynamic
               id="com.mycompany.menu"
               class="com.mycompany.TestMenu">
            <visibleWhen>
	             <reference definitionId="com.mycompany.selection"/>
            </visibleWhen>
         </dynamic>
 </menuContribution>
</extension>
   
<extension point="org.eclipse.core.expressions.definitions">
 <definition id="com.mycompany.selection">
   <with variable="selection">
    <count value="1"/>
     <iterate>
      <adapt type="org.eclipse.core.resources.IProject">
	<and>
	  <test property="org.eclipse.core.resources.open" value="true"/>
	  <test property="com.mycompany.matchesPattern" forcePluginActivation="true"/>
        </and>
     </adapt>              
    </iterate>
   </with>
 </definition>
</extension>
   
<extension point="org.eclipse.core.expressions.propertyTesters">
 <propertyTester id="com.mycompany.propertyTester"
   type="org.eclipse.core.resources.IProject"
   namespace="com.mycompany"
   properties="matchesPattern"
   class="com.mycompany.TestMenuPropertyTester">
 </propertyTester>
</extension>

package com.mycompany;

import org.eclipse.core.expressions.PropertyTester;
...

public class TestMenuPropertyTester extends PropertyTester{
  public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    ...
    return false;
  }
}

The problem is that property tester check is never called and my context menu contribution is always visible.Exactly the same code worked fine on older eclipse versions such as 3.7.2 but it's broken-down now.
Comment 1 Paul Webster CLA 2012-06-28 13:31:05 EDT
Has your plugin been activated?  Does it make any difference if you use activeMenuSelection instead of selection in your with element?

PW
Comment 2 Hristo Bojilov CLA 2012-06-29 02:47:05 EDT
Yes, BundleActivator.start method was called before I opened the context menu.I've set forcePluginActivation="true" to ensure eager activation of my plug-in.It doesn't matter if I use activeMenuSelection or selection unfortunately I've got the same problem.
Comment 3 Martin Oberhuber CLA 2012-11-08 04:35:50 EST
CQ:WINDE4BLOCKING

This issue is blocking Wind River's adoption of Eclipse 4.x - we're going to stay on 3.x until this is fixed.
Comment 4 Brian de Alwis CLA 2012-11-12 13:51:06 EST
*** Bug 387657 has been marked as a duplicate of this bug. ***
Comment 5 Kevan Holdaway CLA 2012-11-30 09:55:27 EST
I am seeing the same issue in an IBM product.

<menuContribution locationURI="popup:org.eclipse.ui.popup.any?before=additions">
	<dynamic class="MyClass" id="MyId">
		<visibleWhen checkEnabled="false">	
			// some property testing
		</visibleWhen>
	</dynamic>
</menuContribution>

This worked fine in eclipse 3.6.2.  Not working at all in 4.2.1.
Comment 6 Paul Elder CLA 2013-01-10 14:24:27 EST
Created attachment 225470 [details]
Proposed Fix
Comment 8 Paul Elder CLA 2013-01-17 13:59:14 EST
Verified in 4.2.2 (M20130116-1800)
Comment 9 Paul Elder CLA 2013-01-29 11:42:39 EST
Verified in 4.3-I20130128-2000