使用DialogBox Uibinder的GWT ViewWithUiHandlers

时间:2013-01-22 20:15:36

标签: gwt uibinder gwt-platform

我一直用ViewWithUiHandlers扩展我的所有视图。因此,从View调用presenter方法我调用

 getUiHandlers().OnUserSelect();

当一个视图必须扩展DialogBox时,如何获取getUiHandlers(),因为一个类不能有多个扩展。

2 个答案:

答案 0 :(得分:0)

查看PopupViewWithUiHandler

答案 1 :(得分:0)

这是一个基本弹出窗口的示例。首先,您必须创建与PresenterWidget相关联的PopupViewWithUiHandler

 public class MyPopupPresenter extends PresenterWidget<MyPopupPresenter.MyView>
        implements MyPopupUiHandlers {
    public interface MyView extends PopupView, HasUiHandlers<MyPopupUiHandlers> {
    }

    @Inject
    public MyPopupPresenter(EventBus eventBus,
                            MyView view) {
        super(eventBus, view);

        getView().setUiHandlers(this);
    }
}

这是您的PopupViewWithUiHandlers

public class MyPopupView extends PopupViewWithUiHandlers<MyPopupUiHandlers>
        implements MyPopupPresenter.MyView, {
    public interface Binder extends UiBinder<PopupPanel, MyPopupView> {
    }

    @Inject
    public MyPopupView(Binder binder,
                       EventBus eventBus) {
        super(eventBus);

        initWidget(binder.createAndBindUi(this));
    }
}

这是与你PopupViewWithUiHandlers相关联的UiBinder。请注意<g:PopupPanel>

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
             xmlns:g='urn:import:com.google.gwt.user.client.ui'>
    <g:PopupPanel>
        <g:HTMLPanel>
            ...
        </g:HTMLPanel>
    </g:PopupPanel>
</ui:UiBinder>

并且,您可以通过调用父addToPopupSlot(myPopupPresenter)中的Presenter来显示该弹出窗口:

public class MyPresenter extends Presenter<MyPresenter.MyView, MyPresenter.MyProxy>       implements MyUiHandlers {
    public interface MyView extends View, HasUiHandlers<MyUiHandlers> {
    }

    @ProxyStandard
    @NameToken(NameTokens.myNameToken)
    public interface MyProxy extends ProxyPlace<MyPresenter> {
    } 

    private final MyPopupPresenter myPopupPresenter;

    @Inject
    public MyPresenter(EventBus eventBus,
                       MyView view,
                       MyProxy proxy,
                       MyPopupPresenter myPopupPresenter) {
        super(eventBus, view, proxy, ApplicationPresenter.MainContentSlot);

        this.myPopupPresenter = myPopupPresenter;

        getView().setUiHandlers(this);
    }

    private void showPopup() {
        addToPopupSlot(myPopupPresenter); // this will show your popup
    }
}