简体   繁体   English

在Eclipse插件中为Java项目添加弹出操作

[英]Add popup action for Java projects in an Eclipse plugin

I want to add popup item for Java projects in my Eclipse plugin. 我想在我的Eclipse插件中添加Java项目的弹出项。 My plugin.xml contains: 我的plugin.xml包含:

<extension point="org.eclipse.ui.popupMenus">
  <objectContribution
        objectClass="org.eclipse.jdt.core.IJavaProject"
        id="com.contribution1">
     <action
           label="Action"
           class="com.actions.NewAction"
           enablesFor="1"
           id="com.actions.newAction">
     </action>
  </objectContribution>

However, the menu item is not shown in the popup. 但是,菜单项未显示在弹出窗口中。 If I use IPackageFragment instead, the menu item shows just fine. 如果我改用IPackageFragment,则菜单项显示得很好。 Please advise. 请指教。

Ok, the problem was that a Java project is considered an IJavaProject in the Java perspective only and the Eclipse instance used to test the plugin starts with the Resources perspective. 好的,问题是,仅在Java透视图中将Java项目视为IJavaProject,并且用于测试插件的Eclipse实例从Resources透视图开始。 If I switch to the Java perspective everything works as expected. 如果我切换到Java透视图,那么一切都会按预期进行。

If you want to display your menu in another explorer (for instance in the Resources perspective's Project explorer), you'll have to change your objectContribution definition as follows: 如果要在另一个资源管理器中显示菜单(例如,在“资源”透视图的“项目资源管理器”中),则必须更改objectContribution定义,如下所示:

  1. Set the objectclass property to org.eclipse.core.resources.IProject . objectclass属性设置为org.eclipse.core.resources.IProject

  2. Add a visibility element to filter your menu/actions for projects that DO NOT have the Java nature . 添加可见性元素以过滤具有Java性质的项目的菜单/操作。

Ie: 即:

<objectContribution
      adaptable="true"
      objectClass="org.eclipse.core.resources.IProject">
...
   <visibility>
      <objectState
            name="projectNature"
            value="org.eclipse.jdt.core.javanature">
      </objectState>
   </visibility>
</objectContribution>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM