Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » menu visibleWhen
menu visibleWhen [message #1122627] Tue, 01 October 2013 19:34 Go to next message
Kevin Regan is currently offline Kevin ReganFriend
Messages: 33
Registered: May 2013
Member
I have added a menu item to the right click Project Explorer menu but cannot get the visibleWhen to work. I have tried various different core expressions and regardless what I put in there the menu does not show up (it does show up if I remove the entire visibleWhen section). I want it to show up if the selected project has my custom nature on it.

First attempt:
<extension
         point="org.eclipse.ui.menus">
         <menuContribution
         	locationURI="popup:org.eclipse.jdt.ui.PackageExplorer?after=additions">
         	<command
         		commandId="myCommand"
         		label="Test">
         		<visibleWhen checkEnabled="false">
				<adapt type="org.eclipse.core.resources.IProject">
         				<test property="org.eclipse.core.resources.projectNature" value="myProjectNature"/>
         			</adapt>

         		</visibleWhen>
         	</command>         	
         </menuContribution>
   </extension>


Then I tried changing the adapt type to IResource - still no luck. I also tried using the standard JavaCore.NATURE_ID. Next:
<extension
         point="org.eclipse.ui.menus">
         <menuContribution
         	locationURI="popup:org.eclipse.jdt.ui.PackageExplorer?after=additions">
         	<command
         		commandId="myCommand"
         		label="Test">
			<visibleWhen>
         			<iterate operator="and">
         				<test property="org.eclipse.core.resources.projectNature" value="myProjectNature"/>
         			</iterate>         			
         		</visibleWhen>
         	
         	</command>         	
         </menuContribution>
   </extension>



<extension
         point="org.eclipse.ui.menus">
         <menuContribution
         	locationURI="popup:org.eclipse.jdt.ui.PackageExplorer?after=additions">
         	<command
         		commandId="myCommand"
         		label="Test">
			<visibleWhen>
         			<with variable="selection">         				
         				<iterate operator="and" ifEmpty="false">
         					<test property="org.eclipse.core.resources.projectNature" value="myProjectNature"/>         				
         				</iterate>
         			</with>         			
         		</visibleWhen>
			
         	
         	</command>         	
         </menuContribution>
   </extension>



Then I tried this one both with and without the iterate:

<extension
         point="org.eclipse.ui.menus">
         <menuContribution
         	locationURI="popup:org.eclipse.jdt.ui.PackageExplorer?after=additions">
         	<command
         		commandId="myCommand"
         		label="Test">
			<visibleWhen checkEnabled="false">
         			<with variable="selection">
         				<iterate>
         					<instanceof value="org.eclipse.core.resources.IProject"/>
         				</iterate>   
         			</with>         			
         		</visibleWhen>
         	</command>         	
         </menuContribution>
   </extension>


The fact that none of these work make me think maybe something more fundamental is going on. Hoping someone here can help me out.... what am I doing wrong??

[Updated on: Tue, 01 October 2013 19:35]

Report message to a moderator

Re: menu visibleWhen [message #1122642 is a reply to message #1122627] Tue, 01 October 2013 19:53 Go to previous message
Kevin Regan is currently offline Kevin ReganFriend
Messages: 33
Registered: May 2013
Member
Well, nevermind - I figured it out. Apparently none of my attempts was properly identifying the thing to test - this did the trick:

<visibleWhen checkEnabled="false">
         			<with variable="activeMenuSelection">
         				<iterate ifEmpty="false">
         					<adapt type="org.eclipse.core.resources.IProject">
         						<test property="org.eclipse.core.resources.projectNature" value="myProjectNature"/>
         					</adapt>
         				</iterate>
         			</with>         			         			
         		</visibleWhen>
Previous Topic:How to use Eclipse Ant Task from Java Code
Next Topic:deprecated Activator
Goto Forum:
  


Current Time: Sat Nov 22 13:28:54 GMT 2014

Powered by FUDForum. Page generated in 0.01803 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software