0

I have been extending all my Views with ViewWithUiHandlers. So, from the View to invoke a presenter method I call

 getUiHandlers().OnUserSelect();

How do i get the getUiHandlers() when one of view has to extend DialogBox, as a class can't have multiple extends.

4

2 回答 2

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. 注意<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)parent来显示弹出窗口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
    }
}
于 2013-04-18T13:15:40.160 回答
0

看着PopupViewWithUiHandler

于 2013-01-22T22:58:11.293 回答