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
StringService
in thecom.packtpub.e4.application
package with a@Creatable
annotation, and aprocess
method that takes a string and returns an uppercase version:import org.eclipse.e4.core.di.annotations.Creatable; @Creatable public class StringService { public String process(String string) { return string.toUpperCase(); } }
Add an injectable instance of
StringService
to theRainbow
class:@Inject private StringService stringService;
Use the injected
stringService
toprocess
the color choice before posting the event to the event broker:public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection sel = (IStructuredSelection) event.getSelection(); Object colour = sel.getFirstElement...