]> source.dussan.org Git - vaadin-framework.git/commitdiff
Only run sizeInit after the actual layout (#8313)
authorLeif Åstrand <leif@vaadin.com>
Mon, 12 Mar 2012 12:29:55 +0000 (14:29 +0200)
committerLeif Åstrand <leif@vaadin.com>
Mon, 12 Mar 2012 12:29:55 +0000 (14:29 +0200)
src/com/vaadin/terminal/gwt/client/ui/TableConnector.java
src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java

index 1a5b535da3a503fdced71f35d36984e8b0baa207..b2a183ac5a60b57deb9c2383a5e85211f4511a1d 100644 (file)
@@ -16,7 +16,7 @@ import com.vaadin.terminal.gwt.client.UIDL;
 import com.vaadin.terminal.gwt.client.Util;
 
 public class TableConnector extends AbstractComponentContainerConnector
-        implements DirectionalManagedLayout {
+        implements DirectionalManagedLayout, PostLayoutListener {
 
     /*
      * (non-Javadoc)
@@ -256,6 +256,10 @@ public class TableConnector extends AbstractComponentContainerConnector
     }
 
     public void layoutHorizontally() {
-        getWidget().updateWidth();
+        // getWidget().updateWidth();
+    }
+
+    public void postLayout() {
+        getWidget().sizeInit();
     }
 }
index a4764f25505f20563a317cb82bdd5dfedc875010..e2d52f76fdc9866e07b09eb9353a2dfeb2770a66 100644 (file)
@@ -456,6 +456,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
     int serverCacheFirst = -1;
     int serverCacheLast = -1;
 
+    private boolean sizeNeedsInit = true;
+
     public VScrollTable() {
         setMultiSelectMode(MULTISELECT_MODE_DEFAULT);
 
@@ -838,9 +840,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
         tFoot.setHorizontalScrollPosition(0);
 
         initialContentReceived = true;
-        if (isAttached()) {
-            sizeInit();
-        }
+        sizeNeedsInit = true;
         scrollBody.restoreRowVisibility();
     }
 
@@ -965,7 +965,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
 
         if (oldPageLength != pageLength && initializedAndAttached) {
             // page length changed, need to update size
-            sizeInit();
+            sizeNeedsInit = true;
         }
     }
 
@@ -1580,14 +1580,6 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
         }
     }
 
-    @Override
-    protected void onAttach() {
-        super.onAttach();
-        if (initialContentReceived) {
-            sizeInit();
-        }
-    }
-
     @Override
     protected void onDetach() {
         rowRequestHandler.cancel();
@@ -1611,7 +1603,11 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
      * 
      * * Makes deferred request to get some cache rows
      */
-    private void sizeInit() {
+    void sizeInit() {
+        if (!sizeNeedsInit) {
+            return;
+        }
+        sizeNeedsInit = false;
         /*
          * We will use browsers table rendering algorithm to find proper column
          * widths. If content and header take less space than available, we will
@@ -5521,6 +5517,15 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
 
     }
 
+    @Override
+    public void setWidth(String width) {
+        String oldWidth = getElement().getStyle().getWidth();
+        if (!oldWidth.equals(width)) {
+            super.setWidth(width);
+            updateWidth();
+        }
+    }
+
     void updateWidth() {
         if (!isVisible()) {
             /*
@@ -5543,8 +5548,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
 
         } else {
 
-            // Readjust size of table
-            sizeInit();
+            sizeNeedsInit = true;
 
             // readjust undefined width columns
             triggerLazyColumnAdjustment(false);