Eclipse Plugin: what property attribut for testing name of subversion resources - eclipse

I'm writing a plugin. To start it, the menu entry is displayed when doing a rightclick on a project in SVN-Plugin-View. By using "org.tigris.subversion.subclipse.ui.repository.RepositoriesView" as locationURI inside the plugin.xml my menu entry is visible, as I wanted.
But now I want to make it visible under special conditions. I don't find out, what property I can use to test the name of the Project.
I already did something similar inside Eclipse with
<command...
<visible when>
<with variable="activeMenuSelection">
<iterate ifEmpty="false">
<adapt type="org.eclipse.core.resources.IProject">
<test property="org.eclipse.core.resources.name" value="Test_*"/>
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
Now I use
but I don't find out what to use as test property
Like in my working (without SVN) example I tried
<test property="org.tigris.subversion.subclipse.core.resources.name" value="Test_*/>"
But it did not work. The menu entry was not visible for SVN-Projects with names starting with "Test_"

Related

Submenu on method level for custom launcher in RCP client

I have written a custom launcher in Eclipse which I can access via the "Run As" and "Debug As" on class level. I have a similar configuration as described in How do I use "org.eclipse.debug.ui.launchShortcuts"?. Unfortunately I can't see the submenu in the package explorer at the method level (for example submenu to launch the customer launcher in order to execute a single JUnit test). How can I do this?
JUnit uses a contextualLaunch based on the selected element being a org.eclipse.jdt.core.IJavaElement rather than just a resource. You will need to do the same.
This is what JUnit uses:
<contextualLaunch>
<enablement>
<with variable="selection">
<count value="1"/>
<iterate>
<adapt type="org.eclipse.jdt.core.IJavaElement">
<and>
<test property="org.eclipse.jdt.core.isInJavaProject"/>
<or>
<test property="org.eclipse.jdt.core.hasTypeOnClasspath" value="junit.framework.Test"/>
<test property="org.eclipse.jdt.core.hasTypeOnClasspath" value="org.junit.platform.commons.annotation.Testable"/>
</or>
<test property="org.eclipse.jdt.junit.canLaunchAsJUnit" forcePluginActivation="true"/>
</and>
</adapt>
</iterate>
</with>
</enablement>
</contextualLaunch>
Some of the <test elements are specific to JUnit so you will need to use something different.

eclipse property tester for empty project or folder

I have a popup-menu contribution for .txt file in a project:
<menuContribution
allPopups="false"
locationURI="popup:com.XXXX.ui.view.navigator?endof=group1">
<command
commandId="com.XXXX.ui.commandid2"
style="push">
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="or">
<or>
<adapt
type="org.eclipse.core.resources.IFile">
<test
property="org.eclipse.core.resources.extension"
value="txt">
</test>
</adapt>
<instanceof
value="org.eclipse.core.resources.IFolder">
</instanceof>
</or>
</iterate>
</visibleWhen>
</command>
As you can see, currently I have enable for folder also. But wanted to make invisible for a blank folder and empty project. No clue how to apply property tester for an empty folder or Project. Any pointer would be much helpful.
There is no standard property tester available which tests if the folder or project is empty.
You could write your own property tester for this using the org.eclipse.core.expressions.propertyTesters extension point.

Contribute to Eclipse context menu when file and parent project meet conditions

I want to contribute a context menu only when the following 2 conditions are met:
1.- If selected file has .txt extension
2.- If parent project of the selected file has an specific facet
I can do this by separate using the following conditions using the org.eclipse.ui.menus extension point, i.e: for the project facet:
<with variable="activeMenuSelection">
<iterate operator="and" ifEmpty="false">
<adapt type="org.eclipse.core.resources.IProject">
<test property="org.eclipse.wst.common.project.facet.core.projectFacet" value="jst.code.quality" forcePluginActivation="true" />
</adapt>
</iterate>
</with>
And for the file extension:
<with variable="activeMenuSelection">
<iterate operator="and" ifEmpty="false">
<adapt type="org.eclipse.core.resources.IFile">
<test property="org.eclipse.core.resources.extension" value="txt" forcePluginActivation="true" />
</adapt>
</iterate>
</with>
But I have problems to combine this two conditions since the activeMenuSelection variable will only contain the file and I can't use it to test the project facet, is there a variable I can use to access the active project in the same condition?
The org.eclipse.wst.common.project.facet.core.projectFacet test will work on any IResource so it will work on an IFile as well as an IProject. So you can combine the tests.

