|
Re: RCP EventBus? [message #1005974 is a reply to message #1005970] |
Tue, 29 January 2013 13:03 |
John Steele Messages: 50 Registered: January 2010 |
Member |
|
|
Lars did an article on the e4 way: http://www.vogella.com/articles/Eclipse4EventSystem/article.html
If you're tying to do it the 3.x way you do something similar to the following:
private void doPostEvent (String topic, Dictionary<String, Object> props) {
Event event = new Event (topic, props);
BundleContext ctx = FrameworkUtil.getBundle(SomeClass.class).getBundleContext();
ServiceReference ref = ctx.getServiceReference(EventAdmin.class.getName());
if( ref != null){
EventAdmin admin = (EventAdmin) ctx.getService(ref);
admin.sendEvent(event);
ctx.ungetService(ref);
}
}
To register an event handler do something similar to the following:
public void registerEventHandler(String topic, IMyEventHandler handler) {
BundleContext ctx = FrameworkUtil.getBundle(SomeClass.class).getBundleContext();
Dictionary<String, String> props = new Hashtable<String, String>();
props.put(EventConstants.EVENT_TOPIC, topic);
ServiceRegistration reg = ctx.registerService(EventHandler.class.getName(), handler, props);
}
I don't see an incentive on bringing the old way into e4. It's way too verbose. If you're trying to bring the e4 annotation driven method into a 3.x RCP application I don't think it's possible, but I could be wrong on that. Either way, they both accomplish the same thing, internal communication.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03053 seconds