]> source.dussan.org Git - vaadin-framework.git/commitdiff
Store widget -> LayoutSlot mapping in a map instead of LayoutData
authorArtur Signell <artur@vaadin.com>
Fri, 23 Mar 2012 09:23:37 +0000 (11:23 +0200)
committerArtur Signell <artur@vaadin.com>
Fri, 23 Mar 2012 09:29:50 +0000 (11:29 +0200)
This enables retrieval of the slot also after the widget has been
removed from the layout

src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java
src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayout.java

index dc0812c6f13e8a8ad6eb547e0d7d34af137f3dbd..ce2d9c28ad29548a0a69c94b2ad40aeb98590115 100644 (file)
@@ -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());
             }
         }
 
index 0bd2a90c888a8029c7911388c842bfd998e2de61..b7d28c56b976e447249b1f2b89db3cac2356c26a 100644 (file)
@@ -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<Widget, VLayoutSlot> widgetToSlot = new HashMap<Widget, VLayoutSlot>();
+
     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) {