From ec8f056ee82a889edd0d88b6905a9ed9a2107f32 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Mon, 2 Apr 2012 14:46:07 +0300 Subject: [PATCH] Use StateChangeHandler to detect child sizing change --- .../terminal/gwt/client/ui/RootConnector.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/RootConnector.java b/src/com/vaadin/terminal/gwt/client/ui/RootConnector.java index 245c92f352..988c1558cc 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/RootConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/RootConnector.java @@ -11,6 +11,7 @@ import com.google.gwt.core.client.Scheduler; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.Position; +import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; @@ -29,9 +30,10 @@ import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VConsole; import com.vaadin.terminal.gwt.client.communication.ServerRpc; +import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; +import com.vaadin.terminal.gwt.client.communication.StateChangeEvent.StateChangeHandler; -public class RootConnector extends AbstractComponentContainerConnector - implements SimpleManagedLayout { +public class RootConnector extends AbstractComponentContainerConnector { public interface RootServerRPC extends ClickRPC, ServerRpc { @@ -39,6 +41,16 @@ public class RootConnector extends AbstractComponentContainerConnector private RootServerRPC rpc = GWT.create(RootServerRPC.class); + private HandlerRegistration childStateChangeHandlerRegistration; + + private final StateChangeHandler childStateChangeHandler = new StateChangeHandler() { + public void onStateChanged(StateChangeEvent stateChangeEvent) { + // TODO Should use a more specific handler that only reacts to + // size changes + onChildSizeChange(); + } + }; + @Override protected void init() { super.init(); @@ -149,11 +161,19 @@ public class RootConnector extends AbstractComponentContainerConnector if (getWidget().layout != lo) { // remove old client.unregisterPaintable(getWidget().layout); + if (childStateChangeHandlerRegistration != null) { + childStateChangeHandlerRegistration.removeHandler(); + childStateChangeHandlerRegistration = null; + } // add new getWidget().setWidget(lo.getWidget()); getWidget().layout = lo; } } else { + if (getWidget().layout != lo) { + childStateChangeHandlerRegistration = lo + .addStateChangeHandler(childStateChangeHandler); + } getWidget().setWidget(lo.getWidget()); getWidget().layout = lo; } @@ -331,7 +351,7 @@ public class RootConnector extends AbstractComponentContainerConnector return GWT.create(VView.class); } - public void layout() { + protected void onChildSizeChange() { ComponentConnector child = getWidget().layout; Style childStyle = child.getWidget().getElement().getStyle(); /* -- 2.39.5