Eclipse RCP的4 - 处理方法参数 [英] Eclipse RCP 4 - Handler method parameters

查看:562
本文介绍了Eclipse RCP的4 - 处理方法参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在看新的Eclipse RCP框架,并有一个关于处理程序的问题。
在RCP 3.X处理程序类需要实现一个接口,这样的方法在这里给出。在RCP 4处理器类并不需要实现一个接口。相反,你注释的方法。例如。如果你有一个 ExitH​​andler 中的 Vogellas教程你有一个 @Execute 注释。正如你可以看到,有一个 IWorkbench 参数传递。

I'm currently taking a look to the new Eclipse RCP framework and have a questions about handlers. In RCP 3.x a handler class needed to implement an interface, so the methods where given. In RCP 4 the handler class doesn't need to implement an interface. Instead you annotate the methods. E.g. if you have an ExitHandler as in Vogellas Tutorial you have an @Execute annotation. As you can see, there's an IWorkbench parameter passed.

package com.example.e4.rcp.todo.handler;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.workbench.IWorkbench;

public class ExitHandler {
  @Execute
  public void execute(IWorkbench workbench) {
    workbench.close();
  }
} 

我现在的问题是:我怎么知道哪些参数使用某些注释时,通过?我怎么知道在这个特定的情况下,我得到一个 IWorkbench 对象,而不是一个Window对象或东西吗?事实上,我可以标注方法不带参数,它仍然会被执行。

My question now is: How do I know which parameters are passed when using certain annotations? How do I know in this certain case that I get an IWorkbench object and not a Window object or something? In fact I can annotate a method without a parameter and it will still be executed.

是否有文件的地方?似乎在Eclipse e4的工具不支持我还有要么...

Is there documentation somewhere? The Eclipse e4 Tools don't seem to support me there either...

推荐答案

注释 @Execute 没有确定类型被注入,该方法声明一样。

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

作为行为注释, @Execute 标记在处理器执行时应该调用的方法。对象的类型的被注入由方法的参数来确定。注入另一个对象类型,改变方法的参数,例如

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
}

注入一个 MWindow 从活动内容。

@Execute 注释包含 @Inject 标注,所以当触发事件和处理程序是怎么回事要执行会发生以下情况:

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. 的框架内寻找由 @Execute 注释
  2. 标记的方法
  3. 在E4上下文搜索的方法的参数类型的对象(如 IWorkbench

  4. 的对象被注入并执行方法

除非 @optional 标注设置,一个例外是,如果没有对象在上下文中抛出。

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

有关进一步阅读和更全面的解释请参见<一个href=\"http://eclipsesource.com/blogs/tutorials/eclipse-4-e4-tutorial-part-4-dependency-injection-basics/\"相对=nofollow>
日食4(E4)教程部分4-依赖注入基础
的Eclipse 4(E4) 6教程部分:行为注释

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.

4的Eclipse注释的概述可以在 Eclipse的4 维基中找到。

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

这篇关于Eclipse RCP的4 - 处理方法参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