I have written a plugin which is a simple validator for some java classes. (Additional logic validation)
I used a custom nature to ommit manual adding of builders to any project.
When i have a project Folder of type "Project" or "Maven" - the Add/Remove [MyNature] button is visible. However for Java-Projects, the ui-contribution is not available...
(and I need to add it to Maven-Projects which also have the nature Java-Project...)
The menucontributions are defined like this:
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.eclipse.ui.projectConfigure?after=additions">
<command
commandId="my.namespace.lazyloadingvalidatorplugin.addRemoveLazyLoadingNature"
label="Remove Lazy Loading Nature"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="selection">
<count
value="1">
</count>
<iterate>
<and>
<instanceof
value="org.eclipse.core.resources.IProject">
</instanceof>
<test
value="my.namespace.lazyloadingvalidatorplugin.lazyLoadingNature"
property="org.eclipse.core.resources.projectNature">
</test>
</and>
</iterate>
</with>
</visibleWhen>
</command>
<command
commandId="my.namespace.lazyloadingvalidatorplugin.addRemoveLazyLoadingNature"
label="Add Lazy Loading Nature"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="selection">
<count
value="1">
</count>
<iterate>
<and>
<instanceof
value="org.eclipse.core.resources.IProject">
</instanceof>
<not>
<test
value="my.namespace.lazyloadingvalidatorplugin.lazyLoadingNature"
property="org.eclipse.core.resources.projectNature">
</test>
</not>
</and>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>
I also tried to add the nature to the pom file, using the following entries:
<additionalProjectnatures>
<projectnature>
lazyLoadingNature
</projectnature>
</additionalProjectnatures>
<buildcommands>
<buildcommand>
my.namespace.lazyloadingvalidatorplugin.lazyLoadingBuilder
</buildcommand>
</buildcommands>
no success... any ideas what is wrong?
figured out, its the check
<instanceof
value="org.eclipse.core.resources.IProject">
</instanceof>
that fails... Removing this condition leads to simultaneously showing the "Add" and "Remove" button for Jave-Nature-Projects... Well, could live with that - question just why and how to do it right :)
Use
<adapt
type="org.eclipse.core.resources.IProject">
</adapt>
instead of instanceof. Objects shown in views are often not actual instances of Projects, Files.... but can be 'adapted' to those objects.
Related
I've followed all the possible solutions that I found on several forum (also this: Eclipse plugin menu item is not visible). But, all of them didn't resolve my problem. I've also followed this tutorial http://www.vogella.com/tutorials/EclipsePlugIn/article.html. Anyway the label didn't show in the menu. This is my plugin.xml:
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="pr.handlers.SampleHandler3"
id="pr.commands.rightclick"
name="Analyze">
</command>
.....
<menuContribution
locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
<command
commandId="pr.commands.rightclick"
label="Analyze"
style="push">
<visibleWhen>
<with variable="activeMenuSelection">
<iterate
ifEmpty="false">
<adapt type="org.eclipse.core.resources.IFile">
<test property="org.eclipse.core.resources.name" value="*java" />
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
It seems that for Java files in the packages section of the Package Explorer there is no adapter defined for org.eclipse.core.resources.IFile, there is however an adapter for org.eclipse.core.resources.IResource so changing your adapt to that should work.
Since matching IResource will also match folders your test would be better checking the content type id:
<adapt type="org.eclipse.core.resources.IResource">
<test property="org.eclipse.core.resources.contentTypeId" value="org.eclipse.jdt.core.javaSource" />
</adapt>
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
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>
...
I have a menu contribution to the Package Explorer from an Eclipse plugin.
It looks like this:
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
<command
commandId="org.attrx.actions.Open"
style="push">
<visibleWhen
checkEnabled="false">
<iterate>
<adapt
type="org.eclipse.core.resources.IFile">
<test
property="org.eclipse.core.resources.name"
value="*.java">
</test>
</adapt>
</iterate>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="org.attrx.actions.Open"
id="org.attrx.actions.Open"
name="Open File">
</command>
</extension>
</plugin>
I would like to add a separator line in the context menu before and after this command. Could someone help me achieve this?
Use
<separator
name="separator-id"
visible="true">
</separator>
before and after the <command>.
Note: Separators are not shown if they are at the beginning or end of a menu.
I'm trying to add a Menu Item to the Run Menu in Eclipse via a plugin.
However, I only want this Item to appear when I'm in the "Report Design" perspective (this is for BIRT).
Secondly, (if possible) I'd like the menu item to be only enabled if the extension of the open file is .rptdesign.
I'm not having any luck using either of the visibility or visibleWhen elements in the plugin.xml
Any hints appreciated,
Ro
Eventually got it, here's what I had to do.....
Create the Command
<extension
point="org.eclipse.ui.commands">
<command
name="Deploy"
icon="icons/deploy.gif"
style="push"
id="com.test.deployCommand">
</command>
Create the Handler for the command
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="com.test.deployCommand"
class="com.test.DeployHandler">
</handler>
Add an existing property tester available in BIRT (to test the file type) - Would not work if i changed the namespace parameter
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="org.eclipse.birt.report.debug.internal.ui.script.ScriptDebuggerPropertyTester"
id="com.test.propertyTester1"
namespace="scriptdebug"
properties="isRptdesign"
type="org.eclipse.core.runtime.IAdaptable">
</propertyTester>
Added two definitions
<extension point="org.eclipse.core.expressions.definitions">
<definition id="com.test.inRptDesignPerspective">
<with variable="activeWorkbenchWindow.activePerspective">
<equals value="org.eclipse.birt.report.designer.ui.ReportPerspective"/>
</with>
</definition>
<definition id="com.test.inRptDesignFile">
<with variable="selection">
<count value="1" />
<iterate>
<and>
<test property="scriptdebug.isRptdesign" />
</and>
</iterate>
</with>
</definition>
</extension>
On my menu extension, added a setting to the command, marking when its visible
<extension
point="org.eclipse.ui.menus">
<menuContribution locationURI="menu:org.eclipse.ui.main.menu" id="com.test.contribution2">
<menu
id="org.eclipse.ui.run"
label="Run"
path="additions">
<groupMarker
name="preview">
</groupMarker>
<command
commandId="com.test.deployCommand"
icon="icons/deploy.gif"
id="com.test.deployCommand"
menubarPath="org.eclipse.ui.run/preview"
style="push"
class="com.test.DeployHandler">
<visibleWhen>
<and>
<reference definitionId="com.test.inRptDesignPerspective"/>
<reference definitionId="com.test.inRptDesignFile"/>
</and>
</visibleWhen>
</command>
</menu>
</menuContribution>