eclipse-plugin - PropertyTester 的触发器评估

标签 eclipse-plugin e4

code from two years back必须升级到 E4,现在一堆东西不再工作了。其中之一是 IEvaluationService如果这样使用:

<handler class="org.acme.PrintHandler" commandId="org.eclipse.ui.file.print">
  <activeWhen>
    <with variable="activePart">
      <test property="org.acme.printable" />
    </with>
  </activeWhen>
</handler>
IEvaluationService service = (IEvaluationService) PlatformUI.getWorkbench().getService(IEvaluationService.class);
service.requestEvaluation("org.acme.printable");

我如何(重新)触发对 PropertyTester 的评估?由于 E4 实际上还没有接近生产就绪状态,我需要 E3(兼容层)的解决方法。

Related question - 但是这个用户正在搜索 E4 中的等效项,而我需要一个适用于 E3 的项。

有趣的是,如果我替换 <activeWhen>带有 <enabledWhen> 的标签有用。在那种情况下 IEventBroker#postIEventBroker#send工作,也是。

这是一个 similar question .该用户使用 Eclipse 4.2 - 我用 4.5、4.6 和 4.7 测试了这个问题。

最佳答案

EvaluationService 与 E3 兼容层中的 API 兼容。但是 E4 中的实现完全不同,导致 requestEvaluation 的行为根本不同。

我能找到的解决此问题的最佳方法是手动停用和激活当前事件部分的所有上下文。这导致内部重新评估,并在需要时重新呈现各个部分的所有 UI 元素。

有人可能会争辩说,这比请求评估一个非常具体的属性效率低,而 EvaluationService 应该这样做。但由于评估仅限于事件部分,因此不应产生太多开销。而且它确实在全局范围内工作,因为不再需要特定的属性字符串。

唯一未涵盖的用例可能是 RCP 应用程序的主工具栏。

/**
 * Triggers evaluation of all UI elements (buttons, etc.) of the active part.
 * Also causes test of all property testers of all opened parts implicitly.
 * Workaround of the broken <code>IEvaluationService.requestEvaluation</code>.
 */
public static void triggerUIElementsEvaluation() {
    try {
        final EPartService partService = PlatformUI.getWorkbench().getService(EPartService.class);
        final MPart activePart = partService.getActivePart();

        /* Toggle context of active part to trigger re-evaluation of its UI elements. */
        if (activePart != null) {
            activePart.getContext().deactivate();
            activePart.getContext().activateBranch();
        }
    } catch (IllegalStateException e) {
        /* Ignore "Application does not have an active window" exception to allow program to continue. */
    }
}

关于eclipse-plugin - PropertyTester 的触发器评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43656265/

相关文章:

Eclipse RCP e4 使用 Application.e4xmi 文件的缓存版本

java - 工具栏中的文本框 Eclipse RCP 应用程序

java - 向 eclipse 插件添加 java 要求

java - 如何摆脱这个 "The import com.google.gwt cannot be resolved"

java - 为什么 GEF 编辑器部分不显示?

eclipse-plugin - 运行 Hello World OSGI 包时出现 FrameworkEvent 错误

css - eclipse e4 深色主题 : How to style widgets created by FormToolKit with css

java - 获取Eclipse E4的GUI组件

java - GWT/ eclipse : ClassNotFoundException com/google/gwt/dev/Compiler