Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Add Action to the "Source" context menu
icon5.gif  Add Action to the "Source" context menu [message #547507] Sat, 17 July 2010 22:40 Go to next message
Michael Ernst is currently offline Michael ErnstFriend
Messages: 49
Registered: July 2010
Member
Hi,

I want to add my developed action to the "Source" context menu of the JDT. It should be enabled on a IJavaProject, IPackageFragment/Root, ICompilationUnit. So first I thought I should use an objectContribution but there is only a single type registrable. Than I used a viewerContribution, and it works fine. The context menu entry is shown. But each time the Runtime starts with a fresh plugin installation I get an entry in the Log:

Plug-in 'myPlugin' contributed an invalid Menu Extension (Path: 'org.eclipse.jdt.ui.source.menu' is invalid): myPlugin.action

plugin.xml:
<extension
point="org.eclipse.ui.popupMenus">
	<viewerContribution
		id="myPlugin.viewerContribution"
		targetID="org.eclipse.jdt.ui.PackageExplorer">
		<action
			class="myPlugin.ActionDelegate"
			id="myPlugin.action"
			label="%action.label"
		menubarPath="org.eclipse.jdt.ui.source.menu/myAction"/>
	</viewerContribution>
</extension>


What is the reason for this message, or is there another way to add an entry to the context menu?

Kind regards,
Michael
Re: Add Action to the "Source" context menu [message #549835 is a reply to message #547507] Wed, 28 July 2010 08:05 Go to previous messageGo to next message
Michael Ernst is currently offline Michael ErnstFriend
Messages: 49
Registered: July 2010
Member
Hi,

there are now more than 600 viewers and nobody has an idea how to contribute to the source menu of the JDT? Sad

I get the error each time I'm clicking on a Element which not provides a "Source" menu.

I played a little bit with the enablement-Tag but without any results.


Kind regards,
Michael
Re: Add Action to the "Source" context menu [message #549906 is a reply to message #547507] Wed, 28 July 2010 12:30 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Michael Ernst wrote:
>
> Plug-in 'myPlugin' contributed an invalid Menu Extension (Path:
> 'org.eclipse.jdt.ui.source.menu' is invalid): myPlugin.action
>
> plugin.xml:
>
> <extension
> point="org.eclipse.ui.popupMenus">
> <viewerContribution
> id="myPlugin.viewerContribution"
> targetID="org.eclipse.jdt.ui.PackageExplorer">
> <action
> class="myPlugin.ActionDelegate"
> id="myPlugin.action"
> label="%action.label"
> menubarPath="org.eclipse.jdt.ui.source.menu/myAction"/>
> </viewerContribution>
> </extension>

the menubarPath has to reference an existing group in the popupMenu,
probably not "myAction". Also, despite a viewerContribution being
added after an objectContribution, since an objectContribution may or
may not be there you cannot use a viewerContribution to add to an
objectContribution menu. Technically to add to the source menu you
would need an objectContribution that matches the one that provides the
source menu itself.

Since 3.3 org.eclipse.ui.menus allows you to contribute commands to
menus and toolbars in many locations. menu contributions can depend on
other menu contributions, unlike the legacy action contributions (like
popupMenus, except in a very few situations). They're also still under
active development.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Add Action to the "Source" context menu [message #550020 is a reply to message #547507] Wed, 28 July 2010 18:57 Go to previous messageGo to next message
Michael Ernst is currently offline Michael ErnstFriend
Messages: 49
Registered: July 2010
Member
Thanks for your reply,

Commands and org.eclipse.ui.menus was a good hint!

The command is now also visible in the editor's context menu!

I got a working solution now:
	<extension
	      point="org.eclipse.ui.commands">
	      <command
             id="command.mycommand"
             name="%action.label">
	      </command>
	</extension>
	
	<extension
	      point="org.eclipse.ui.menus">
		<menuContribution
        allPopups="true"
        locationURI="popup:org.eclipse.jdt.ui.source.menu?after=additions">
        	<separator
               name="mySeparator"
               visible="true">
        	</separator>
        	<command
               commandId="command.mycommand"
               style="push">
				<visibleWhen>
					<or>
						<with
		                     variable="activeMenuSelection">
							<iterate>
								<or>
									<adapt type="org.eclipse.jdt.core.IJavaProject"/>
									<adapt type="org.eclipse.jdt.core.IPackageFragment"/>
									<adapt type="org.eclipse.jdt.core.IPackageFragmentRoot"/>
									<adapt type="org.eclipse.jdt.core.ICompilationUnit"/>
								</or>
							</iterate>
						</with>
						<with variable="activeEditorId">
						      <equals value="org.eclipse.jdt.ui.CompilationUnitEditor" />
						</with>
					</or>
				</visibleWhen>
        	</command>
            <separator
                  name="additions"
                  visible="false">
            </separator>
		</menuContribution>
	</extension>
	
	<extension
	    point="org.eclipse.ui.handlers">
	    <handler
	          commandId="command.mycommand"
	          class="project.MyHandler">
	    </handler>
    </extension>


Kind regards,
Michael
icon14.gif  Re: Add Action to the "Source" context menu [message #649410 is a reply to message #550020] Wed, 19 January 2011 07:40 Go to previous message
Christophe Bismuth is currently offline Christophe BismuthFriend
Messages: 67
Registered: July 2009
Location: Paris, France
Member

Thank you for sharing.

Chris
Previous Topic:Error with decompiler editor
Next Topic:[SOLVED] MultiTextEdit overlap
Goto Forum:
  


Current Time: Thu Dec 18 18:38:46 GMT 2014

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

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