|
|
|
|
|
|
|
|
|
|
Re: How to use global actions in a context menu [message #464200 is a reply to message #464145] |
Tue, 27 February 2007 11: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.27322 seconds