2017-05-18 28 views
0

code from two years back必须升级到E4,现在一堆东西不再工作了。其中一个是IEvaluationService如果使用的话是这样的:PropertyTester的触发器评估

<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中工作的人。

有趣的是,如果我用<enabledWhen>代替<activeWhen>标签,它的作品。在这种情况下,IEventBroker#postIEventBroker#send也可以工作。

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

回答

0

我打算分享我的解决方法,这是不好的,并不适用于阿尔勒案件。只有真正的作品,因为在我的使用情况下,我有一个ISelectionProvider一个IWorkbenchPart ...但也许这将帮助旁边的人:

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

此代码只是将重置选择,它通常会触发PropertyTester。如果没有选择任何东西,我认为它不会起作用。