Global Event Service [message #455727] |
Wed, 04 October 2006 14:32  |
Eclipse User |
|
|
|
Hi,
I'm looking for a service like the SelectionService, but with the
possibility to send different events. For example I want to register a
View as listener for a user-defined event (e.g. file loaded/saved) and
register other parts as provider like the SelectionListener/Provider. Is
there such a service or have I to implement it myself?
Thanks in advance,
Ingo
|
|
|
|
|
|
|
|
|
|
Re: Global Event Service [message #455885 is a reply to message #455806] |
Mon, 09 October 2006 08:07   |
Eclipse User |
|
|
|
Hi Paul,
I hope you don't think I'm stupid, but I don't understand how to make the
event service plugin a required bundle for my plugin where I can access
the EventAdmin class. I just can add the org.eclipse.equinox.event plugin
to my required plugins, but not org.osgi.service.event or anything else
from org.osgi.*. Then I can't access the class EventAdmin if I don't use
Import-Package in my manifest. I read the Event Admin Service
specification in the OSGi Service Platform Service Compendium Release 4,
and they say in chapter 113.12:
Event Admin Package Version 1.1.
Bundles wishing to use this package must list the package in the Import-
Package header of the bundles manifest. For example:
Import-Package: org.osgi.service.event; version=1.1
Now I'm a little bit confused about what you say and what the
specification says. But I'm new in RCP development, and perhaps I didn't
really understand what you mean.
Next problem I have is how to start the service. I read I can do this in
the config.ini with the following instruction:
osgi.bundles=org.eclipse.equinox.event@start
But if I do so I get a BundleException (Bundle "org.eclipse.equinox.event"
version "1.0.0.v20060601a" has already been installed from:
update@plugins/org.eclipse.equinox.event_1.0.0.v20060601a.jar) and the
service will not start. So I considered to do this programmatically in my
plugin's start-method, but I'm not sure what is the best way to do this.
If I use the Activator class from the event service plugin Eclipse says
discouraged access. But how could I start this service, what is the normal
procedure?
And after slowly understanding how to use this service I'm meanwhile not
sure if this service is really right for me. I think this service is
designed for sending/handling events between Bundles, not inside a bundle.
I hit on it because I need to register an EventHandler service for each
handler. But to do so I need the BundleContext and the only class I have a
reference to it is my Activator class. I solve this by adding a method
registerService(EventHandler, Dictionary) to my Activator class and cache
the BundleContext from the start method. Is this approach bad practice or
would you say you can let this?
Ingo
|
|
|
Re: Global Event Service [message #455914 is a reply to message #455885] |
Mon, 09 October 2006 20:41   |
Eclipse User |
|
|
|
Ingo Kroh wrote:
> Hi Paul,
>
> I hope you don't think I'm stupid, but I don't understand how to make
> the event service plugin a required bundle for my plugin where I can
> access the EventAdmin class. I just can add the
> org.eclipse.equinox.event plugin to my required plugins, but not
> org.osgi.service.event or anything else from org.osgi.*. Then I can't
> access the class EventAdmin if I don't use Import-Package in my
> manifest. I read the Event Admin Service specification in the OSGi
> Service Platform Service Compendium Release 4, and they say in chapter
> 113.12:
>
> Event Admin Package Version 1.1.
> Bundles wishing to use this package must list the package in the Import-
> Package header of the bundle�s manifest. For example:
> Import-Package: org.osgi.service.event; version=1.1
If that's what they say, I'd go with it. I'm not sure how the import
package would allow something to work when a require-bundle does, but I
haven't actually tried it with the event bundle (so my information is
general, not specific).
> Next problem I have is how to start the service. I read I can do this in
> the config.ini with the following instruction:
>
> osgi.bundles=org.eclipse.equinox.event@start
I'm not sure why the event service won't start for your ... it should be
done either 1) adding it to the osgi.bundles or 2) possibly calling into
a class.
You can start another bundle deliberately by using
org.eclipse.core.runtime.Platform#getBundle(String) to get the Bundle,
checking the state, and calling Bundle#start().
> And after slowly understanding how to use this service I'm meanwhile not
> sure if this service is really right for me. I think this service is
> designed for sending/handling events between Bundles, not inside a
> bundle. I hit on it because I need to register an EventHandler service
> for each handler. But to do so I need the BundleContext and the only
> class I have a reference to it is my Activator class. I solve this by
> adding a method registerService(EventHandler, Dictionary) to my
> Activator class and cache the BundleContext from the start method. Is
> this approach bad practice or would you say you can let this?
This is a common approach for plugins that need the BundleContext, they
cache it in their Activator.
Maybe this event service is too heavy weight for what you want to do.
Another option is to provide your "event service" as a singleton through
a static method on your Activator.
org.eclipse.core.commands.common.EventManager (in
org.eclipse.core.commands) provides an abstract base class that can be
specialized with your listeners.
Later,
PW
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04839 seconds