Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Obtaining reference to Action declared in plugin
Obtaining reference to Action declared in plugin [message #508115] Sat, 16 January 2010 01:51 Go to next message
AlesD is currently offline AlesDFriend
Messages: 12
Registered: July 2009
Junior Member
Hello,

I have a RCP application which contribute actions to menus and
toolbars. The action is defined via org.eclipse.ui.actionSets. It shows
properly in
menu and toolbar, but I'd like to add it also to SWT Button in one of the
views I crated. The button should show text and image configured in
action. I have found that I can create the button via
IContributionItem#fill(Composite) and I suppose that I shall use
ActionContributionItem implementation. To instantiate it I need IAction.

And here is my question: Is there a way to get instance implementing
org.eclipse.jface.action.IAction for the action defined in my (or 3rd
party) plug-in? Is there an example code snippet somewhere?

Or am I completely wrong and I can't mix declarative actions with JFace
actions.

Thanks in advance

Ales
Re: Obtaining reference to Action declared in plugin [message #508342 is a reply to message #508115] Mon, 18 January 2010 13:45 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

There's no reliable way to get that action, or even your
IActionDelegate. On run the current PluginAction will be handed to your
delegates run method so you can possibly update its attributes, but we
make no guarantees on how long that action will be around. i.e. on the
next run call we could hand you a different instance (although I don't
believe we do ATM)

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Obtaining reference to Action declared in plugin [message #508453 is a reply to message #508342] Mon, 18 January 2010 22:51 Go to previous messageGo to next message
AlesD is currently offline AlesDFriend
Messages: 12
Registered: July 2009
Junior Member
Paul Webster napsal(a):
> There's no reliable way to get that action, or even your
> IActionDelegate. On run the current PluginAction will be handed to your
> delegates run method so you can possibly update its attributes, but we
> make no guarantees on how long that action will be around. i.e. on the
> next run call we could hand you a different instance (although I don't
> believe we do ATM)
>
> PW
>
Thanks,

is it better with with extension points org.eclipse.ui.commands and
org.eclipse.ui.commandImages? I have found that some developers consider
the actions from org.eclipse.ui.actionSets inferior to commands and even
suggest their deprecation. It seems possible to obtain Command reference
via ICommandService using it's ID. The Command however miss the UI
properties like text and image.

Ales
Re: Obtaining reference to Action declared in plugin [message #508835 is a reply to message #508453] Wed, 20 January 2010 14:00 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

AlesD wrote:
>
> is it better with with extension points org.eclipse.ui.commands and
> org.eclipse.ui.commandImages? I have found that some developers consider
> the actions from org.eclipse.ui.actionSets inferior to commands and even
> suggest their deprecation. It seems possible to obtain Command reference
> via ICommandService using it's ID. The Command however miss the UI
> properties like text and image.

There's 2 parts to what you want to do, but I'm not sure what's enough.
If you use a command+hander and command images. you can create a
CommandContributionItem. It can fill the Composite with a button. You
create them with a
org.eclipse.ui.menus.CommandContributionItemParameter, it will fill in
the label from the command name, and the images from commandImages for
you (you can even override some of that information when you create the
CCI).

If you expect to dynamically update a command's menu item or tool item,
then your handler would implement IElementUpdater and ICommandService
can request a UI element refresh ... but that's probably solving a
different problem.

Actions (as implemented in JFace) are tightly coupled MVC. ActionSets
suffer from the same thing, they limit the lifecycle, position,
composition, and behaviour of the contribution. But they both still
work, exactly as they always have (they are not under active
development, though, but are so widespread it would generate a lot of
useless warning messages for us to officially deprecate them).

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Previous Topic:Eclipse plugins don't work
Next Topic:OperationHistory not cleaned after editor closed
Goto Forum:
  


Current Time: Fri Mar 29 14:04:52 GMT 2024

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

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

Back to the top