How to contribute to a sub menu of context menu? - eclipse

I am trying to define a sub menu entry in a viewpart's context menu.
I want to contribute a "Connection Profile" menu item in this sub menu through my own plugin, and I hope other plugin can also contribute menu items to this sub menu.
my plugin.xml
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:cn.ggfan.dmp.view.explorer">
<menu
id="new"
label="New">
</menu>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="menu:new?after=additions">
<command
commandId="cn.ggfan.dmp.commands.addCP"
label="Connection Profiles"
style="push">
</command>
</menuContribution>
</extension>
it doest work. what's wrong with my code?
----------------------- Edit -----------------------
If I define the submenu like this, it works. but I still don't know how to contribute to my "new" sub menu in other plugins.
<menuContribution
allPopups="false"
locationURI="popup:cn.ggfan.dmp.view.explorer">
<menu
id="new"
label="new">
<command
commandId="cn.ggfan.dmp.commands.addCP"
label="Connection Profiles"
style="push">
</command>
</menu>
</menuContribution>

finally, I got it, my "new" sub menu should be treated as a "popup" other than a "menu":
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:cn.ggfan.dmp.view.explorer">
<menu
id="cn.ggfan.new"
label="New">
<command
commandId="cn.ggfan.dmp.commands.addCP"
label="Connection Profile"
style="push">
</command>
</menu>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:cn.ggfan.new?after=additions">
<command
commandId="cn.ggfan.dmp.commands.addTable"
label="Table"
style="push">
</command>
</menuContribution>
</extension>

Try with menu:cn.ggfan.dmp.view.explorer rather than popup:cn.ggfan.dmp.view.explorer.
See Working with the menus extension point - a blog entry I wrote almost 6 years ago :-)

Related

Eclipse Plugin extension point org.eclipse.ui.command: how to change text?

EDIT: Here is the full plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.commands">
<category
name="TB Category"
id="TBPlugin.commands.category">
</category>
<command
name="fubar1"
categoryId="TBPlugin.commands.category"
id="TBPlugin.commands.sampleCommand">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="TBPlugin.commands.sampleCommand"
class="tbplugin.handlers.SampleHandler">
</handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="TBPlugin.commands.sampleCommand"
contextId="org.eclipse.ui.contexts.window"
sequence="M1+6"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
</key>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
label="TB"
mnemonic="M"
id="TBPlugin.menus.sampleMenu">
<command
commandId="TBPlugin.commands.sampleCommand"
mnemonic="S"
id="TBPlugin.menus.sampleCommand">
</command>
</menu>
</menuContribution>
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="TBPlugin.toolbars.sampleToolbar">
<command
commandId="TBPlugin.commands.sampleCommand"
icon="icons/sample.png"
tooltip="TB"
id="TBPlugin.toolbars.sampleCommand">
</command>
</toolbar>
</menuContribution>
</extension>
</plugin>
I would expect that fubar would show up someplace but I see "Sample Command" when, for example, I click on the new item in the menu bar, not "fubar". Moreover, search the code, xml files, etc. and the specific string "Sample Command" is not showing up. Where is that string defined and how do I change it?
The name value in the command is the default name of the command. It may be overridden by the menu definition.
If the org.eclipse.ui.menus extension point is used to define the menu you might have something like:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="some location URI">
<command
commandId="TBPlugin.commands.sampleCommand"
label="%command.name"
style="push">
label sets the displayed name, it is optional with the command name being the default.
If label starts with % it is the id of a property in the plugin's bundle localization properties file (usually plugin.properties or OSGI-INF/i10n/bundle.properties)

Toolbar item not clickable in Eclipse RCP - Windows

I am new to Eclipse Rich Client Platform. I am learning to create Views by adding toolbar, menu, etc. As a part of an exercise, I added a toolbar to my view and also declared a handler for its command. But when I run my application the toolbar appears in disabled mode and I am not able to click it.
This is my plugin.xml
<extension
point="org.eclipse.ui.commands">
<category
id="ch02.WebBrowser.commands.category"
name="Web Category">
</category>
<command
categoryId="ch02.WebBrowser.commands.category"
id="ch02.WebBrowser.commands.newBrowser"
name="New Browser">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="ch02.WebBrowser.toolbar.sampletoolbar">
<command
commandId="ch02.WebBrowser.commands.newBrowser"
icon="icons/16-earth.png"
id="ch02.WebBrowser.toolbars.newBrowserCommand"
style="push"
tooltip="Open New Browser">
</command>
</toolbar>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="ch02.webbrowser.handlers.NewBrowserHandler"
commandId="ch02.WebBrowser.commands.newBrowser">
</handler>
</extension>
Output
Please check your handler isEnable() and isHandled() status.

Project Explore has replicated(duplicated) popup menu entry of Package Explorer

