Displaying a message to System.out
shows that the command works, but what if the command needed to pick up a local state? Fortunately, the @Named
and @Inject
annotations allow objects to be injected into the method when it is called.
Modify the
hello()
method so that instead of printing a message toSystem.out
, it opens a dialog window, using the active shell:public void hello(@Named(IServiceConstants.ACTIVE_SHELL) Shell s){ MessageDialog.openInformation(s, "Hello World", "Welcome to Eclipse 4 technology"); }
Other arguments can be passed in from the context, managed by the
IEclipseContext
interface. For example, using themath.random
function from earlier, a value could be injected into the handler like this:public void hello(@Named(IServiceConstants.ACTIVE_SHELL) Shell s, @Named("math.random") double value) {
If the same handler is being used for different functions (for example, Paste and Paste Special) they can be disambiguated by passing...