]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed escalator attach/detach logic #12645
authorJohn Ahlroos <john@vaadin.com>
Thu, 12 Dec 2013 12:48:46 +0000 (14:48 +0200)
committerVaadin Code Review <review@vaadin.com>
Thu, 12 Dec 2013 12:54:00 +0000 (12:54 +0000)
Change-Id: If1ba80802010e31362d555023b2b5e5850d2962b

client/src/com/vaadin/client/ui/grid/Escalator.java

index 548d79192a42d1ecbd3395b2dc8bae7c75a8e1d6..20a187e1a53223204ad671717ddc42c2421f87c8 100644 (file)
@@ -35,7 +35,6 @@ import com.google.gwt.dom.client.NodeList;
 import com.google.gwt.dom.client.Style;
 import com.google.gwt.dom.client.Style.Display;
 import com.google.gwt.dom.client.Style.Unit;
-import com.google.gwt.event.logical.shared.AttachEvent;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Window;
@@ -3037,49 +3036,41 @@ public class Escalator extends Widget {
 
         setStylePrimaryName("v-escalator");
 
-        /*
-         * Size calculations work only after the Escalator has been attached to
-         * the DOM. It doesn't matter if the table is populated or not by this
-         * point, there's a lot of other stuff to calculate also. All sizes
-         * start working once the first sizes have been initialized.
-         */
-        addAttachHandler(new AttachEvent.Handler() {
-            @Override
-            public void onAttachOrDetach(final AttachEvent event) {
-                if (event.isAttached()) {
-
-                    /*
-                     * this specific order of method calls matters: header and
-                     * footer get defined heights, the body assumes to get the
-                     * rest.
-                     */
-                    header.paintInsertRows(0, header.getRowCount());
-                    footer.paintInsertRows(0, footer.getRowCount());
-                    recalculateElementSizes();
-                    body.paintInsertRows(0, body.getRowCount());
-
-                    scroller.attachScrollListener(verticalScrollbar
-                            .getElement());
-                    scroller.attachScrollListener(horizontalScrollbar
-                            .getElement());
-                    scroller.attachMousewheelListener(getElement());
-                    scroller.attachTouchListeners(getElement());
-                } else {
-                    scroller.detachScrollListener(verticalScrollbar
-                            .getElement());
-                    scroller.detachScrollListener(horizontalScrollbar
-                            .getElement());
-                    scroller.detachMousewheelListener(getElement());
-                    scroller.detachTouchListeners(getElement());
-                }
-            }
-        });
-
         // init default dimensions
         setHeight(null);
         setWidth(null);
     }
 
+    @Override
+    protected void onLoad() {
+        super.onLoad();
+
+        header.paintInsertRows(0, header.getRowCount());
+        footer.paintInsertRows(0, footer.getRowCount());
+        recalculateElementSizes();
+        body.paintInsertRows(0, body.getRowCount());
+
+        scroller.attachScrollListener(verticalScrollbar.getElement());
+        scroller.attachScrollListener(horizontalScrollbar.getElement());
+        scroller.attachMousewheelListener(getElement());
+        scroller.attachTouchListeners(getElement());
+    }
+
+    @Override
+    protected void onUnload() {
+
+        scroller.detachScrollListener(verticalScrollbar.getElement());
+        scroller.detachScrollListener(horizontalScrollbar.getElement());
+        scroller.detachMousewheelListener(getElement());
+        scroller.detachTouchListeners(getElement());
+
+        header.paintRemoveRows(0, header.getRowCount());
+        footer.paintRemoveRows(0, footer.getRowCount());
+        body.paintRemoveRows(0, body.getRowCount());
+
+        super.onUnload();
+    }
+
     private void detectAndApplyPositionFunction() {
         /*
          * firefox has a bug in its translate operation, showing white space