Eclipse e4 RCP:核心表达式 - 更少的XML地狱? [英] Eclipse e4 RCP: Core Expressions - Something less XML-hell?

查看:265
本文介绍了Eclipse e4 RCP:核心表达式 - 更少的XML地狱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用E4 RCP应用程序,并且有一个上下文菜单,其菜单项可视或不可视,具体取决于选择。我发现这样做的方式是在plugin.xml中定义的核心表达式,如下所示:

I'm working on an E4 RCP application, and have a context menu which has menu items visible or not depending on the selection. The way I've found to do this is with core expressions defined in the plugin.xml like so:

<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>

这个工作,菜单如果所选项目是Class1或Class2的实例,则显示项目。

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

这一切似乎是一个非常讨厌的方式来做事情!当许多这些被添加时,它将成为一个维护和调试噩梦。

This all seems like an extremely nasty way to do things! When many of these are added, its going to be a maintenance and debugging nightmare.

任何人都可以表现出更少的XML-ish的方式吗?例如,Java中的纯编程方法将会很棒!

Can anyone demonstrate a less XML-ish way of doing this? Pure programmatic methods in Java would be great!

推荐答案

例如,核心表达式不适用于工具栏项。您可以在命令处理程序中使用以下解决方法:

Core expressions are not working for toolbar items, for example. You can use the following workaround in command handlers:

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

where toolItem is retrieved by EModelService

这篇关于Eclipse e4 RCP:核心表达式 - 更少的XML地狱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