Differences
This shows you the differences between two versions of the page.
osgi_component_handling_e4_events [2013/12/05 22:04] |
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 " | ||
+ | |||
+ | The OSGi component needs to set the topic which it should listen to in the component definition as the property '' | ||
+ | |||
+ | <sxh java> | ||
+ | @Override | ||
+ | public void handleEvent(Event event) { | ||
+ | Object data = event.getProperty(IEventBroker.DATA); | ||
+ | | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Sending e4 events ===== | ||
+ | To send e4 events you just need to wrap your object into a map with the key " | ||
+ | |||
+ | <sxh java> | ||
+ | private void postEvent(String topic, Object value) { | ||
+ | Map< | ||
+ | map.put(IEventBroker.DATA, | ||
+ | |||
+ | Event event = new Event(topic, | ||
+ | eventAdmin.postEvent(event); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Links ===== | ||
+ | * [[http:// | ||
+ | * [[osgi_component_handling_e4_events|OSGi component handling e4 Events]] | ||
+ | |||
+ | {{tag> |