Differences

This shows you the differences between two versions of the page.

Link to this comparison view

osgi_component_handling_e4_events [2021/04/05 11:23] (current)
Line 1: Line 1:
 +====== OSGi component handling e4 Events ======
 +Eclipse e4 has its own event broker for handling events. Under the hood it uses the OSGi event handling components like EventHandler. 
  
 +===== Receiving e4 events =====
 +Internally Eclipse e4 wraps every object send via the map into a Map (if it is not by itself a Map). The passed object is added to the map with the key IEventBroker.DATA which resolves to the String "data".
 +
 +The OSGi component needs to set the topic which it should listen to in the component definition as the property ''event.topics'' and should implement the ''EventHandler'' interface from the OSGi runtime.
 +
 +<sxh java>
 +@Override
 +public void handleEvent(Event event) {
 +    Object data = event.getProperty(IEventBroker.DATA);
 +    
 +    ...
 +}
 +</sxh>
 +
 +===== Sending e4 events =====
 +To send e4 events you just need to wrap your object into a map with the key "data".
 +
 +<sxh java>
 + private void postEvent(String topic, Object value) {
 + Map<String, Object> map = new HashMap<String, Object>();
 + map.put(IEventBroker.DATA, value);
 +
 + Event event = new Event(topic, map);
 + eventAdmin.postEvent(event);
 + }
 +</sxh>
 +
 +===== Links =====
 +  * [[http://www.vogella.com/articles/Eclipse4EventSystem/article.html | Eclipse Event System Tutorial]]
 +  * [[osgi_component_handling_e4_events|OSGi component handling e4 Events]]
 +
 +{{tag>e4}}