There's a more generic way of passing information between components in Eclipse 4, using the OSGi EventAdmin
service. This is a message bus, like JMS, but operates in memory. There is also an Eclipse-specific EventBroker
, which provides a slightly simpler API to send messages.
Add the following bundles as dependencies to the
com.packtpub.e4.application
project, by double-clicking on the project'sMETA-INF/MANIFEST.MF
file and going to the Dependencies tab:org.eclipse.osgi.services
org.eclipse.e4.core.services
org.eclipse.e4.core.di.extensions
Open the
Rainbow
class and obtain an instance ofEventBroker
through injection.Modify the
selectionChanged()
method, so that instead of setting a selection, it uses theEventBroker
topost()
the color asynchronously to therainbow/colour
topic.public void selectionChanged(SelectionChangedEvent event) { //The following commented line needs to be removed /*selectionService.setSelection(event.getSelection()...