Eclipse e4 RCP: Basic Expressions - Something Else XML Hell?

I am working on an E4 RCP application and have a context menu in which menu items are visible or independent of choice. The way I found this are the key expressions defined in the plugin.xml file as follows:

<extension
     point="org.eclipse.core.expressions.definitions">
     <definition
        id="com.foo.bar.test.core.expression">
      <with variable="org.eclipse.ui.selection">
        <iterate ifEmpty="false">
            <or>
          <instanceof value="com.foo.bar.Class1">
          </instanceof>
          <instanceof value="com.foo.bar.Class2">
          </instanceof>
            </or>
        </iterate>
      </with>
  </definition>

This works, and the menu item is displayed if the selected item is an instance of Class1 or Class2.

All this seems like a very unpleasant way to do something! When many of them are added, this will be the maintenance and debugging of nightmares.

Can anyone demonstrate a less XML way to do this? Pure Java programming methods would be great!

+4
source share
1 answer

, , . :

public class SomeHandler {
    protected MToolItem toolItem;

    @CanExecute
    @Inject
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional ISelection selection)
    {
        boolean canExecute = ...
        setToolItemVisible(canExecute);
        ...
    }

    private void setToolItemVisible(final boolean visible) {
        if (toolItem != null) {
            Display.getDefault().asyncExec(new Runnable() {
                @Override
                public void run() {
                    toolItem.setVisible(visible);
                }
            });
        }
    }
}

toolItem EModelService

+5

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


All Articles