GWT ViewWithUiHandlers with DialogBox Uibinder



我一直在用ViewWithUiHandlers扩展我所有的视图。因此,从视图调用我调用的演示器方法

 getUiHandlers().OnUserSelect();

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

看看PopupViewWithUiHandler

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

 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>

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

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
    }
}

相关内容

  • 没有找到相关文章

最新更新