POJOs can be instantiated and made available in the E4 context, such that they can be injected into other classes or created on demand. This allows an application to be built in a flexible manner without tight coupling between services.
Create a class in the
com.packtpub.e4.application
package calledStringService
with a@Creatable
annotation, and aprocess()
method that takes aString
and returns an upper-case version:import org.eclipse.e4.core.di.annotations.Creatable; @Creatable public class SimpleService { public String process(String string) { return string.toUpperCase(); } }
Add an injectable instance of
StringService
to theRainbow
class:@Inject private StringService stringService;
Use the injected service to process the string color choice before posting the event to the event broker:
public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection sel = (IStructuredSelection) event.getSelection(); Object colour...