I have several plugins where commands need to be disabled when the user isn’t logged in. This is done via an ISourceProvider. In one plugin.xml I have:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu">
<menu
id="menus.arm"
label="%menu.label"
mnemonic="%menu.mnemonic">
<command
commandId="ru.focusmedia.odp.arm.commands.login"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="arm.variables.loggedIn">
<equals
value="false">
</equals>
</with>
</visibleWhen>
</command>
<command
commandId="ru.focusmedia.odp.arm.commands.logout"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="arm.variables.loggedIn">
<equals
value="true">
</equals>
</with>
</visibleWhen>
</command>
<command
commandId="org.eclipse.ui.file.exit"
label="%command.label"
style="push"
tooltip="%command.tooltip">
</command>
</menu>
<menu
id="menus.help"
label="%menu.label.0"
mnemonic="%menu.mnemonic.0">
<command
commandId="org.eclipse.ui.help.aboutAction"
label="%command.label.0"
style="push"
tooltip="%command.tooltip.0">
</command>
</menu>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="ru.focusmedia.odp.arm.login.LogoutHandler"
id="ru.focusmedia.odp.arm.commands.logout"
name="%command.name.logout">
</command>
<command
defaultHandler="ru.focusmedia.odp.arm.login.LoginHandler"
id="ru.focusmedia.odp.arm.commands.login"
name="%command.name.login">
</command>
</extension>
<extension
point="org.eclipse.ui.services">
<sourceProvider
provider="ru.focusmedia.odp.arm.login.LoginStateSourceProvider">
<variable
name="arm.variables.loggedIn"
priorityLevel="workbench">
</variable>
</sourceProvider>
</extension>
This works fine; the correct command is visible all the time. In another plugin, which depends on this one, I have
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="ru.focusmedia.odp.arm.alarms.RequestMoreAlarmsHandler"
id="arm.alarms.commands.request_more_alarms"
name="Request more alarms">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="ru.focusmedia.odp.arm.alarms.RequestMoreAlarmsHandler"
commandId="arm.alarms.commands.request_more_alarms">
<enabledWhen>
<with
variable="arm.variables.loggedIn">
<equals
value="true">
</equals>
</with>
</enabledWhen>
</handler>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:arm.views.alarms">
<command
commandId="arm.alarms.commands.request_more_alarms"
style="push">
</command>
</menuContribution>
</extension>
And this command is disabled all the time. What’s going wrong?
There is a conflict between handler definitions in
<command defaultHandler=...and<handler .... After removing thedefaultHandlerattribute, it works fine.