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 IEventBroker
, 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 inject an instance ofIEventBroker
into aprivate
fieldbroker
:@Inject private IEventBroker broker;
Modify the
selectionChanged
method, so that instead of setting a selection, it uses theIEventBroker
topost
the color asynchronously to therainbow/color
topic:public void selectionChanged(SelectionChangedEvent event) { // selectionService.setSelection(event.getSelection()); IStructuredSelection...