Browse Source

Pass ManagedLayout to layout slot to avoid NPE when a child is detached

(getParent() returns null)
tags/7.0.0.alpha2
Artur Signell 12 years ago
parent
commit
cc74de9d35

+ 1
- 1
src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java View 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++);
}

+ 13
- 11
src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java View 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);
}
}


+ 26
- 23
src/com/vaadin/terminal/gwt/client/ui/layout/ComponentConnectorLayoutSlot.java View 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();
}
}

Loading…
Cancel
Save