]> source.dussan.org Git - vaadin-framework.git/commitdiff
Don't remove widgets that are not there (#8313)
authorLeif Åstrand <leif@vaadin.com>
Tue, 21 Feb 2012 07:41:51 +0000 (09:41 +0200)
committerLeif Åstrand <leif@vaadin.com>
Tue, 21 Feb 2012 07:41:51 +0000 (09:41 +0200)
src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayoutPaintable.java

index 867e0eef121382de3c0693c2e0e40a432c3c5bc0..b991b37c444ccf91255489c8e88833178853ad21 100644 (file)
@@ -3,6 +3,7 @@ package com.vaadin.terminal.gwt.client.ui;
 import java.util.HashSet;
 import java.util.Iterator;
 
+import com.google.gwt.dom.client.Node;
 import com.google.gwt.dom.client.Style;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
@@ -105,10 +106,35 @@ public abstract class VMeasuringOrderedLayoutPaintable extends
 
         for (VPaintableWidget child : previousChildren) {
             Widget widget = child.getWidgetForPaintable();
-            layout.removeSlot(layout.getSlotForChild(widget));
 
-            VPaintableMap vPaintableMap = VPaintableMap.get(client);
-            vPaintableMap.unregisterPaintable(child);
+            // Don't remove and unregister if it has been moved to a different
+            // parent. Slot element will be left behind, but that is taken care
+            // of later
+            if (widget.getParent() == getWidgetForPaintable()) {
+                layout.removeSlot(layout.getSlotForChild(widget));
+
+                VPaintableMap vPaintableMap = VPaintableMap.get(client);
+                vPaintableMap.unregisterPaintable(child);
+            }
+        }
+
+        // Remove empty layout slots left behind after children have moved to
+        // other paintables
+        while (true) {
+            int childCount = layout.getElement().getChildCount();
+            if (childCount <= 1) {
+                // Stop if no more slots (spacing element is always present)
+                break;
+            }
+
+            Node lastSlot = layout.getElement().getChild(childCount - 2);
+            if (lastSlot.getChildCount() == 0) {
+                // Remove if empty
+                lastSlot.removeFromParent();
+            } else {
+                // Stop searching when last slot is not empty
+                break;
+            }
         }
 
         int bitMask = uidl.getIntAttribute("margins");