Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to check Radio in Menu Contribution
How to check Radio in Menu Contribution [message #452317] Sat, 01 August 2009 12:56 Go to next message
Kai Schlamp is currently offline Kai SchlampFriend
Messages: 344
Registered: July 2009
Senior Member
Hi.

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
Re: How to check Radio in Menu Contribution [message #452780 is a reply to message #452317] Sat, 01 August 2009 14:00 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

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


Re: How to check Radio in Menu Contribution [message #452864 is a reply to message #452780] Sat, 01 August 2009 14:07 Go to previous messageGo to next message
Kai Schlamp is currently offline Kai SchlampFriend
Messages: 344
Registered: July 2009
Senior Member
Thanks Paul.

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
>
>
Re: How to check Radio in Menu Contribution [message #453558 is a reply to message #452780] Sat, 01 August 2009 15:57 Go to previous messageGo to next message
Kai Schlamp is currently offline Kai SchlampFriend
Messages: 344
Registered: July 2009
Senior Member
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
>
>
Re: How to check Radio in Menu Contribution [message #454727 is a reply to message #453558] Sat, 01 August 2009 18:49 Go to previous messageGo to next message
Kai Schlamp is currently offline Kai SchlampFriend
Messages: 344
Registered: July 2009
Senior Member
Here my workaround, but I don't think that this is the way it should be. For me RadioState doesn't
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
>>
>>
Re: How to check Radio in Menu Contribution [message #479340 is a reply to message #454727] Mon, 10 August 2009 17:33 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Are you activating the handler yourself, or including it from a plugin.xml? From the plugin.xml it should go through org.eclipse.ui.internal.handlers.HandlerProxy.updateElement( UIElement, Map) which should handle the checked state for you.

If it is not, please open a bug https://bugs.eclipse.org/bugs/enter_bug.cgi?product=E4&c omponent=UI

PW


Previous Topic:PSF files : specify revision number of a project
Next Topic:Test Framework Update Site
Goto Forum:
  


Current Time: Wed Apr 24 23:38:54 GMT 2024

Powered by FUDForum. Page generated in 0.02936 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top