]> source.dussan.org Git - vaadin-framework.git/commitdiff
Pass ManagedLayout to layout slot to avoid NPE when a child is detached
authorArtur Signell <artur@vaadin.com>
Tue, 20 Mar 2012 13:57:37 +0000 (15:57 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 21 Mar 2012 13:28:09 +0000 (15:28 +0200)
(getParent() returns null)

src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java
src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java
src/com/vaadin/terminal/gwt/client/ui/layout/ComponentConnectorLayoutSlot.java

index 0b077d93535b24eb8e05c687072417da5d010282..f4a65df56bd94fba859f4acb332e47a4bb3ddfec 100644 (file)
@@ -241,7 +241,7 @@ public abstract class AbstractOrderedLayoutConnector extends
                 // another AbstractOrderedLayout. In this case we discard it and
                 // create a new slot.
                 slot = new ComponentConnectorLayoutSlot(getWidget()
-                        .getStylePrimaryName(), child);
+                        .getStylePrimaryName(), child, this);
             }
             layout.addOrMove(slot, currentIndex++);
         }
index 01e1b7c8dacbca6e1533d5dd9e5119d06d837289..5acf85b72be4f58a707b41e838cdd71793a50cea 100644 (file)
@@ -59,8 +59,9 @@ public class VGridLayout extends ComplexPanel {
         setStyleName(CLASSNAME);
     }
 
-    private ComponentConnector getPaintable() {
-        return ConnectorMap.get(client).getConnector(this);
+    private GridLayoutConnector getConnector() {
+        return (GridLayoutConnector) ConnectorMap.get(client)
+                .getConnector(this);
     }
 
     /**
@@ -235,11 +236,11 @@ public class VGridLayout extends ComplexPanel {
     }
 
     private boolean isUndefinedHeight() {
-        return getPaintable().isUndefinedHeight();
+        return getConnector().isUndefinedHeight();
     }
 
     private boolean isUndefinedWidth() {
-        return getPaintable().isUndefinedWidth();
+        return getConnector().isUndefinedWidth();
     }
 
     private void detectRowHeights() {
@@ -455,7 +456,7 @@ public class VGridLayout extends ComplexPanel {
 
         public boolean hasRelativeHeight() {
             if (slot != null) {
-                return slot.getPaintable().isRelativeHeight();
+                return slot.getChild().isRelativeHeight();
             } else {
                 return true;
             }
@@ -513,7 +514,7 @@ public class VGridLayout extends ComplexPanel {
 
         protected boolean hasRelativeWidth() {
             if (slot != null) {
-                return slot.getPaintable().isRelativeWidth();
+                return slot.getChild().isRelativeWidth();
             } else {
                 return true;
             }
@@ -551,15 +552,16 @@ public class VGridLayout extends ComplexPanel {
                                                        // about childUidl
             hasContent = childUidl != null;
             if (hasContent) {
-                ComponentConnector paintable = client.getPaintable(childUidl);
+                ComponentConnector childConnector = client
+                        .getPaintable(childUidl);
 
-                if (slot == null || slot.getPaintable() != paintable) {
+                if (slot == null || slot.getChild() != childConnector) {
                     slot = new ComponentConnectorLayoutSlot(CLASSNAME,
-                            paintable);
+                            childConnector, getConnector());
                     Element slotWrapper = slot.getWrapperElement();
                     getElement().appendChild(slotWrapper);
 
-                    Widget widget = paintable.getWidget();
+                    Widget widget = childConnector.getWidget();
                     insert(widget, slotWrapper, getWidgetCount(), false);
                     Cell oldCell = widgetToCell.put(widget, this);
                     if (oldCell != null) {
@@ -568,7 +570,7 @@ public class VGridLayout extends ComplexPanel {
                     }
                 }
 
-                paintable.updateFromUIDL(childUidl, client);
+                childConnector.updateFromUIDL(childUidl, client);
             }
         }
 
index 5df2eb748854ef0138a1b250e2a1c6a0f7a4e256..8ff012e08690bcaffed6bf7028954485a83fd66d 100644 (file)
@@ -10,77 +10,80 @@ import com.vaadin.terminal.gwt.client.ui.ManagedLayout;
 
 public class ComponentConnectorLayoutSlot extends VLayoutSlot {
 
-    final ComponentConnector paintable;
-    private LayoutManager layoutManager;
+    final ComponentConnector child;
+    final ManagedLayout layout;
 
     public ComponentConnectorLayoutSlot(String baseClassName,
-            ComponentConnector paintable) {
-        super(baseClassName, paintable.getWidget());
-        this.paintable = paintable;
-        layoutManager = paintable.getLayoutManager();
+            ComponentConnector child, ManagedLayout layout) {
+        super(baseClassName, child.getWidget());
+        this.child = child;
+        this.layout = layout;
     }
 
-    public ComponentConnector getPaintable() {
-        return paintable;
+    public ComponentConnector getChild() {
+        return child;
     }
 
     @Override
     protected int getCaptionHeight() {
         VCaption caption = getCaption();
-        return caption != null ? layoutManager.getOuterHeight(caption
-                .getElement()) : 0;
+        return caption != null ? getLayoutManager().getOuterHeight(
+                caption.getElement()) : 0;
     }
 
     @Override
     protected int getCaptionWidth() {
         VCaption caption = getCaption();
-        return caption != null ? layoutManager.getOuterWidth(caption
-                .getElement()) : 0;
+        return caption != null ? getLayoutManager().getOuterWidth(
+                caption.getElement()) : 0;
+    }
+
+    public LayoutManager getLayoutManager() {
+        return layout.getLayoutManager();
     }
 
     @Override
     public void setCaption(VCaption caption) {
         VCaption oldCaption = getCaption();
         if (oldCaption != null) {
-            layoutManager.unregisterDependency(
-                    (ManagedLayout) paintable.getParent(),
+            getLayoutManager().unregisterDependency(layout,
                     oldCaption.getElement());
         }
         super.setCaption(caption);
         if (caption != null) {
-            layoutManager
-                    .registerDependency((ManagedLayout) paintable.getParent(),
-                            caption.getElement());
+            getLayoutManager().registerDependency(
+                    (ManagedLayout) child.getParent(), caption.getElement());
         }
     }
 
     @Override
     public int getWidgetHeight() {
-        return layoutManager.getOuterHeight(paintable.getWidget().getElement());
+        return getLayoutManager()
+                .getOuterHeight(child.getWidget().getElement());
     }
 
     @Override
     public int getWidgetWidth() {
-        return layoutManager.getOuterWidth(paintable.getWidget().getElement());
+        return getLayoutManager().getOuterWidth(child.getWidget().getElement());
     }
 
     @Override
     public boolean isUndefinedHeight() {
-        return paintable.isUndefinedHeight();
+        return child.isUndefinedHeight();
     }
 
     @Override
     public boolean isUndefinedWidth() {
-        return paintable.isUndefinedWidth();
+        return child.isUndefinedWidth();
     }
 
     @Override
     public boolean isRelativeHeight() {
-        return paintable.isRelativeHeight();
+        return child.isRelativeHeight();
     }
 
     @Override
     public boolean isRelativeWidth() {
-        return paintable.isRelativeWidth();
+        return child.isRelativeWidth();
     }
 }