Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Share data between plugins?
Share data between plugins? [message #328721] Mon, 02 June 2008 19:08 Go to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 333
Registered: July 2009
Senior Member
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?

Hauke
Re: Share data between plugins? [message #328723 is a reply to message #328721] Mon, 02 June 2008 19:27 Go to previous messageGo to next message
Eclipse UserFriend
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 #328730 is a reply to message #328723] Tue, 03 June 2008 06:48 Go to previous messageGo to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 333
Registered: July 2009
Senior Member
Konstantin Komissarchik wrote:
> 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.

Yes, I can access all classes in a static way or create new instances.
But how do I get access to the objects of the classes of the first
plugin that Eclipse uses? So do I have to create a static reference to
each of them?

Hauke
Re: Share data between plugins? [message #328741 is a reply to message #328721] Tue, 03 June 2008 13:55 Go to previous message
Eclipse UserFriend
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
Previous Topic:.syncinfo is deleted RDZ
Next Topic:.syncinfo deleted RDZ
Goto Forum:
  


Current Time: Sat Nov 09 05:19:38 GMT 2024

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

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

Back to the top