views:

215

answers:

2

I want to write an Eclipse-plugin that performs an Action with a selected Project. I used the plugin Template with submenu. My plugin.xml looks like this :

<extension
      point="org.eclipse.ui.popupMenus">
   <objectContribution
         objectClass="org.eclipse.core.internal.resources.Project"
         id="testplugin2.contribution1">
      <menu
            label="Propertie Manager"
            path="additions"
            id="testplugin2.menu1">
         <separator
               name="group1">
         </separator>
      </menu>
      <action
            label="list all *.properties"
            class="testplugin2.popup.actions.ListPropertiesAction"
            menubarPath="testplugin2.menu1/group1"
            enablesFor="1"
            id="testplugin2.projectAction">
      </action>
   </objectContribution>
</extension>

this works fine for everything but javaProjects. It turns out that javaProjects are not Projects. I want this Action to appear when a javaProjects or a normal Projects is selected and not if something else is selected.

How can I make the submenu appeare exactly if a javaProject or a Project is selected?

+1  A: 

I didn't test it, but maybe this works:

<objectcontribution ...>
    <visibility>
        <objectClass
            name="org.eclipse.jdt.core.IJavaProject" />
    </visibility>
</objectContribution>

You can also try "enablement" instead of "visibility".

eclipse help pages on popup menus

Stroboskop
I tested it but I didn't work. If I just add the Tag than the Action doesn't appear at all. If I change objectcontribution objectclass="java.lang.Object" than the Action only appears for JavaProjects. It is not possible to add a second visibility-Tag and enablement didn't work.
Zwarn
Maybe [VonC](http://stackoverflow.com/users/6309/vonc) can help.
Stroboskop
A: 

You should not reference the internal class in you object class. You should use the public interface instead

objectClass="org.eclipse.core.internal.resources.Project"

Try

objectClass="org.eclipse.core.IProject"

I haven't tried this but IJavaProject should adapt to the IProject, so this should work for both.

iain
I tested it and I did not work. I think you mean org.eclipse.core.ressources.IProject and this is suprisingly not a superinterface of org.eclipse.jdt.core.IJavaProject.
Zwarn