这是一个基本弹出窗口的示例。首先,您必须创建一个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
}
}