From 751d60aaf6b5dec813f5f7fe3d46717a0b1ca2ef Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 13 Mar 2012 11:29:43 +0200 Subject: [PATCH] #8500, #3557 Added HasComponents (Iterable) that must be implemented by all components containing components. This might still change when #2924/#2527 is fixed --- .../server/AbstractCommunicationManager.java | 20 +++++++--------- .../vaadin/ui/AbstractComponentContainer.java | 10 ++++++++ src/com/vaadin/ui/ComponentContainer.java | 12 +--------- src/com/vaadin/ui/CustomField.java | 4 ++++ src/com/vaadin/ui/HasComponents.java | 24 +++++++++++++++++++ 5 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 src/com/vaadin/ui/HasComponents.java diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 66e692694f..04f64ecaea 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -68,7 +68,7 @@ import com.vaadin.terminal.gwt.server.ComponentSizeValidator.InvalidLayout; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.AbstractField; import com.vaadin.ui.Component; -import com.vaadin.ui.ComponentContainer; +import com.vaadin.ui.HasComponents; import com.vaadin.ui.Panel; import com.vaadin.ui.Root; @@ -945,14 +945,12 @@ public abstract class AbstractCommunicationManager implements JSONObject hierarchyInfo = new JSONObject(); for (Paintable p : hierarchyPendingQueue) { - if (p instanceof ComponentContainer) { - ComponentContainer cc = (ComponentContainer) p; + if (p instanceof HasComponents) { + HasComponents cc = (HasComponents) p; String connectorId = paintableIdMap.get(cc); JSONArray children = new JSONArray(); - Iterator iterator = getChildComponentIterator(cc); - while (iterator.hasNext()) { - Component child = iterator.next(); + for (Component child : getChildComponents(cc)) { if (child.getState().isVisible()) { String childConnectorId = getPaintableId(child); children.put(childConnectorId); @@ -1177,17 +1175,17 @@ public abstract class AbstractCommunicationManager implements } - private Iterator getChildComponentIterator(ComponentContainer cc) { + private Iterable getChildComponents(HasComponents cc) { if (cc instanceof Panel) { // This is so wrong.. (#2924) if (((Panel) cc).getContent() == null) { - return new NullIterator(); + return Collections.emptyList(); } else { - return Collections.singleton( - (Component) ((Panel) cc).getContent()).iterator(); + return Collections.singleton((Component) ((Panel) cc) + .getContent()); } } - return cc.getComponentIterator(); + return cc; } /** diff --git a/src/com/vaadin/ui/AbstractComponentContainer.java b/src/com/vaadin/ui/AbstractComponentContainer.java index bbe2c20ea5..20b79e8a06 100644 --- a/src/com/vaadin/ui/AbstractComponentContainer.java +++ b/src/com/vaadin/ui/AbstractComponentContainer.java @@ -372,4 +372,14 @@ public abstract class AbstractComponentContainer extends AbstractComponent } } + /** + * Returns an iterator for the child components. + * + * @return An iterator for the child components. + * @see #getComponentIterator() + * @since 7.0.0 + */ + public Iterator iterator() { + return getComponentIterator(); + } } \ No newline at end of file diff --git a/src/com/vaadin/ui/ComponentContainer.java b/src/com/vaadin/ui/ComponentContainer.java index f2bfc723a5..c9bd7f5d8f 100644 --- a/src/com/vaadin/ui/ComponentContainer.java +++ b/src/com/vaadin/ui/ComponentContainer.java @@ -5,7 +5,6 @@ package com.vaadin.ui; import java.io.Serializable; -import java.util.Iterator; /** * Extension to the {@link Component} interface which adds to it the capacity to @@ -17,7 +16,7 @@ import java.util.Iterator; * @VERSION@ * @since 3.0 */ -public interface ComponentContainer extends Component { +public interface ComponentContainer extends HasComponents { /** * Adds the component into this container. @@ -60,15 +59,6 @@ public interface ComponentContainer extends Component { */ public void replaceComponent(Component oldComponent, Component newComponent); - /** - * Gets an iterator to the collection of contained components. Using this - * iterator it is possible to step through all components contained in this - * container. - * - * @return the component iterator. - */ - public Iterator getComponentIterator(); - /** * Gets the number of children this {@link ComponentContainer} has. This * must be symmetric with what {@link #getComponentIterator()} returns. diff --git a/src/com/vaadin/ui/CustomField.java b/src/com/vaadin/ui/CustomField.java index 5804c847af..5436cd0480 100644 --- a/src/com/vaadin/ui/CustomField.java +++ b/src/com/vaadin/ui/CustomField.java @@ -173,6 +173,10 @@ public abstract class CustomField extends AbstractField implements return new ComponentIterator(); } + public Iterator iterator() { + return getComponentIterator(); + } + public int getComponentCount() { return (null != getContent()) ? 1 : 0; } diff --git a/src/com/vaadin/ui/HasComponents.java b/src/com/vaadin/ui/HasComponents.java new file mode 100644 index 0000000000..e6f71fb3ed --- /dev/null +++ b/src/com/vaadin/ui/HasComponents.java @@ -0,0 +1,24 @@ +package com.vaadin.ui; + +import java.util.Iterator; + +/** + * Interface that must be implemented by all {@link Component}s that contain + * other {@link Component}s. + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + * + */ +public interface HasComponents extends Component, Iterable { + /** + * Gets an iterator to the collection of contained components. Using this + * iterator it is possible to step through all components contained in this + * container. + * + * @return the component iterator. + */ + public Iterator getComponentIterator(); + +} -- 2.39.5