Eclipse RCP 工具栏状态更新未以编程方式触发

问题描述 投票:0回答:1

我想要做什么:我试图以编程方式触发工具栏上图标的显示/隐藏/启用/禁用。这是行不通的。然而,只要视图焦点发生变化,我就会看到显示/隐藏/启用/禁用功能“启动”(所以我认为 XML 是有效的)。 我正在做什么:在plugin.xml中我有以下内容(ID/类名已更改):

<extension point="org.eclipse.ui.views"> <view id="com.aaa.bbb.ccc.MyView" allowMultiple="false" name="%view.name.MyView" class="com.aaa.bbb.ccc.MyView" icon="icons/MyView.png"/> </extension> <extension point="org.eclipse.core.expressions.propertyTesters"> <!-- com.aaa.bbb.ccc.MyTester extends PropertyTester --> <propertyTester class="com.aaa.bbb.ccc.MyTester" id="com.aaa.bbb.ccc.MyTester" namespace="com.aaa.bbb.ccc.MyTester" properties="isValid" type="java.lang.Object"/> </extension> <extension point="org.eclipse.ui.handlers"> <!-- com.aaa.bbb.ccc.MyHandler extends AbstractHandler and overrides isEnabled --> <handler class="com.aaa.bbb.ccc.MyHandler" commandId="com.aaa.bbb.ccc.MyCommand"/> </extension> <extension point="org.eclipse.ui.commands"> <command id="com.aaa.bbb.ccc.MyCommand" name="com.aaa.bbb.ccc.MyCommand"></command> </extension> <extension point="org.eclipse.ui.menus"> <menuContribution locationURI="toolbar:com.aaa.bbb.ccc.MyView"> <command commandId="com.aaa.bbb.ccc.MyCommand" id="com.aaa.bbb.ccc.MyCommand" style="push"> <visibleWhen> <test property="com.aaa.bbb.ccc.MyTester.isValid"/> </visibleWhen> </command> </menuContribution> </extension>

...并且在发生应该导致工具栏更新的代码中,我有以下内容:

Display.getDefault().syncExec(new Runnable() { @Override public void run() { // update the toolbar buttons IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); ICommandService commandService = window.getService(ICommandService.class); if (commandService != null) { commandService.refreshElements("com.aaa.bbb.ccc.MyCommand", null); } IEvaluationService evaluationService = window.getService(IEvaluationService.class); if (evaluationService != null) { evaluationService.requestEvaluation("com.aaa.bbb.ccc.MyTester"); } } });

...有什么想法我把事情搞砸了吗?

java eclipse eclipse-rcp plugin.xml
1个回答
0
投票

evaluationService.requestEvaluation("com.aaa.bbb.ccc.MyTester");

evaluationService.requestEvaluation("com.aaa.bbb.ccc.MyTester.isValid");

修复了测试人员评估的问题。命令刷新结果是一个拼写错误:-/

© www.soinside.com 2019 - 2024. All rights reserved.