如何在GWTP中为非Presenter类使用EventBus? [英] How to use EventBus for non-Presenter class in GWTP?

查看:218
本文介绍了如何在GWTP中为非Presenter类使用EventBus?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GWTP平台& eClipse构建webapp。在Eclipse中,创建Presenter时,它将创建3个文件(例如:SearchPresenter.java,SearchView.java和SearchView.ui.xml):

  public class SearchView extends ViewImpl implements SearchPresenter.MyView 

public class SearchPresenter extends
Presenter< SearchPresenter.MyView,SearchPresenter.MyProxy> {
... 。
private EventBus eventBus;
@Inject
public SearchPresenter(final EventBus eventBus,final MyView view){
super(eventBus,view);
this.eventBus = eventBus;




$ b $ p
$ b

要使用eventBus,我们只需简单地使用eclipse来创建EventBus文件,例如MyEvent.java,然后我们使用下面的代码在SearchPresenter中调用eventBus:
$ b

  MyEvent mEvent = new MyEvent() ; 
SearchPresenter.this.eventBus.fireEvent(mEvent);

现在假设我有一个非演示者类 public class SearchDialogBox extends DialogBox ,那么我的问题是我如何在SearchDialogBox中使用MyEvent?如何在SearchDialogBox中使用getEventBus()?

解决方案

我不使用GWTP,但我猜以下是确定的。 >

  @Inject private EventBus eventBus 

应该可以工作(如果你没有在SearchDialogBox构造函数中使用它)。



否则,请尝试找出GWTP中的哪个类扩展了com.google .gwt.inject.client.Ginjector。假设它被称为MyInjector,只需写:

  private EventBus eventBus = MyInjector.INSTANCE.getEventBus(); 


I am using GWTP platform & eClipse to build webapp. In Eclipse, when creating a Presenter, it will create 3 files (ex: SearchPresenter.java, SearchView.java, & SearchView.ui.xml):

public class SearchView extends ViewImpl implements SearchPresenter.MyView

public class SearchPresenter extends
    Presenter<SearchPresenter.MyView, SearchPresenter.MyProxy>{
    ....
    private EventBus eventBus;
    @Inject
    public SearchPresenter(final EventBus eventBus, final MyView view) {
         super(eventBus, view);
        this.eventBus=eventBus;
    }
}

To use eventBus, we just simply use eclipse to create EventBus file, ex MyEvent.java, then we call eventBus in SearchPresenter by using this code:

MyEvent mEvent=new MyEvent();
SearchPresenter.this.eventBus.fireEvent(mEvent);

now suppose I got a non-presenter class public class SearchDialogBox extends DialogBox, then my question is how can i use MyEvent in SearchDialogBox? How to getEventBus() in SearchDialogBox?

解决方案

I' dont use GWTP, but I guess the following is ok.

@Inject private EventBus eventBus

should work (if you don't use it in SearchDialogBox constructor right away).

Otherwise try to find out which class in GWTP extends com.google.gwt.inject.client.Ginjector. Assuming it is called "MyInjector" just write :

private EventBus eventBus = MyInjector.INSTANCE.getEventBus();

这篇关于如何在GWTP中为非Presenter类使用EventBus?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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