Turn on / off menu item in Eclipse plugin

I created a popup menu with one menu item, I want to enable it only when I right-click on an element of the tree of a certain type of class, otherwise disable it.

How can i achieve this?

+6
source share
1 answer

You can add a handler that uses activeWhen and associate it with this menu command identifier.

Here is the handler that makes the command active only when the current selection is not empty, and the selection is an element 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> 
+6
source

Source: https://habr.com/ru/post/920306/


All Articles