触发PropertyTester的评估 [英] Trigger evaluation of PropertyTester

查看:98
本文介绍了触发PropertyTester的评估的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两年前的代码必须是升级到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服务=(IEvaluationService )PlatformUI.getWorkbench()。getService(IEvaluationService.class); 
service.requestEvaluation( org.acme.printable);

我如何(重新)触发 PropertyTester的评估?由于E4确实还没有准备好投入生产,因此我需要E3(兼容层)的解决方法。



相关问题-但是该用户正在E4中搜索等效项,而我



很有趣,如果我将< activeWhen> 标记替换为< enabledWhen> 起作用。在这种情况下, IEventBroker#post IEventBroker#send 也可以工作。



这是类似的问题。该用户使用Eclipse 4.2-我用4.5、4.6和4.7测试了该问题。

解决方案

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



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



一个人可能认为这比请求评估以下项效率低一个非常具体的属性,如EvaluationService应该做的那样。但是,由于评估仅限于活动部件,因此不应产生过多的开销。



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



它确实可以在全球范围内工作,因为不再需要特定的属性字符串。 p>

  / ** 
*触发对所有UI元素(按钮等)的求值活动部分。
*还隐式导致对所有打开的部件的所有属性测试器进行测试。
*损坏的< code> IEvaluationService.requestEvaluation< / code>的解决方法。
* /
public static void triggerUIElementsEvaluation(){
try {
final EPartService partService = PlatformUI.getWorkbench()。getService(EPartService.class);
最终MPart activePart = partService.getActivePart();

/ *切换活动零件的上下文以触发对其UI元素的重新评估。 * /
if(activePart!= null){
activePart.getContext()。deactivate();
activePart.getContext()。activateBranch();
}
} catch(IllegalStateException e){
/ *忽略应用程序没有活动窗口异常以允许程序继续。 * /
}
}


The code from two years back had to be upgraded to E4, and now a bunch of stuff does not work anymore. One of these is the IEvaluationService if used like this:

<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");

How do I (re)trigger the evaluation of a PropertyTester? Since E4 is really not even close to being production ready, I need a workaround for E3 (compatibility layer).

Related question - but this user was searching for the equivalent in E4, while I need one that works in E3.

Funnily enough, if I replace the <activeWhen> tags with <enabledWhen> it works. In that case IEventBroker#post and IEventBroker#send work, too.

This is a similar question. That user used Eclipse 4.2 - I tested the problem with 4.5, 4.6 and 4.7.

解决方案

The EvaluationService is API compatible in the E3 Compatibility Layer. But the implementation in E4 is completely different, causing the behaviour of requestEvaluation to be fundamentally different.

The best solution to this problem I could find is to manually deactivate and activate all contexts of currently active parts. This causes internally to re-evaluate and, when required, re-render all UI elements of the respective parts.

One could argue this is less efficient than requesting the evaluation of a very specific property, as the EvaluationService is supposed to do. But since the evaluation is limited to active parts only, it should not create too much overhead. And it does work globally, as no specific property string is required anymore.

The only usecase not covered by this yet may be the main toolbar of your RCP application.

/**
 * 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. */
    }
}

这篇关于触发PropertyTester的评估的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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