Trouble deciding how to add popup menu to eclipse plugin using either action ObjectContributions or command handlers

The issue is this: Most things I read on the web says that we should avoid actions when creating popup menus because the command framework allows for more decoupling.
Example: http://wiki.eclipse.org/FAQ_What_is_the_difference_between_a_command_and_an_action%3F
Fair enough.
But I am having a heck of a time getting the command framework to add my menu when I right click on a .java file inside the editor, and only when I click inside the editor. I can get the menu to show (using 'with' and the activeEditor variable), but it also shows when I right click on the java file inside the package explorer, which I don't want. I suspect it's because the file is already open inside the editor.
I also have a menu that gets added when I right click on the java file inside the package explorer, using IComplilationUnit. That works fine.
So my problem is solved using a popup menu action for when I click inside the file. I also get access to to all the ISelection stuff there. But the coupling is to high and I lose the flexability of using handlers.
I'm looking for either:
Tell me I'm doing it the only way possible; or
Tell me how to have my popup appear only when I right click on the java file editor.
Regards
In the end it was really straight forward. The example below uses the command framework. It doesn't have the handlers, so just click the class hyperlink whenever you need a class generated.
Create a new eclipse plugin project called com.test.plugin.project
In the dependency tab of the plugin.xml file add the following dependencies
org.eclipse.jdt
org.eclipse.jdt.core
org.eclipse.jdt.ui
org.eclipse.jface.text
Put this in the plugin.xml tab section:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="true"
locationURI="popup:org.eclipse.ui.popup.any">
<menu
label="Test Project Sub Menu">
<command
commandId="com.test.plugin.project.command.packageexplorer"
id="packageexplorerId"
style="push">
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="or">
<instanceof
value="org.eclipse.jdt.internal.core.CompilationUnit">
</instanceof>
</iterate>
</visibleWhen>
</command>
<command
commandId="com.test.plugin.project.command.classfile"
id="classfileId"
style="push">
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="or">
<and>
<with
variable="selection">
<instanceof
value="org.eclipse.jface.text.TextSelection">
</instanceof>
</with>
<with
variable="activeEditorId">
<equals
value="org.eclipse.jdt.ui.CompilationUnitEditor">
</equals>
</with>
</and>
</iterate>
</visibleWhen>
</command>
</menu>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
id="com.test.plugin.project.command.packageexplorer"
name="Only Show In Package Explorer">
</command>
<command
id="com.test.plugin.project.command.classfile"
name="Only Show In Class File">
</command>
</extension>
</plugin>
What this does
It creates one popup menu in a sub menu when you right click on a java file inside the package explorer (and only when you click on a java file).
It create a different popup menu in a sub menu when you right click on a java file.

visibleWhen menuContribution showing up wrongly

I have created an eclipse menucontribution in my plugin which should show up ONLY when rightclicking a project that has a specific nature:
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<menu
icon="ico/full/obj16/icon-logo-composer.png"
id="com.dubture.composer.lib.ui.menu"
label="Composer">
<visibleWhen
checkEnabled="false">
<iterate>
<adapt
type="org.eclipse.core.resources.IProject">
<and>
<test
property="org.eclipse.core.resources.projectNature"
value="com.dubture.composer.core.composerNature">
</test>
</and>
</adapt>
</iterate>
</visibleWhen>
</menu>
</menuContribution>
The visibleWhen condition seems to work only when right-clicking a project. The menu is only shown when the project has the specified nature.
However, when i right-click somewhere else (for example in some empty area in the project explorer or inside the problems view), the menu entry will show up despite the adapt condition.
Anyone knows how to restrict it to right clicking on projects only?
the test property is used by PropertyTester
if you add your menucontribution to popup:org.eclipse.ui.popup.any?after=additions, I believe it could show everywhere, you should restrict to popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu unless required otherwise
this snippet uses commands but I think you can try to mix with your requirements to see if it works
<menuContribution locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu">
<command
commandId="COMMANDID"
icon="icons/icon.png"
label="LABEL"
style="push">
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="and">
<instanceof
value="org.eclipse.core.resources.IProject">
</instanceof>
</iterate>
</visibleWhen>
</command>
</menuContribution>