I am new to extention creation in eclipse. I am trying to add same context menu to Project Explorer and Package Explorer.
XXX_label is menu and XXX, YYY and ZZZ are commands.
For project Explorer as described in Link, I added entry for project explorer and package Explorer.
Plugin.xml
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
<menu
id="XXX_Project"
label="XXX_label">
</menu>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:XXX_Project?after=additions">
<command
commandId="demoeeeeeeeemenu.XXX"
id="XXX"
label="XXX"
style="push">
<visibleWhen>
<with
variable="activeMenuSelection">
<iterate
ifEmpty="true"
operator="or">
//Only option to get the Project instance in core expression is adapt type!!
<adapt
type="org.eclipse.core.internal.resources.Project">
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
<command
commandId="demoeeeeeeeemenu.YYY"
label="YYY"
style="push">
</command>
<command
commandId="demoeeeeeeeemenu.ZZZ"
label="ZZZ"
style="push">
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:popup:org.eclipse.jdt.ui.PackageExplorer#PopupMenu?after=additions">
<menu
id="XXX_package"
label="XXX_label">
</menu>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:XXX_package?after=additions">
<command
commandId="demoeeeeeeeemenu.XXX"
label="XXX"
style="push">
</command>
<command
commandId="demoeeeeeeeemenu.YYY"
label="YYY"
style="push">
</command>
<command
commandId="demoeeeeeeeemenu.ZZZ"
label="ZZZ"
style="push">
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
id="demoeeeeeeeemenu.XXX"
name="XXX">
</command>
<command
id="demoeeeeeeeemenu.YYY"
name="YYY">
</command>
<command
id="demoeeeeeeeemenu.ZZZ"
name="ZZZ">
</command>
</extension>
</plugin>
How to eliminate extra entry done by package explorer?
Any of Help is Appreciated.
EDIT :
I think it is better to use locationURI="popup:org.eclipse.ui.popup.any?after=additions" as single popup entry which will add menu entry in both package explorer, Project Explorer and Navigator.
Location URI for package explorer is : popup:org.eclipse.jdt.ui.PackageExplorer.

Could not add menu item to Egit history View menu

In Egit, ..... when right click the project, then click "Show in History", the history View shows the list of all commits, select one commit, right click , the pop up menu shows (Checkout, Create Branch, Create Tag, .....Revision Comment). What I need to do is to add a new item in this pop up menu called "Add To Factory", then when click it , go to "AddToFactoryHandler" to do the implementation.
From the source code in Egit, this menu id is "org.eclipse.egit.ui.historyPageContributions",
(1)
<extension point="org.eclipse.ui.commands">
<command
id="xxxxxxxxxx.AddToFactory"
defaultHandler="xxxxxxxxxxx.AddToFactoryHandler"
description="description"
name="AddToFactory">
</command>
</extension>
<extension point="org.eclipse.ui.handlers">
<handler
commandId="xxxxxxxxxx.AddToFactory">
<class
class="xxxxxxxxxxx.AddToFactoryHandler">
</class>
<activeWhen>
<and>
<count
value="1">
</count>
<iterate>
<adapt
type="org.eclipse.jgit.lib.ReflogEntry">
</adapt>
</iterate>
</and>
</activeWhen>
</handler>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.eclipse.egit.ui.historyPageContributions">
<command
commandId="xxxxxxxxxx.AddToFactory"
label="AddToFactory"
style="push">
</command>
</extension>
(2) <extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.egit.ui.historyPageContributions">
<command commandId="xxxxxxxxxx.AddToFactory" style="push">
<visibleWhen checkEnabled="true"/>
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.handlers">
<handler
class="xxxxxxxxxxx.AddToFactoryHandler"
commandId="xxxxxxxxxx.AddToFactory">
<enabledWhen>
<and>
<with variable="activePartId">
<equals value="org.eclipse.egit.ui.historyPageContributions"/>
</with>
<with variable="activeMenuSelection">
<iterate ifEmpty="false">
<adapt type="org.eclipse.jgit.lib.ReflogEntry"/>
</iterate>
</with>
</and>
</enabledWhen>
</handler>
</extension>
Either way, when I select the commit in the history view and right clcik , "AddToFActory" never show up in the pop up menu. Any idea how to add item to such pop up menu? Thanks a lot for the help?

Eclipse Toolbar visibility via Source Provider not working

I have a menu and toolbar that are defined in plugin.xml and a class that implements a source provider by extending AbstractSourceProvider. The menu is properly hidden but the toolbar with exactly the same visibleWhen is still visible. Since the menu is properly hidden, I'm fairly confident that the source provider is working correctly.
Anyone see why this declaration is not hiding the whole toolbar?
<menuContribution
allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu?before=Window">
<menu
label="Data Manager"
mnemonic="D">
<command
command1
</command>
<command
command2
</command>
<visibleWhen
checkEnabled="false">
<with
variable="datamanager.handlers.ShowActions">
<equals
value="showActions">
</equals>
</with>
</visibleWhen>
</menu>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="datamanager.toolbar1">
<command
command3
</command>
<command
command 4
</command>
<visibleWhen
checkEnabled="false">
<with
variable="datamanager.handlers.ShowActions">
<equals
value="showActions">
</equals>
</with>
</visibleWhen>
</toolbar>
</menuContribution>
This looks like the problem described in Eclipse bug 201589 which has been open for rather a long time.