Pergunta

I am using SmartGWT 3.0 and GWTP 0.7.

I am trying to do a simple PresenterWidget showing a SmartGWT Window. This is the code for the widget presenter:

import com.gwtplatform.mvp.client.PresenterWidget;
import com.gwtplatform.mvp.client.PopupView;
import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;

public class DemoWidgetPresenter extends
    PresenterWidget<DemoWidgetPresenter.MyView> {

public interface MyView extends PopupView {
}

@Inject
public DemoWidgetPresenter(final EventBus eventBus, final MyView view) {
    super(eventBus, view);
}

@Override
protected void onBind() {
    super.onBind();
}

@Override
protected void onReveal() {
    super.onReveal();
    System.out.println(">>>> onReveal()");
}
}

And the view code:

import com.gwtplatform.mvp.client.PopupViewImpl;
import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
import com.google.gwt.user.client.ui.Widget;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.CloseClickEvent;
import com.smartgwt.client.widgets.events.CloseClickHandler;

public class DemoWidgetView extends PopupViewImpl implements
    DemoWidgetPresenter.MyView {

private Window winModal;

@Inject
public DemoWidgetView(final EventBus eventBus) {
    super(eventBus);

    winModal = new Window();
    winModal.setWidth(300);
    winModal.setHeight(500);
    winModal.setTitle("Export file");
    winModal.setShowMinimizeButton(false);
    winModal.setIsModal(true);
    winModal.setShowModalMask(true);
    winModal.centerInPage();
    winModal.setCanDragResize(true);
    winModal.addCloseClickHandler(new CloseClickHandler() {
        @Override
        public void onCloseClick(CloseClickEvent event) {
            winModal.hide();
        }
    });
}

@Override
public void center() {
    winModal.centerInPage();
}

@Override
public void hide() {
    winModal.hide();
}

@Override
public void setPosition(int left, int top) {
    winModal.setLeft(left);
    winModal.setTop(top);
}

@Override
public void show() {
    winModal.show();
}

public Widget asWidget() {
    return winModal;
}
}

In another part of the program I show this presenter with: addToPopupSlot(dp, true);

Where dp is an injected instance of DemoWidgetPresenter.

When DemoWidgetPresenter is show the folowing Exception is raised:

com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full                                    set in UmbrellaException#getCauses
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at     com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: com.smartgwt.client.widgets.Window cannot be cast to com.google.gwt.user.client.ui.PopupPanel
at com.gwtplatform.mvp.client.PopupViewImpl.asPopupPanel(PopupViewImpl.java:130)
at com.gwtplatform.mvp.client.PopupViewImpl.setCloseHandler(PopupViewImpl.java:104)
at com.gwtplatform.mvp.client.PresenterWidget.monitorCloseEvent(PresenterWidget.java:574)
at com.gwtplatform.mvp.client.PresenterWidget.addToPopupSlot(PresenterWidget.java:205)
at com.demo.client.core.mvp.DiffPresenter$9.onClick(DiffPresenter.java:397)
at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:96)
at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:1)
at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)

I see the problem is due to a casting between com.smartgwt.client.widgets.Window and com.google.gwt.user.client.ui.PopupPanel but I don't know how to solve it!

Despite the Exception, the window is shown, but function onReveal() is never call, so the presenter live cycle is broken..

Any idea/workaround :-)?

Thank you in advance!

Foi útil?

Solução 2

I found a solution doing an adapter class:

import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.PopupPanel;
import com.gwtplatform.mvp.client.PopupView;
import com.gwtplatform.mvp.client.PopupViewImpl;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.CloseClickEvent;
import com.smartgwt.client.widgets.events.CloseClickHandler;

/**
 * Adapter class for {@link Window}. This class it is necessary when a
 * {@link PopupView} uses as widget a {@link Window}. GWTP library does an
 * explicit cast to {@link PopupPanel} in {@link PopupViewImpl} and a cast
 * exception is raised. This class adapts only these functions which are call in
 * {@link PopupViewImpl}.
 * 
 * 
 */
public class PopupPanelAdapter extends PopupPanel {

private Window delegate;

public PopupPanelAdapter(Window delegate) {
    this.delegate = delegate;
    // adapting window close event
    delegate.addCloseClickHandler(new CloseClickHandler() {
        @Override
        public void onCloseClick(CloseClickEvent event) {
            CloseEvent.fire(PopupPanelAdapter.this, null);
        }
    });
}

public void hide() {
    delegate.hide();
}

public void show() {
    delegate.show();
}

@Override
public HandlerRegistration addCloseHandler(CloseHandler<PopupPanel> handler) {
    return super.addCloseHandler(handler);
}

@Override
public boolean isShowing() {
    return isVisible();
}

@Override
public void center() {
    delegate.centerInPage();
}

@Override
public void setPopupPosition(int left, int top) {
    if (delegate == null)// call in constructor, delegate is null
        return;
    delegate.setLeft(left);
    delegate.setTop(top);
}
}

It works fine!

Outras dicas

In my case we are using UIBinder XML to define layout and I had an issue with GWTBootstrap3's Modal compenent.

I have rolled out a custom ModalPopupAdapter using the mentioned solution, but needed the following additions to the different parts:

Java Code in View

@UiField(provided = true)
Modal modal = new Modal();

@UiField(provided = true)
ModalPopupAdapter modalPopupAdapter = new ModalPopupAdapter(modal);

UIBinder XML

<afr:ModalPopupAdapter ui:field="modalPopupAdapter">
    <bs:Modal ui:field="modal" other-attributes...>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top