From: Artur Signell Date: Tue, 20 Mar 2012 13:57:37 +0000 (+0200) Subject: Pass ManagedLayout to layout slot to avoid NPE when a child is detached X-Git-Tag: 7.0.0.alpha2~267 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cc74de9d35f5f85e022d5f2cdbb09258e6e8e8b0;p=vaadin-framework.git Pass ManagedLayout to layout slot to avoid NPE when a child is detached (getParent() returns null) --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java index 0b077d9353..f4a65df56b 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java @@ -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++); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java index 01e1b7c8da..5acf85b72b 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java @@ -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); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/layout/ComponentConnectorLayoutSlot.java b/src/com/vaadin/terminal/gwt/client/ui/layout/ComponentConnectorLayoutSlot.java index 5df2eb7488..8ff012e086 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/layout/ComponentConnectorLayoutSlot.java +++ b/src/com/vaadin/terminal/gwt/client/ui/layout/ComponentConnectorLayoutSlot.java @@ -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(); } }