Eclipse 4模型中工具栏项的可见性

时间:2014-05-08 12:11:43

标签: eclipse toolbar eclipse-kepler e4

我有一个简单的e4 RPC应用程序,基于e4模型。我在PartSachContainer中有两个部分 - 左边一个,右边一个。 当一个部件处于活动状态时,我需要一个特定的工具栏项,当另一个部件处于活动状态时,我需要另一个项目可见。

我尝试使用CoreExpression,但无济于事。我无法理解在表达式本身需要写什么。

我的配置如下:

第一部分定义为

ID: simple1.part.leftpart
Label: LeftPart
ClassURI: bundleclass://Simple1/simple1.parts.LeftPart

第二部分定义为

ID: simple1.part.rightpart
Label: RightPart
ClassURI: bundleclass://Simple1/simple1.parts.RightPart

ToolBar贡献定义为

<toolBarContributions xmi:id="_gqB4gNaWEeO3iqh7a9kwnw" elementId="simple1.toolbarcontribution.0" parentId="simple1.toolbar.0">
    <children xsi:type="menu:HandledToolItem" xmi:id="_PtGaINaSEeO3iqh7a9kwnw" elementId="simple1.handledtoolitem.leftpitem" iconURI="platform:/plugin/Simple1/icons/sample.png" command="_vFvtcNaREeO3iqh7a9kwnw">
      <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_z_87oNanEeO3iqh7a9kwnw" coreExpressionId="Simple1.RightPartActive"/>
    </children>
  </toolBarContributions>

当我设置Visible-When Expression时,我可以看到工具栏项。 但是当我尝试使用CoreExpression(我尝试了各种组合)时,我从未看到工具栏项。

这就是我的开始:

  <definition id="Simple1.RightPartActive">
     <with variable="activePartId">
        <equals 
              value="simple1.part.rightpart">
        </equals>
     </with>
  </definition>

没有运气。

如何定义CoreExpression以查看工具栏项?

以下是真正的问题: 这个正确的部分应该是一个编辑器(在e3术语中) - 用于多个可编辑数据实例的相同实现类。因此,我将使用运行时生成的这些部件的唯一ID(部件isleves将从PartDescription创建)。 那么我应该如何在CoreExpression中使用生成的ID来解决这些部分?

更新

好的,我做了一些调试,发现有一个方法

public EvaluationResult evaluate(IEvaluationContext context)
班上的

org.eclipse.core.internal.expressions.WithExpression 正在被召唤。

第一行:

Object variable= context.getVariable(fVariable);

调用类 EclipseContext

的方法
public Object getVariable(String name) {
    if (IEclipseContext.class.getName().equals(name)) {
    return eclipseContext;
    }
    Object obj = eclipseContext.getActive(name);
    return obj == null ? IEvaluationContext.UNDEFINED_VARIABLE : obj;
}

其中

public Object getActive(final String name) {
    return getActiveLeaf().get(name);
}

public IEclipseContext getActiveLeaf() {
    IEclipseContext activeContext = this;
    IEclipseContext child = getActiveChild();
    while (child != null) {
        activeContext = child;
    child = child.getActiveChild();
    }
    return activeContext;
}

和[b] activeChild [/ b]始终为空。

我在EclipseContext中看不到任何类似于&#34; activePartId&#34;或任何接近它的东西。

那为什么会这样呢? 我们怎么能使用CoreExpressions?

2 个答案:

答案 0 :(得分:0)

这看起来像Eclipse bug 400217,这说明目前无效。

答案 1 :(得分:0)

既然你在e4中为什么不以e4方式处理它呢?

Subscribe to the UIEvents.UILifeCycle.ACTIVATE event.
if (newActivePart == LeftPart)
  <set 'toBeRendered' to true for LeftPart's items and false for RightPart's items

右侧部分相同......