From 0887719871f8dd4d0ca7004ff2305814ca3cbd6f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Tue, 21 Feb 2012 09:10:08 +0200 Subject: [PATCH] Keep children in the right order (#8313) --- .../gwt/client/ui/VMeasuringOrderedLayout.java | 17 ++++++++++++++--- .../ui/VMeasuringOrderedLayoutPaintable.java | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayout.java index dd3cb41a13..ca8b1ebc8d 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayout.java @@ -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); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayoutPaintable.java index e142f31ffe..867e0eef12 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayoutPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayoutPaintable.java @@ -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 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(); -- 2.39.5