]> source.dussan.org Git - vaadin-framework.git/commitdiff
Use StateChangeHandler to detect child sizing change
authorLeif Åstrand <leif@vaadin.com>
Mon, 2 Apr 2012 11:46:07 +0000 (14:46 +0300)
committerLeif Åstrand <leif@vaadin.com>
Mon, 2 Apr 2012 11:46:07 +0000 (14:46 +0300)
src/com/vaadin/terminal/gwt/client/ui/RootConnector.java

index 245c92f35212452735f7eab0417eb0a8311a9249..988c1558cce79785cdd80f5684f2c211cf9b1fd0 100644 (file)
@@ -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();
         /*