From: Artur Signell Date: Fri, 23 Mar 2012 09:23:37 +0000 (+0200) Subject: Store widget -> LayoutSlot mapping in a map instead of LayoutData X-Git-Tag: 7.0.0.alpha2~225 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0436745f876fd34aedb6847ae622db3a5d143cf2;p=vaadin-framework.git Store widget -> LayoutSlot mapping in a map instead of LayoutData This enables retrieval of the slot also after the widget has been removed from the layout --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java index dc0812c6f1..ce2d9c28ad 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java @@ -246,13 +246,11 @@ public abstract class AbstractOrderedLayoutConnector extends layout.addOrMove(slot, currentIndex++); } - // TODO: Move this to layout and base it on DOM and "currentIndex" for (ComponentConnector child : previousChildren) { - Widget widget = child.getWidget(); if (child.getParent() != this) { // Remove slot if the connector is no longer a child of this // layout - layout.removeSlot(layout.getSlotForChild(widget)); + layout.removeSlotForWidget(child.getWidget()); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayout.java index 0bd2a90c88..b7d28c56b9 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayout.java @@ -3,6 +3,9 @@ */ package com.vaadin.terminal.gwt.client.ui; +import java.util.HashMap; +import java.util.Map; + import com.google.gwt.dom.client.DivElement; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Node; @@ -20,6 +23,8 @@ public class VMeasuringOrderedLayout extends ComplexPanel { final DivElement spacingMeasureElement; + private Map widgetToSlot = new HashMap(); + protected VMeasuringOrderedLayout(String className, boolean isVertical) { DivElement element = Document.get().createDivElement(); setElement(element); @@ -45,7 +50,7 @@ public class VMeasuringOrderedLayout extends ComplexPanel { insert(widget, wrapperElement, index, false); } - widget.setLayoutData(layoutSlot); + widgetToSlot.put(widget, layoutSlot); } private void togglePrefixedStyleName(String name, boolean enabled) { @@ -74,7 +79,8 @@ public class VMeasuringOrderedLayout extends ComplexPanel { } } - public void removeSlot(VLayoutSlot slot) { + public void removeSlotForWidget(Widget widget) { + VLayoutSlot slot = getSlotForChild(widget); VCaption caption = slot.getCaption(); if (caption != null) { // Must remove using setCaption to ensure dependencies (layout -> @@ -84,15 +90,11 @@ public class VMeasuringOrderedLayout extends ComplexPanel { remove(slot.getWidget()); getElement().removeChild(slot.getWrapperElement()); + widgetToSlot.remove(widget); } public VLayoutSlot getSlotForChild(Widget widget) { - Object o = widget.getLayoutData(); - if (o instanceof VLayoutSlot) { - return (VLayoutSlot) o; - } - - return null; + return widgetToSlot.get(widget); } public void setCaption(Widget child, VCaption caption) {