Home » Eclipse Projects » Rich Client Platform (RCP) » How to sync radio-menuitems with the toolbar
How to sync radio-menuitems with the toolbar [message #666534] |
Wed, 20 April 2011 18:35 |
Carlo Salinari Messages: 66 Registered: October 2010 |
Member |
|
|
Hi,
In my app, a cad-like program, I have a menu called Tools containing a
group of drawing-related commands (Line, Rectangle, Polygon..) with
style radio (only one tool at a time can be selected).
I also have a toolbar with the same drawing commands.
How do I keep the menu and the toolbar radio groups in sync?
I mean, when I select Line in the menu I'd want to see it reflected also
in the toolbar (Line button pushed down) and vice-versa, if I push a
toolbar button (say, I press the Rectangle) see it selected in the menu.
I thought that, since they share the same command.ids and handlers, it
would work automatically, but it doesn't (they behave as two unrelated
radio groups).
Cheers,
Carlo
|
|
| | | |
Re: How to sync radio-menuitems with the toolbar [message #666865 is a reply to message #666655] |
Sat, 23 April 2011 16:02 |
Carlo Salinari Messages: 66 Registered: October 2010 |
Member |
|
|
On 4/21/2011 3:22 PM, Paul Webster wrote:
> On 04/20/2011 04:33 PM, Carlo Salinari wrote:
>> for (String id : (Collection<String>) service.getDefinedCommandIds()) {
>> service.refreshElements(id, null);
>> }
>> return null;
>
> This is in effect trying to refresh every command in the system. You
> can find your command id from the event, and only refresh that (at the
> end of your handler).
>
>>
>> Also, I'm not explicitly defining Radio states in plugin.xml. Could this
>> be part of the problem?
>
> Using commands with radio buttons involves creating a radio state as
> part of the command definition, and then creating the radio parameter as
> part of the menuContribution/command elements.
>
> When actually updating elements, you then compare the radio parameter
> that would be passed into updateElement(*) and set checked appropriately.
>
> Have a look at the org.eclipse.example.commands plugin in
> https://github.com/paulweb515/commandsEclipseCon2011
>
> That has an example of setting up a group of radio buttons with
> commands. Once you have that, then you can look at managing 2 of them.
>
Thanks a lot for the pointers. The presentation is really helpful, even
if a bit terse. I'll probably harass you in the near future about the
5/6 patterns whose existence I totally ignored! :-)
For now, I have a much dumber problem: I can't run the
org.eclipse.example.commands plugin.
When I try to export it (so that I can put it in my eclipse\plugins dir)
I get an error in the builder @dot.log saying:
"Syntax error, annotations are only available if source level is 1.5"
I've (more than) triple checked that the compiler compliance level is
set to 1.6 everywhere. I've even deleted .metadata and reinstalled
eclipse (helios), but no luck. Do you have any idea how to solve this?
Carlo
|
|
| | | | |
Re: How to sync radio-menuitems with the toolbar [message #667025 is a reply to message #667024] |
Mon, 25 April 2011 16:55 |
Carlo Salinari Messages: 66 Registered: October 2010 |
Member |
|
|
On 4/25/2011 5:19 PM, Paul Webster wrote:
> On 04/25/2011 10:41 AM, Carlo Salinari wrote:
>>
>> by chance, is there any video/audio recording of your presentations?
>
> I had a look at http://www.eclipsecon.org/2011/ and didn't see a link to
> presentation recordings, they probably didn't make recordings of the
> sessions.
Pity.
First quick question about pattern 4 (radio buttons):
I see that the first time the plugin is loaded the choice "page" is
selected, as indicated by the state element
<state
class="org.eclipse.ui.handlers.RadioState:page"
id="org.eclipse.ui.commands.radioState">
</state>
in the declaration of the org.eclipse.example.commands.viewPage command.
Then, if I select "Outline" and then restart the ide, the state is
evidently persisted and then restored, because when I reopen the View
menu I see "Outline" selected.
So, the persisted state (outline) wins over the declaration-based
initial state (page).
How can I change this behavior, so that, no matter what, when the plugin
starts the initial command state is always set to "page"?
|
|
| |
Re: How to sync radio-menuitems with the toolbar [message #667028 is a reply to message #667027] |
Mon, 25 April 2011 19:26 |
Carlo Salinari Messages: 66 Registered: October 2010 |
Member |
|
|
On 4/25/2011 7:32 PM, Paul Webster wrote:
> On 04/25/2011 12:55 PM, Carlo Salinari wrote:
>>
>> How can I change this behavior, so that, no matter what, when the plugin
>> starts the initial command state is always set to "page"?
>
> See
> org.eclipse.ui.handlers.RadioState.setInitializationData(ICo nfigurationElement,
> String, Object)
>
> You can use the other format for executable extension and supply
> multiple parameters:
>
> <state id="org.eclipse.ui.commands.radioState">
> <class class="org.eclipse.ui.handlers.RadioState">
> <parameter name="default" value="page"/>
> <parameter name="persisted" value="false"/>
> </class>
> </state>
>
> or something similar to above (I'm not 100% sure about the syntax).
Yep, it works.
For the record, I re-created my use-case (radio commands shared by both
menu and toolbar) inside your example plugin and it worked (making me
happy as a lark :-) ).
Here is how I proceeded:
1. I created four commands in the toolbar menuContribution (Page,
Outline, Notes, Master)
2. Set the commandId to org.eclipse.example.commands.viewPage
3. Set the style to "radio"
4. Manually edited the contributions' command-element to include the
radioStateParameter, here is one for reference:
<command
commandId="org.eclipse.example.commands.viewPage"
label="Page"
mode="FORCE_TEXT"
style="radio">
<parameter
name="org.eclipse.ui.commands.radioStateParameter"
value="page">
</parameter>
</command>
To my surprise, this even works if your radio group spans more than one
menu, or if it contains separators (this is different from swt's normal
behavior).
|
|
|
Goto Forum:
Current Time: Thu Apr 25 22:22:44 GMT 2024
Powered by FUDForum. Page generated in 0.03700 seconds
|