|
Re: Share data between plugins? [message #328723 is a reply to message #328721] |
Mon, 02 June 2008 19:27 |
Eclipse User |
|
|
|
Originally posted by: kosta.bea.com
You can generally assume that your plugin will stay loaded once it gets
activated. If you second plugin declares a dependency on the first via
the Require-Bundle clause in MANIFEST.MF then all exported packages and
classes of the first plugin will be visible to the second.
- Konstantin
|
|
|
|
Re: Share data between plugins? [message #328741 is a reply to message #328721] |
Tue, 03 June 2008 13:55 |
Eclipse User |
|
|
|
Originally posted by: eclipse-news.rizzoweb.com
Hauke Fuhrmann wrote:
> Hi there,
>
> what is the right design pattern to achieve this:
>
> I have two plugins. The one implements some stateless action within
> Eclipse (i.e. GMF Layout Provider).
> Now I want to add some state (some internal data) and make my other
> plugin listen to changes to that data.
>
> Unfortunately I do not know how to access the instance of the first
> plugin that is used by Eclipse. There is no specific accessor method,
> like for views and editors.
> I could only create a completely new instance via the
> ConfigurationElement for that plugin but that would not give me the
> correct instance that stores the required data.
>
> Is there any pattern to do that? Seems like a common problem to me.
>
> My idea is to implement the singleton pattern to get the one and only
> instance of the first plugin's classes by static references. Is this the
> only way to do it?
> I can't be sure how Eclipse handles the objects internally. Maybe it
> creates a new instance of the plugin every time the action is called...
> then this static reference would change every time and a listener of one
> of the instances would not help...
>
> Any ideas?
If you look at how the Activator classes are usually implemented, they
maintain a static reference to the "default" instance, which is set to
"this" in the start() method. They provide a public accessor to get the
reference. This works because each plugin will only be start()ed once.
See org.eclipse.core.resources.ResourcesPlugin.getPlugin() for an example.
Once you have a reference to the plugin class, it can manage references
to other shared data that you need to access from elsewhere.
Hope this helps,
Eric
|
|
|
Powered by
FUDForum. Page generated in 0.02912 seconds