I contributed a toggle-style toolbar contribution to my view in my RCP. Now, i want to know how to set the button's state (since it's a toggle button) from my view. Or, at least, how to initialize it's state after the view is loaded (the toggle state can vary, its not static)
I tried to call from my view: getViewSite().getActionBars().getMenuManager().getItems() (returns an array of IContributionElements), which i iterated over and looked for the id. but the array only contains the models of the buttons, and there is no possibility to change the selection through these objects.
Help!!
In the definition of your command (in plug-in.xml) that the CommandContributionItem
calls into, define a state element like the following:
<state class="org.eclipse.ui.handlers.RegistryToggleState:true"
id="org.eclipse.ui.commands.toggleState">
</state>
The above will initialise the state (toggle on/off) to either true/false depending on what you specify after the 'RegistryToggleState:' section.
To change the state within your code, first get the reference to your ParamterizedCommand
like you did before. Then get the reference to the underyling Command
object from the ParamaterizedCommmand
and call:
HandlerUtil.toggleCommandState(command);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With