Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Sharing state between different commands
Sharing state between different commands [message #642941] Fri, 03 December 2010 12:41 Go to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
We have the following situation where it would be nice to realize state
sharing between *different* commands.

E.g. consider a org.eclipse.ui.commands command that describes a
radio-state where we re-use the org.eclipse.ui.commands.radioState state
as nicely described in the article:

http://blog.eclipse-tips.com/2009/03/commands-part-6-toggle- radio-menu.html

The radio-state we are administrating here is some look&feel identifier
and the corresponding handler applies this look&feel - this works
without problems.

Now we have a *different* command, which is supposed perform two steps:

1) Loading data into a viewer
2) Applying the look&feel as controlled by above radio-state-handler

Step (1) is specific for the second command (handler), no question, but
ideally - to realize (2) - we would like to evaluate the state of the
first radio-state handler to do different stuff based on that state. The
problem is, that by quering

event.getParameter(RadioState.PARAMETER_ID)

we obviously get null, because we are asking the wrong event for it. Is
there a way to ask for the specific parameter value of another command
in this context?

I know that I could use an AbstractSourceProvider to share state
globally, but that would (IMO) not allow to take advantage of the
additional command parameter functionality (e.g. defining the radio
state at the org.eclipse.ui.menus implementation).

Is there some way to realize that?

Thanks & Greetings from Bremen,

Daniel Krügler
Re: Sharing state between different commands [message #642949 is a reply to message #642941] Fri, 03 December 2010 13:09 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 12/3/2010 13:41, Daniel Krügler wrote:
> We have the following situation where it would be nice to realize state
> sharing between *different* commands.
>
> E.g. consider a org.eclipse.ui.commands command that describes a
> radio-state where we re-use the org.eclipse.ui.commands.radioState state
> as nicely described in the article:
>
> http://blog.eclipse-tips.com/2009/03/commands-part-6-toggle- radio-menu.html
>
> The radio-state we are administrating here is some look&feel identifier
> and the corresponding handler applies this look&feel - this works
> without problems.
>
> Now we have a *different* command, which is supposed perform two steps:
>
> 1) Loading data into a viewer
> 2) Applying the look&feel as controlled by above radio-state-handler
>
> Step (1) is specific for the second command (handler), no question, but
> ideally - to realize (2) - we would like to evaluate the state of the
> first radio-state handler to do different stuff based on that state. The
> problem is, that by quering
>
> event.getParameter(RadioState.PARAMETER_ID)
>
> we obviously get null, because we are asking the wrong event for it. Is
> there a way to ask for the specific parameter value of another command
> in this context?

Let me add more information: Since after (1) we want to invoke the first
radio-state handler I used the IHandlerService.executeCommand method
(with second argument null): That invokes the right command, but it's
state values are all null. How can I activate the handler such that it's
current state is transmitted as well?

> I know that I could use an AbstractSourceProvider to share state
> globally, but that would (IMO) not allow to take advantage of the
> additional command parameter functionality (e.g. defining the radio
> state at the org.eclipse.ui.menus implementation).
>
> Is there some way to realize that?
>
> Thanks & Greetings from Bremen,
>
> Daniel Krügler
Re: Sharing state between different commands [message #643025 is a reply to message #642941] Fri, 03 December 2010 17:08 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
On 03/12/10 6:11 PM, Daniel Krügler wrote:
> We have the following situation where it would be nice to realize state
> sharing between *different* commands.

> Now we have a *different* command, which is supposed perform two steps:
>
> 1) Loading data into a viewer
> 2) Applying the look&feel as controlled by above radio-state-handler
>
> Step (1) is specific for the second command (handler), no question, but
> ideally - to realize (2) - we would like to evaluate the state of the
> first radio-state handler to do different stuff based on that state. The
> problem is, that by quering
>
> event.getParameter(RadioState.PARAMETER_ID)

