Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Accessing editor actionbar contribution
Accessing editor actionbar contribution [message #447767] Fri, 14 April 2006 16:26 Go to next message
Lukas Zapletal is currently offline Lukas ZapletalFriend
Messages: 44
Registered: July 2009
Member
Hello,

I have an action on the toolbar (contributed by my editor). Its a
radiobutton. Now I need to get a reference to this action object to
determine its state. How to do it?

Thanks

--
Best regards,
Lukas Zapletal
Re: Accessing editor actionbar contribution [message #447796 is a reply to message #447767] Sun, 16 April 2006 20:14 Go to previous messageGo to next message
Lukas Zapletal is currently offline Lukas ZapletalFriend
Messages: 44
Registered: July 2009
Member
Dne Fri, 14 Apr 2006 18:26:06 +0200
Lukas Zapletal <lukas.zapletal@linuxexpres.cz> napsal(a):

> I have an action on the toolbar (contributed by my editor). Its a
> radiobutton. Now I need to get a reference to this action object to
> determine its state. How to do it?

What I need - I have three checkbox buttons in the CoolBar and only
two of them can be activated in the same time. I do not know, how to
deactivate one since I do not have a reference to other actions from
the coolbar in the run(Action delegate) method.

I created them in the plugin.xml:

<action
class="cz.upol.jo.app.editors.actions.ConstrainZ"
id="cz.upol.jo.editoraction.constraintz"
label="Z"
state="false"
style="toggle"
toolbarPath="scene_constraint"/>
<action
class="cz.upol.jo.app.editors.actions.ConstrainY"
id="cz.upol.jo.editoraction.constrainty"
label="Y"
state="true"
style="toggle"
toolbarPath="scene_constraint"/>
<action
class="cz.upol.jo.app.editors.actions.ConstrainX"
id="cz.upol.jo.editoraction.constraintx"
label="X"
state="true"
style="toggle"
toolbarPath="scene_constraint"/>

I cannot find the method returning me the action (by an id).

--
Best regards,
Lukas Zapletal
Re: Accessing editor actionbar contribution [message #447809 is a reply to message #447796] Mon, 17 April 2006 14:34 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

From your IEditorSite you can get the IActionBars and the appropriate
manager. Then use IContributionManager#find(*) to find the
IContributionItem that you need.

You have to walk the hierarchy of the path you specified (toolbarPath,
menuPath, etc).

Later,
PW


Re: Accessing editor actionbar contribution [message #447822 is a reply to message #447809] Mon, 17 April 2006 18:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: childress.shapetechllc.com

Paul Webster wrote:

> From your IEditorSite you can get the IActionBars and the appropriate
> manager. Then use IContributionManager#find(*) to find the
> IContributionItem that you need.

> You have to walk the hierarchy of the path you specified (toolbarPath,
> menuPath, etc).

When you do this, you get a
org.eclipse.ui.internal.PluginActionContributionItem, which doesn't give
you access to any methods to query the state of the item if it
is a TOGGLE or RADIO button.

If you can get access to the ToolBar, you should be able to access the
ToolItem, which contains the information needed. But, I can't find a way
to do that.



Ken...
Re: Accessing editor actionbar contribution [message #447826 is a reply to message #447822] Mon, 17 April 2006 20:18 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Ken Childress wrote:
> When you do this, you get a
> org.eclipse.ui.internal.PluginActionContributionItem, which doesn't give
> you access to any methods to query the state of the item if it
> is a TOGGLE or RADIO button.

If it's a PluginActionContributionItem it's also a
org.eclipse.jface.action.ActionContributionItem, which has getAction().
IAction has an isChecked() method.


But this is a hack. I'm still looking for the proper way to access the
state of a contributed action.

Later,
PW


Re: Accessing editor actionbar contribution [message #447838 is a reply to message #447826] Mon, 17 April 2006 22:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: childress.shapetechllc.com

Paul Webster wrote:

> Ken Childress wrote:
>> When you do this, you get a
>> org.eclipse.ui.internal.PluginActionContributionItem, which doesn't give
>> you access to any methods to query the state of the item if it
>> is a TOGGLE or RADIO button.

> If it's a PluginActionContributionItem it's also a
> org.eclipse.jface.action.ActionContributionItem, which has getAction().
> IAction has an isChecked() method.


> But this is a hack. I'm still looking for the proper way to access the
> state of a contributed action.

Thanks. This seems to work. I would be interested in knowing if there is
a better way of doing this.



Ken...
Re: Accessing editor actionbar contribution [message #447942 is a reply to message #447767] Tue, 18 April 2006 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

The way that these things are moving is to Commands, Handlers, and Bindings.

It looks like you can use definitionId in your action declaration to
link it to a command. Define a command in the org.eclipse.ui.commands
extension point. Using a definitionId and a command turns the legacy
actionSet or editorAction actions into handlers.

Use ICommandServer#getCommand(String commandId) to get the Command.

From Command, you can use getState(IMenuStateIds.STYLE), and then if
your command state is an instance of ToggleState, use
((Boolean)state.getValue()).booleanValue().

Later,
PW


Re: Accessing editor actionbar contribution [message #448136 is a reply to message #447942] Tue, 18 April 2006 22:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: childress.shapetechllc.com

Paul Webster wrote:

> The way that these things are moving is to Commands, Handlers, and Bindings.

> It looks like you can use definitionId in your action declaration to
> link it to a command. Define a command in the org.eclipse.ui.commands
> extension point. Using a definitionId and a command turns the legacy
> actionSet or editorAction actions into handlers.

> Use ICommandServer#getCommand(String commandId) to get the Command.

> From Command, you can use getState(IMenuStateIds.STYLE), and then if
> your command state is an instance of ToggleState, use
> ((Boolean)state.getValue()).booleanValue().

I tried what you suggest. I created a command, and put its id as the
definitionId of the editorAction. Then, I tried to access it via,

CommandManager manager = new CommandManager();
Command command = manager.getCommand( "commandId" );

At this point, I'm not seeing any way to get at the state or other
information about the contribution. Am I missing something or doing
something wrong?



Ken...
Re: Accessing editor actionbar contribution [message #448221 is a reply to message #448136] Wed, 19 April 2006 11:39 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You need the command service.

Object serviceObject = PlatformUI.getWorkbench()
.getAdapter(ICommandService.class);
if (serviceObject != null) {
ICommandService service = (ICommandService) serviceObject;
..............
}

In 3.1.2 I think you would need the global command service, and in 3.1.2
you use getAdapter(*) to retrieve services.

In 3.2, the services should be retrieved from the IServiceLocator
"closest" to them. i.e. in an editor, you would use
getSite().getService(ICommandService.class).

Later,
PW


Re: Accessing editor actionbar contribution [message #448351 is a reply to message #448221] Fri, 21 April 2006 15:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: childress.shapetechllc.com

Paul Webster wrote:

> You need the command service.

> Object serviceObject = PlatformUI.getWorkbench()
> .getAdapter(ICommandService.class);
> if (serviceObject != null) {
> ICommandService service = (ICommandService) serviceObject;
> ..............
> }

> In 3.1.2 I think you would need the global command service, and in 3.1.2
> you use getAdapter(*) to retrieve services.

I appreciate you trying to help me, but I'm just not seeing how this
helps. Once I have the ICommandService, I still don't understand how to
get at the information I need to find out the state of the button. I can
get the Command using the command's id, but I still see no way of getting
to the state of the button.



Ken...
Re: Accessing editor actionbar contribution [message #448381 is a reply to message #448351] Mon, 24 April 2006 13:15 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Ken Childress wrote:
>
> I appreciate you trying to help me, but I'm just not seeing how this
> helps. Once I have the ICommandService, I still don't understand how to
> get at the information I need to find out the state of the button. I
> can get the Command using the command's id, but I still see no way of
> getting to the state of the button.

From Command, you can use Command#getState(IMenuStateIds.STYLE), and
then if your command state is an instance of ToggleState, use
((Boolean)state.getValue()).booleanValue().

Later,
PW


Re: Accessing editor actionbar contribution [message #448442 is a reply to message #448381] Mon, 24 April 2006 22:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: childress.shapetechllc.com

Paul Webster wrote:

> Ken Childress wrote:
>>
>> I appreciate you trying to help me, but I'm just not seeing how this
>> helps. Once I have the ICommandService, I still don't understand how to
>> get at the information I need to find out the state of the button. I
>> can get the Command using the command's id, but I still see no way of
>> getting to the state of the button.

> From Command, you can use Command#getState(IMenuStateIds.STYLE), and
> then if your command state is an instance of ToggleState, use
> ((Boolean)state.getValue()).booleanValue().

Are we talking 3.1.2?

I don't see a getState method in the Command class.



Ken...
Re: Accessing editor actionbar contribution [message #448517 is a reply to message #448442] Tue, 25 April 2006 17:16 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Ken Childress wrote:
> Are we talking 3.1.2?
>
> I don't see a getState method in the Command class.
>

ah, I'm on 3.2. It doesn't look like there are equivalent methods on 3.1.x.

Later,
PW


Previous Topic:Coolbar with other hoverstyle
Next Topic:NoSuchMethodError in Product Release
Goto Forum:
  


Current Time: Fri Jan 03 03:43:20 GMT 2025

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

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

Back to the top