]> source.dussan.org Git - vaadin-framework.git/commitdiff
Keep children in the right order (#8313)
authorLeif Åstrand <leif@vaadin.com>
Tue, 21 Feb 2012 07:10:08 +0000 (09:10 +0200)
committerLeif Åstrand <leif@vaadin.com>
Tue, 21 Feb 2012 07:10:08 +0000 (09:10 +0200)
src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayout.java
src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayoutPaintable.java

index dd3cb41a13f4ba787f732aa5d1422efabcf9305d..ca8b1ebc8d1c627d07c3389392c8cf3ac42b0e1d 100644 (file)
@@ -5,6 +5,7 @@ package com.vaadin.terminal.gwt.client.ui;
 
 import com.google.gwt.dom.client.DivElement;
 import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.Node;
 import com.google.gwt.dom.client.Style;
 import com.google.gwt.dom.client.Style.Position;
 import com.google.gwt.user.client.Element;
@@ -32,12 +33,22 @@ public class VMeasuringOrderedLayout extends ComplexPanel {
         this.isVertical = isVertical;
     }
 
-    public void addSlot(VLayoutSlot layoutSlot) {
+    public void addOrMove(VLayoutSlot layoutSlot, int index) {
         Widget widget = layoutSlot.getWidget();
         Element wrapperElement = layoutSlot.getWrapperElement();
 
-        getElement().appendChild(wrapperElement);
-        add(widget, wrapperElement);
+        Element containerElement = getElement();
+        Node childAtIndex = containerElement.getChild(index);
+        boolean alreadyAttached;
+        if (childAtIndex != wrapperElement) {
+            alreadyAttached = wrapperElement.getParentElement() == containerElement;
+            containerElement.insertBefore(wrapperElement, childAtIndex);
+        } else {
+            alreadyAttached = true;
+        }
+        if (!alreadyAttached) {
+            insert(widget, wrapperElement, index, false);
+        }
 
         widget.setLayoutData(layoutSlot);
     }
index e142f31ffe57ddfa6dc53e312fd0fbbcd28bc3c6..867e0eef121382de3c0693c2e0e40a432c3c5bc0 100644 (file)
@@ -63,6 +63,7 @@ public abstract class VMeasuringOrderedLayoutPaintable extends
         ValueMap expandRatios = uidl.getMapAttribute("expandRatios");
         ValueMap alignments = uidl.getMapAttribute("alignments");
 
+        int currentIndex = 0;
         // TODO Support reordering elements!
         for (final Iterator<Object> it = uidl.getChildIterator(); it.hasNext();) {
             final UIDL childUIDL = (UIDL) it.next();
@@ -74,8 +75,8 @@ public abstract class VMeasuringOrderedLayoutPaintable extends
             if (widget.getParent() != layout) {
                 slot = new VPaintableLayoutSlot(getWidgetForPaintable()
                         .getStylePrimaryName(), child);
-                layout.addSlot(slot);
             }
+            layout.addOrMove(slot, currentIndex++);
 
             String pid = child.getId();