How to use global actions in a context menu [message #464018] |
Thu, 22 February 2007 08:14  |
Eclipse User |
|
|
|
Hi. I am new to the rcp framework but I already like it a lot. At the
moment I am trying to figure out how I can use a global action within a
views context menu (and the view-toolbar). For the menubar this is easy
with the ActionFactory and the methods register and getAction, but in my
view I don't have the method getAction(id) available and I cant get an
IAction from the ActionFactory??
Or am I totaly wrong here?
Thanks in advance
--Marc
|
|
|
|
|
|
|
|
|
|
|
|
Re: How to use global actions in a context menu [message #464200 is a reply to message #464145] |
Tue, 27 February 2007 06:20   |
Eclipse User |
|
|
|
Originally posted by: 11235813.despammed.com
Marc Schlegel schrieb:
> Robert, thank you very much for your help..it works just fine.
>
> I added a private class (ActionRegistry) in my RcpPlugin (the Activator)
> where I store all this global actions in a HashMap.
Thanks for your solution.
A few days ago, when I was faced with the same problem, I tried 2
similar approaches: One was to create the actions as Singletons and to
ask for the single instance (doing well, but not very elegant), the
other one was very similar to yours. I added a public function
getGlobalAction(String actionId) to the ApplicationActionBarAdvisor
class, which returns the action with the given id:
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
private static ApplicationActionBarAdvisor advisor = null;
public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
super(configurer);
advisor = this;
}
public static IAction getGlobalAction(String actionId) {
if (advisor != null)
return getAction(actionId);
return null;
}
}
Ok, I have a singleton, too, but now the singleton is the advisor, not
each of the actions. The advisor 'knows' all of the registered actions
via getAction(...). My own actions are declared and created the way the
ActionFactory does it (MyActionFactory), so I can use
MyActionFactory.EXAMPLEACTION.getId() everywhere in the plugin to get
the id of one of my own actions.
Can someone with more experience give me some feedback about this
solution? The solution is doing well, but IMHO it's not the Eclipse-way :-)
>
> Maybe there will be a more sophisticated solution in the next Eclipse
> release (or there is one already but we just didn't see it :-) ).
I really hope so, too.
> The
> Platform must store the actions somewhere (remember the register-method)
> and it would be nice to access this Registry directly with a simple id.
Yes. The platform stores the values in the actions field of the
ActionAdvisor. But the access is protected.
Regards,
Carmen
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04340 seconds