PropertyTester的触发器评估

两年前的代码必须升级到E4,现在一堆东西不再起作用了。 其中一个是IEvaluationService如果这样使用:

        
 IEvaluationService service = (IEvaluationService) PlatformUI.getWorkbench().getService(IEvaluationService.class); service.requestEvaluation("org.acme.printable"); 

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

相关问题 – 但是这个用户在E4中搜索等效的,而我需要一个在E3中工作的用户。

有趣的是,如果我用替换标签就行了。 在那种情况下, IEventBroker#postIEventBroker#send工作。

这是一个类似的问题 。 该用户使用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 IEvaluationService.requestEvaluation. */ 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. */ } } 

我将分享我的解决方法,这是不好的,并且在alles案例中不起作用。 并且只有真正有效,因为在我的用例中我有一个带有ISelectionProviderIWorkbenchPart …但也许它会帮助下一个人:

 IWorkbenchPart activePart = // get active view or editor ISelectionProvider selectionProvider = activePart.getSite().getSelectionProvider(); ISelection selection = selectionProvider.getSelection(); selectionProvider.setSelection(new StructuredSelection()); selectionProvider.setSelection(selection); 

此代码仅重置选择,通常会触发PropertyTester 。 如果没有选择任何内容,我认为它不会起作用。

 eventBroker.post(UIEvents.REQUEST_ENABLEMENT_UPDATE_TOPIC, UIEvents.ALL_ELEMENT_ID); 

另请参阅Eclipse bug 436755和Eclipse Wiki: Eclipse 4 – RCP – 事件模型