2017-05-18 30 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。如果沒有選擇任何東西,我認爲它不會起作用。