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

sg24os4d  于 2023-10-18  发布在  Eclipse
关注(0)|答案(1)|浏览(142)

我正在尝试做什么:我正在尝试以编程方式触发工具栏上图标的显示/隐藏/启用/禁用。这行不通。然而,我确实看到显示/隐藏/启用/禁用功能'踢'每当视图焦点改变(所以我认为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");
            }

        }
        
    });

你知道我把事情搞砸了吗

fhg3lkii

fhg3lkii1#

改变

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

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

修复了测试仪评估的问题。命令refresh原来是一个错字:-/

相关问题