What I am trying to do: I am trying to programmatically trigger the showing / hiding / enabling / disabling of an icon on the toolbar. This does not work. However I do see the show / hide / enable / disable functionality 'kick in' whenever the view focus changes (so I think the XML is valid).
What I am doing: in plugin.xml I have the following (ID / class names changed):
<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>
... and in the code where things happen that should result in a toolbar update I have the following:
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");
}
}
});
... any ideas where I'm messing things up?
Changing
evaluationService.requestEvaluation("com.aaa.bbb.ccc.MyTester");
to
evaluationService.requestEvaluation("com.aaa.bbb.ccc.MyTester.isValid");
fixed the issue with the tester evaluation. The command refresh turned out to be a typo :-/