From f52babe2f00763d23ec91a2789224e363b2708e0 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Wed, 21 Nov 2012 14:05:51 +0200 Subject: [PATCH] Implement HasComponents directly in PopupView (#10238) Change-Id: If0bd9d3cf92c4f040e63f693da214aacac421168 --- .../ui/popupview/PopupViewConnector.java | 4 +- server/src/com/vaadin/ui/PopupView.java | 119 +++--------------- 2 files changed, 18 insertions(+), 105 deletions(-) diff --git a/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java b/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java index 7fdd986d93..d4567c19f2 100644 --- a/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java +++ b/client/src/com/vaadin/client/ui/popupview/PopupViewConnector.java @@ -24,7 +24,7 @@ import com.vaadin.client.ConnectorHierarchyChangeEvent; import com.vaadin.client.VCaption; import com.vaadin.client.VCaptionWrapper; import com.vaadin.client.communication.StateChangeEvent; -import com.vaadin.client.ui.AbstractComponentContainerConnector; +import com.vaadin.client.ui.AbstractHasComponentsConnector; import com.vaadin.client.ui.PostLayoutListener; import com.vaadin.client.ui.VPopupView; import com.vaadin.shared.ui.ComponentStateUtil; @@ -34,7 +34,7 @@ import com.vaadin.shared.ui.popupview.PopupViewState; import com.vaadin.ui.PopupView; @Connect(PopupView.class) -public class PopupViewConnector extends AbstractComponentContainerConnector +public class PopupViewConnector extends AbstractHasComponentsConnector implements PostLayoutListener, VisibilityChangeHandler { private boolean centerAfterLayout = false; diff --git a/server/src/com/vaadin/ui/PopupView.java b/server/src/com/vaadin/ui/PopupView.java index b6d5012e20..843f306d2a 100644 --- a/server/src/com/vaadin/ui/PopupView.java +++ b/server/src/com/vaadin/ui/PopupView.java @@ -17,6 +17,7 @@ package com.vaadin.ui; import java.io.Serializable; import java.lang.reflect.Method; +import java.util.Collections; import java.util.Iterator; import com.vaadin.shared.ui.popupview.PopupViewServerRpc; @@ -32,7 +33,7 @@ import com.vaadin.shared.ui.popupview.PopupViewState; * @author Vaadin Ltd. */ @SuppressWarnings("serial") -public class PopupView extends AbstractComponentContainer { +public class PopupView extends AbstractComponent implements HasComponents { private Content content; private Component visibleComponent; @@ -58,42 +59,6 @@ public class PopupView extends AbstractComponentContainer { } }; - /** - * Iterator for the visible components (zero or one components), used by - * {@link PopupView#getComponentIterator()}. - */ - private static class SingleComponentIterator implements - Iterator, Serializable { - - private final Component component; - private boolean first; - - public SingleComponentIterator(Component component) { - this.component = component; - first = (component == null); - } - - @Override - public boolean hasNext() { - return !first; - } - - @Override - public Component next() { - if (!first) { - first = true; - return component; - } else { - return null; - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - } - /* Constructors */ /** @@ -177,9 +142,16 @@ public class PopupView extends AbstractComponentContainer { throw new java.lang.IllegalStateException( "PopupView.Content did not return Component to set visible"); } - super.addComponent(visibleComponent); + if (visibleComponent.getParent() != null) { + // If the component already has a parent, try to remove it + AbstractSingleComponentContainer + .removeFromParent(visibleComponent); + } + visibleComponent.setParent(this); } else { - super.removeComponent(visibleComponent); + if (visibleComponent.getParent() == this) { + visibleComponent.setParent(null); + } visibleComponent = null; } fireEvent(new PopupVisibilityEvent(this)); @@ -240,7 +212,11 @@ public class PopupView extends AbstractComponentContainer { */ @Override public Iterator iterator() { - return new SingleComponentIterator(visibleComponent); + if (content != null) { + return Collections.singletonList(visibleComponent).iterator(); + } else { + return Collections. emptyList().iterator(); + } } /** @@ -249,73 +225,10 @@ public class PopupView extends AbstractComponentContainer { * * @return the number of contained components (zero or one) */ - @Override public int getComponentCount() { return (visibleComponent != null ? 1 : 0); } - /** - * Not supported in this implementation. - * - * @see com.vaadin.ui.AbstractComponentContainer#removeAllComponents() - * @throws UnsupportedOperationException - */ - @Override - public void removeAllComponents() { - throw new UnsupportedOperationException(); - } - - /** - * Not supported in this implementation. - * - * @see com.vaadin.ui.AbstractComponentContainer#moveComponentsFrom(com.vaadin.ui.ComponentContainer) - * @throws UnsupportedOperationException - */ - @Override - public void moveComponentsFrom(ComponentContainer source) - throws UnsupportedOperationException { - - throw new UnsupportedOperationException(); - } - - /** - * Not supported in this implementation. - * - * @see com.vaadin.ui.AbstractComponentContainer#addComponent(com.vaadin.ui.Component) - * @throws UnsupportedOperationException - */ - @Override - public void addComponent(Component c) throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - - } - - /** - * Not supported in this implementation. - * - * @see com.vaadin.ui.ComponentContainer#replaceComponent(com.vaadin.ui.Component, - * com.vaadin.ui.Component) - * @throws UnsupportedOperationException - */ - @Override - public void replaceComponent(Component oldComponent, Component newComponent) - throws UnsupportedOperationException { - - throw new UnsupportedOperationException(); - } - - /** - * Not supported in this implementation - * - * @see com.vaadin.ui.AbstractComponentContainer#removeComponent(com.vaadin.ui.Component) - */ - @Override - public void removeComponent(Component c) - throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - - } - @Override protected PopupViewState getState() { return (PopupViewState) super.getState(); -- 2.39.5