@Inject IContributionFactory contributionFactory .. Object handler = contributionFactory.create("bundleclass://de.plugin.name/de.plugin.path.to.Handler", eclipseContext);
IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor( MODULE_ID); for (IConfigurationElement configElement : configElements) { //search the Element here... }
Is there a way to create the handler by id only?
Can I somehow resolve the id to bundleURI?
contributing a Handler for a Command and executing it by ID is clearer.
... @Inject IEclipseContext context; MyHandler myHandler = new MyHandler(); ContextInjectionFactory.inject(myHandler, context); myHandler.execute(); //if execute is the method you annotated with @Execute ...
Bundle bundle = FrameworkUtil.getBundle(MyHandler.class);
... @Inject ECommandService commandService; @Inject EHandlerService handlerService; ... Map params = new HashMap(); ParameterizedCommand cmd = commandService.createCommand("my.command.id", params); //$NON-NLS-1$ handlerService.executeHandler(cmd); ...
If you need some injection, you could try to inject via ContextInjectionFactory.
... @Inject IEclipseContext context; MyHandler myHandler = new MyHandler(); ContextInjectionFactory.inject(myHandler, context); myHandler.execute(); //if execute is the method you annotated with @Execute ...
ContextInjectionFactory.invoke(myHandler, Execute.class, context);
You can also use
to execute the handler including injections in the annotated method.ContextInjectionFactory.invoke(myHandler, Execute.class, context);
No never use DI-Fields inside handlers! Never use @Inject inside
handlers this is doomed to fail miserably because the handler is created
in a completely different context then it is executed!
You should use CIF.invoke()
Tom