I want to be able to control when a particular command can be enabled in a toolbar. Currently this is in my plugin.xml
file:
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="my.plugin.handler.Terminate"
description="Terminate session"
id="my.plugin.terminate"
name="Terminate">
</command>
</extension>
<extension
point="org.eclipse.ui.commandImages">
<image
commandId="my.plugin.terminate"
icon="icons/terminate.gif">
</image>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="toolbar:my.plugin.views.RuntimeSessionsView">
<command
commandId="my.plugin.terminate"
disabledIcon="icons/terminate_dis.gif"
icon="icons/terminate.gif"
style="push">
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="my.plugin.handler.Terminate"
commandId="my.plugin.terminate">
<enabledWhen>
<with
variable="canTerminate">
<equals
value="true">
</equals>
</with>
</enabledWhen>
</handler>
</extension>
And here is what I get in the console:
!ENTRY org.eclipse.ui.workbench 2 0 2015-03-11 11:59:05.237
!MESSAGE A handler conflict occurred. This may disable some commands.
!SUBENTRY 1 org.eclipse.ui.workbench 2 0 2015-03-11 11:59:05.237
!MESSAGE Conflict for 'my.plugin.terminate':
HandlerActivation(commandId=my.plugin.terminate,
handler=my.plugin.handler.Terminate,
expression=,sourcePriority=0)
HandlerActivation(commandId=my.plugin.terminate,
handler=my.plugin.handler.Terminate,
expression=,sourcePriority=0)
WARNING 15-03-11,11:59:05 (0) Conflict for 'my.plugin.terminate':
HandlerActivation(commandId=my.plugin.terminate,
handler=my.plugin.handler.Terminate,
expression=,sourcePriority=0)
HandlerActivation(commandId=my.plugin.terminate,
handler=my.plugin.handler.Terminate,
expression=,sourcePriority=0)
Conflict for 'my.plugin.terminate':
HandlerActivation(commandId=my.plugin.terminate,
handler=my.plugin.handler.Terminate,
expression=,sourcePriority=0)
HandlerActivation(commandId=my.plugin.terminate,
handler=my.plugin.handler.Terminate,
expression=,sourcePriority=0)
Currently the my.plugin.terminate
command is disabled and I am getting this error message. It would disappear if I would deleted the last extension point ("org.eclipse.ui.handlers"), but then the my.plugin.terminate
command would be enabled again.
➤ What I want to achieve is to be able to control the enabled / disabled state of this command. How can I do this?
You have specified the same handler in the command default handler and the handler extension point. Since they are both active you get a conflict.
Don't specify the default handler.