You need to get hold of the command (probably from ICommandService) and
then call radioStateCommand.getState() to get the current state.

--
- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: Sharing state between different commands [message #643027 is a reply to message #642949] Fri, 03 December 2010 17:10 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
On 03/12/10 6:39 PM, Daniel Krügler wrote:

> Let me add more information: Since after (1) we want to invoke the first
> radio-state handler I used the IHandlerService.executeCommand method
> (with second argument null): That invokes the right command, but it's
> state values are all null. How can I activate the handler such that it's
> current state is transmitted as well?

I guess you are calling executeCommand(String, Event). Call the
overloaded method executeCommand(ParameterisedCommand, Event)

--
- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: Sharing state between different commands [message #643233 is a reply to message #643027] Mon, 06 December 2010 08:15 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 12/3/2010 18:10, Prakash G.R. wrote:
> On 03/12/10 6:39 PM, Daniel Krügler wrote:
>
>> Let me add more information: Since after (1) we want to invoke the first
>> radio-state handler I used the IHandlerService.executeCommand method
>> (with second argument null): That invokes the right command, but it's
>> state values are all null. How can I activate the handler such that it's
>> current state is transmitted as well?
>
> I guess you are calling executeCommand(String, Event).

Yes, this is correct.

> Call the
> overloaded method executeCommand(ParameterisedCommand, Event)

Hmmh, maybe I'm misunderstanding something fundamental, but wouldn't
this imply that I need to fill the first argument with the corresponding
parameter values on my own? If so, this is not my intention: The
corresponding command get's it's parameter values from it's own state
that I don't want to manually change. What I don't understand is that
this state seems to be empty when invoked via the first executeCommand
overload.

Thanks & Greetings from Bremen,

Daniel Krügler
Re: Sharing state between different commands [message #643269 is a reply to message #643025] Mon, 06 December 2010 10:32 Go to previous message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 12/3/2010 18:08, Prakash G.R. wrote:
> On 03/12/10 6:11 PM, Daniel Krügler wrote:
>> We have the following situation where it would be nice to realize state
>> sharing between *different* commands.
>
>> Now we have a *different* command, which is supposed perform two steps:
>>
>> 1) Loading data into a viewer
>> 2) Applying the look&feel as controlled by above radio-state-handler
>>
>> Step (1) is specific for the second command (handler), no question, but
>> ideally - to realize (2) - we would like to evaluate the state of the
>> first radio-state handler to do different stuff based on that state. The
>> problem is, that by quering
>>
>> event.getParameter(RadioState.PARAMETER_ID)
>
> You need to get hold of the command (probably from ICommandService) and
> then call radioStateCommand.getState() to get the current state.

Thanks Prakash: Yes, I finally found this solution and it is the correct
one, if I would just to implement my own logic based on this state.

What I don't understand is the following: If I want to invoke another
command from the given command with state via the IHandlerService, I
cannot do this via the

Object executeCommand(String commandId, Event event);

method, but must instead use the overload:

Object executeCommand(ParameterizedCommand command, Event event);

This looks odd to me, because the parameter is a result of an associated
state. Let's assume that the called handler has a
org.eclipse.ui.handlers.RadioState, I now must create a
ParameterizedCommand object that is filled with the state that I need to
read from the command, because otherwise the command parameter within
the called command is not set (null).

I understand that it must be empty, because no-one has set it yet
(usually the menu contribution will set it). So one might assume that
the command should not ask for the parameter but for the state instead.
This would also not work, because then it would never change its radio
state, though.

I think what I'm missing would be a function that just created a
ParameterizedCommand based on the parameter state - Does there exist
something like that?

Thanks & Greetings from Bremen,

Daniel Krügler
Previous Topic:Problem in creating new rcp project when rap is installed
Next Topic:Can I open a view in detached mode programmatically?
Goto Forum:
  


Current Time: Tue Apr 23 07:56:29 GMT 2024

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

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

Back to the top