]> source.dussan.org Git - vaadin-framework.git/commitdiff
#8500, #3557 Added HasComponents (Iterable<Component>) that must be
authorArtur Signell <artur@vaadin.com>
Tue, 13 Mar 2012 09:29:43 +0000 (11:29 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 14 Mar 2012 14:00:37 +0000 (16:00 +0200)
implemented by all components containing components.

This might still change when #2924/#2527 is fixed

src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
src/com/vaadin/ui/AbstractComponentContainer.java
src/com/vaadin/ui/ComponentContainer.java
src/com/vaadin/ui/CustomField.java
src/com/vaadin/ui/HasComponents.java [new file with mode: 0644]

index 66e692694f821c99c5a49a4a80cda766d1697073..04f64ecaead173f464b232734fe8762af4291b76 100644 (file)
@@ -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<Component> 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<Component> getChildComponentIterator(ComponentContainer cc) {
+    private Iterable<Component> getChildComponents(HasComponents cc) {
         if (cc instanceof Panel) {
             // This is so wrong.. (#2924)
             if (((Panel) cc).getContent() == null) {
-                return new NullIterator<Component>();
+                return Collections.emptyList();
             } else {
-                return Collections.singleton(
-                        (Component) ((Panel) cc).getContent()).iterator();
+                return Collections.singleton((Component) ((Panel) cc)
+                        .getContent());
             }
         }
-        return cc.getComponentIterator();
+        return cc;
     }
 
     /**
index bbe2c20ea5282ef0908ae0a7fe41c726dfdd5308..20b79e8a067ee59de81ea8e80027b7413f876cd8 100644 (file)
@@ -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<Component> iterator() {
+        return getComponentIterator();
+    }
 }
\ No newline at end of file
index f2bfc723a5a06388a764d29629f850d0304586d7..c9bd7f5d8feab356ea55ff2c0b966deb3e45800e 100644 (file)
@@ -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<Component> getComponentIterator();
-
     /**
      * Gets the number of children this {@link ComponentContainer} has. This
      * must be symmetric with what {@link #getComponentIterator()} returns.
index 5804c847af5d2b4eeafaed90957f8df1a15b6f71..5436cd0480650e75393f4098ebe27a58c09bdcc1 100644 (file)
@@ -173,6 +173,10 @@ public abstract class CustomField<T> extends AbstractField<T> implements
         return new ComponentIterator();
     }
 
+    public Iterator<Component> 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 (file)
index 0000000..e6f71fb
--- /dev/null
@@ -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<Component> {
+    /**
+     * 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<Component> getComponentIterator();
+
+}