开发者

Eclipse-Plugin with submenu. How to handle JavaProjects and Projects?

开发者 https://www.devze.com 2022-12-17 15:45 出处:网络
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 :

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 exac开发者_Go百科tly if a javaProject or a Project is selected?


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


Make sure the adaptable property of your object contribution is set to true (it defaults to false):

adaptable="true"

@iain suggestion to target the interface is also good practice.

Just tried your example and the menus were showing as expected on a Java project.

Always bear in mind adpatability to org.eclipse.core.resources.IResource in general to ensure your menus, actions to be consistently displayed and enabled (whatever the explorer or actual object class being rendered).

Finally, beware that the org.eclipse.ui.popupMenus extension point is deprecated.

Though in my experience using it is faster and easier than the recommended org.eclipse.ui.commands, you may end up having a hard time migrating all your menus when it is removed (that is, if it is removed at some point).

Cheers,


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消