Time for action: passing command parameters
Displaying a message to System.out
shows that the command works, but what if the command needed to pick up 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:public ...
Get Eclipse Plug-in Development Beginner's Guide - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.