Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsHow to check Radio in Menu Contribution
https://www.eclipse.org/forums/index.php/mv/msg/143652/452317/#msg_452317
I programmatically added some commands by doing
LayoutResultGraphAction layoutResultGraphAction = new LayoutResultGraphAction();
service.activateHandler("org.pubcurator.core.commands.option1 ", new ActionHandler(Option1Action));
and added those as sub menus to a toolbar pulldown menu contribution as radio buttons.
They show up correctly, but I don't know how to check them when clicked.
A option1Action.setChecked(true) does nothing.
How do I do that?
Regards,
Kai]]>Kai Schlamp2009-08-01T12:56:08-00:00Re: How to check Radio in Menu Contribution
https://www.eclipse.org/forums/index.php/mv/msg/143652/452780/#msg_452780
To support toggle or radio menu contributions you need to write a handler
that can implement org.eclipse.ui.commands.IElementUpdater
It has a method that will be called for each UIElement, and supports
setChecked(*)
The examples need to be updated to show they understand State support
(early activation is no longer necessary to maintain the checked state
across restarts).
PW]]>Paul Webster2009-08-01T14:00:04-00:00Re: How to check Radio in Menu Contribution
https://www.eclipse.org/forums/index.php/mv/msg/143652/452864/#msg_452864
I also just found that blog entry http://blog.eclipse-tips.com/2009/03/commands-part-6-toggle- radio-menu.html
I think I will from now on directly use Handlers (I even don't know why I only used Actions until now).
Regards,
Kai
Paul Webster wrote:
> AFAIK it won't link up a toggle or radio action with a menu
> contribution. To support toggle or radio menu contributions you need to
> write a handler that can implement org.eclipse.ui.commands.IElementUpdater
>
> It has a method that will be called for each UIElement, and supports
> setChecked(*)
>
>
> See:
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Menu_Contributions#Example_Matrix
>
> The examples need to be updated to show they understand State support
> (early activation is no longer necessary to maintain the checked state
> across restarts).
>
> PW
>
>]]>Kai Schlamp2009-08-01T14:07:15-00:00Re: How to check Radio in Menu Contribution
https://www.eclipse.org/forums/index.php/mv/msg/143652/453558/#msg_453558
http://blog.eclipse-tips.com/2009/03/commands-part-6-toggle- radio-menu.html
I would assume now that this would be enough to check that menu item by default (parameter value is
the same as state value), but it is not checked. Did I understand the RadioState thing wrong?
I also tried a HandlerUtil.updateRadioState(event.getCommand(), "state1"); in my programmatically
provided Handler, but still ... the menu item is not checked :-(
Regards,
Kai
Paul Webster wrote:
> AFAIK it won't link up a toggle or radio action with a menu
> contribution. To support toggle or radio menu contributions you need to
> write a handler that can implement org.eclipse.ui.commands.IElementUpdater
>
> It has a method that will be called for each UIElement, and supports
> setChecked(*)
>
>
> See:
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Menu_Contributions#Example_Matrix
>
> The examples need to be updated to show they understand State support
> (early activation is no longer necessary to maintain the checked state
> across restarts).
>
> PW
>
>]]>Kai Schlamp2009-08-01T15:57:52-00:00Re: How to check Radio in Menu Contribution
https://www.eclipse.org/forums/index.php/mv/msg/143652/454727/#msg_454727
work on it's own.
private class SetLayoutAlgorithmHandler extends AbstractHandler implements IElementUpdater {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
String state = event.getParameter(RadioState.PARAMETER_ID);
HandlerUtil.updateRadioState(event.getCommand(), state);
// Do what has to be done.
return null;
}
@SuppressWarnings("unchecked")
@Override
public void updateElement(UIElement element, Map parameters) {
String state = (String) parameters.get(RadioState.PARAMETER_ID);
ICommandService service = (ICommandService)
element.getServiceLocator().getService(ICommandService.class );
State commandState =
service.getCommand("org.pubcurator.core.commands.setLayoutAlgorithm ").getState(RadioState.STATE_ID);
if (commandState.getValue().equals(state)) {
element.setChecked(true);
}
}
}
Kai Schlamp wrote:
> As mentioned I now tried it with RadioState like described in that blog
> entry:
> http://blog.eclipse-tips.com/2009/03/commands-part-6-toggle- radio-menu.html
>
> I added the command:
>
> <command
> id="org.pubcurator.core.commands.setLayoutAlgorithm"
> name="Set Layout Algorithm">
> <commandParameter
> id="org.eclipse.ui.commands.radioStateParameter"
> name="State"
> optional="false">
> </commandParameter>
> <state
> class="org.eclipse.ui.handlers.RadioState:state1"
> id="org.eclipse.ui.commands.radioState">
> </state>
> </command>
>
> and added the menu item:
>
> <menuContribution
> locationURI="menu:org.pubcurator.core.menus.layoutResultGraph ">
> <command
> commandId="org.pubcurator.core.commands.setLayoutAlgorithm"
> label="Layout Algorithm A"
> style="radio">
> <parameter
> name="org.eclipse.ui.commands.radioStateParameter"
> value="state1">
> </parameter>
> </command>
> </menuContribution>
>
> I would assume now that this would be enough to check that menu item by
> default (parameter value is the same as state value), but it is not
> checked. Did I understand the RadioState thing wrong?
> I also tried a HandlerUtil.updateRadioState(event.getCommand(),
> "state1"); in my programmatically provided Handler, but still ... the
> menu item is not checked :-(
>
> Regards,
> Kai
>
>
>
>
> Paul Webster wrote:
>> AFAIK it won't link up a toggle or radio action with a menu
>> contribution. To support toggle or radio menu contributions you need
>> to write a handler that can implement
>> org.eclipse.ui.commands.IElementUpdater
>>
>> It has a method that will be called for each UIElement, and supports
>> setChecked(*)
>>
>>
>> See:
>> http://wiki.eclipse.org/Platform_Command_Framework
>> http://wiki.eclipse.org/Menu_Contributions#Example_Matrix
>>
>> The examples need to be updated to show they understand State support
>> (early activation is no longer necessary to maintain the checked state
>> across restarts).
>>
>> PW
>>
>>]]>Kai Schlamp2009-08-01T18:49:12-00:00Re: How to check Radio in Menu Contribution
https://www.eclipse.org/forums/index.php/mv/msg/143652/479340/#msg_479340
If it is not, please open a bug https://bugs.eclipse.org/bugs/enter_bug.cgi?product=E4&c omponent=UI