Eclipse RCP 4 - Handler method parameters

无人久伴 提交于 2019-12-05 22:43:40

The annotation @Execute doesn't determine the type to be injected, the method declaration does.

As a behavior annotation, @Execute marks the method that should be called when the handler is executed. The type of the object to be injected is determined by the method's arguments. To inject another object type, change the method's argument, e.g.

@Execute
public void execute(MWindow window) {
    // method body
}

to inject an MWindow from the active context.

The @Execute annotation contains the @Inject annotation, so when an event is triggered and the handler is going to be executed the following happens:

  1. the framework looks for the method marked by the @Execute annotation
  2. the E4 context is searched for an object of the method's argument type (e.g. IWorkbench)
  3. the object gets injected and the method is executed

Unless the @Optional annotation is set, an exception is thrown if no object is found in the context.

For further reading and more thorough explanations see Eclipse 4 (e4) Tutorial Part 4- Dependency Injection Basics and Eclipse 4 (e4) Tutorial Part 6: Behavior Annotations.

An overview of Eclipse 4 annotations can be found at the Eclipse 4 Wiki.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!