Enable/disable menu item in Eclipse plugin

江枫思渺然 提交于 2019-12-12 08:52:50

问题


I've made a pop-up menu with one menu item, I want to enable it only when I do a right click on a tree item of a certain class type otherwise disable it.

How can I achieve this?


回答1:


You can add a handler that uses activeWhen and associate it with that menu's command id.

Here is a handler that makes a command active only when the current selection is not empty, and the selection is an item that can be adapted to an object of type Widget:

<extension point="org.eclipse.ui.handlers">
  <handler class="com.myproject.handlers.ExportWidgetHandler"
           commandId="com.myproject.commands.exportWidget">
     <activeWhen>
        <with variable="selection">
           <iterate ifEmpty="false" operator="and">
              <adapt type="com.myproject.objects.Widget"/>
           </iterate>
        </with>
     </activeWhen>
  </handler>
</extension>


来源:https://stackoverflow.com/questions/11450052/enable-disable-menu-item-in-eclipse-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!