Eclipse Toolbar visibility via Source Provider not working - eclipse

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.

Related

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.

Eclipse RCP: how to create a popup menu for the selection in a text editor?

Using the Eclipse template I generated this sample which works fine when I select a file in the project explorer. However I want to also make it available when I do right-click on a Text Editor or even when I have some text selected.
What is the right objectClass to use in the objectContribution?
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
id="com.example.popup-cli.contribution1"
objectClass="org.eclipse.core.resources.IFile">
<menu
id="com.example.popup.menu1"
label="New Submenu"
path="additions">
<separator
name="group1">
</separator>
</menu>
<action
class="com.example.popup.actions.NewAction"
enablesFor="1"
id="com.example.popup.newAction"
label="New Action"
menubarPath="com.example.popup.menu1/group1">
</action>
</objectContribution>
</extension>
Using the org.eclipse.ui.menus extension point you can use the activeEditorInput variable to test the current editor input (the file being edited).
For example:
<extension point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:#AbstractTextEditorRulerContext?after=QuickDiff.Toggle">
<command
commandId="org.eclipse.team.cvs.ui.showAnnotation"
label="%ShowAnnotationAction.label"
style="push">
<visibleWhen
checkEnabled="false">
<with variable="activeEditorInput">
<test
property="org.eclipse.team.internal.ccvs.ui.isManaged"
value="true">
</test>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>
The above is from the CVS plugin
I'm not sure if this is the ideal solution but it worked, it makes the popup menu visible when I press right-click on a resource in the Project Explorer and in the Editor if it's associated to a resource in the Project Explorer.
This is not perfect since it's still being displayed in non Text Editor editors/views, but I can ignore the action on those cases. If someone has some suggestion to improve this please comment.
<extension point="org.eclipse.core.expressions.definitions">
<definition id="com.example.definitions.resourceDefinition">
<adapt type="org.eclipse.core.resources.IResource"/>
</definition>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command commandId="com.example.commands.myCommand">
<visibleWhen checkEnabled="false">
<or>
<with variable="activeEditorInput">
<reference definitionId="com.example.definitions.resourceDefinition"/>
</with>
<iterate>
<reference definitionId="com.example.definitions.resourceDefinition"/>
</iterate>
</or>
</visibleWhen>
</command>
<menuContribution>
</extension>

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?

Avoid duplication of toolbar item in eclipse

I have created a toolbar item using eclipse menu contributions and commands.
Using eclipse command core expressions I have bounded the commands to two views (activePartID is viewA or viewB). There is a provision to open viewB from viewA.
Since I have bounded the command to both the views, when I try to open viewB from viewA, the toolbar item appears twice. How to refrain it from appearing more than once in the toolbar.
Anyhelp is appreciated.
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="<xyz>.toolbar">
<command
commandId="xyz.abc"
icon="icons/db.jpg"
id="ABC"
label="ABC"
style="push"
tooltip="ABC">
<visibleWhen
checkEnabled="false">
<and>
<with
variable="activeWorkbenchWindow.activePerspective">
<equals
value="xyz.perspective">
</equals>
</with>
<with
variable="activePartId">
<or>
<equals
value="viewA">
</equals>
<equals
value="viewB">
</equals>
</or>
</with>
</and>
</visibleWhen>
</command>
</toolbar>
</menuContribution>
<extension point>
Thanks,
Santhosh

Eclipse RCP toolbar separators dont show up

I'm having a problem with the main toolbar in my Eclipse RCP application. The added separators in my plugin.xml never show up. Their visibility are all set to true
Is this a known bug? Because programatically added separators in some views contributions show up just fine.
See attached pic:
Here is the plugin.xml part:
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="hu.clickandlike.wfbpmn.application.toolbar1">
<command
commandId="hu.clickandlike.wfbpmn.application.menu.command.new"
icon="icons/1390594879_document-new.png"
label="New"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="hu.clickandlike.wfbpmn.application.menu.command.new.state">
<equals
value="true">
</equals>
</with>
</visibleWhen>
</command>
<command
commandId="hu.clickandlike.wfbpmn.application.menu.command.open"
icon="icons/1390594932_document-open.png"
label="Open"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="hu.clickandlike.wfbpmn.application.menu.command.open.state">
<equals
value="true">
</equals>
</with>
</visibleWhen>
</command>
<separator
name="Separator 1"
visible="true">
</separator>
...