Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable/disable menu item in Eclipse plugin

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?

like image 384
becks Avatar asked Jul 12 '12 10:07

becks


People also ask

Which property is used to enable or disable menu item?

In order to disable a dynamic menu item you have to bind its IsEnabled property to the appropriate boolean property of your data item. To do this you can set the ItemContainerStyle property of RadMenu.

How do I turn off menu items?

To disable a menu item, set its Enabled property to False. In the following example, an event handler is attached to the OnClick event for the Edit item on a child form's menu bar. It sets Enabled for the Cut, Copy, and Delete menu items on the Edit menu based on whether RichEdit1 has selected text.


1 Answers

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>
like image 114
stracka Avatar answered Sep 21 '22 17:09

stracka