]> source.dussan.org Git - vaadin-framework.git/commitdiff
#8500 Made Form implement HasComponents to properly support sending
authorArtur Signell <artur@vaadin.com>
Tue, 13 Mar 2012 10:13:16 +0000 (12:13 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 14 Mar 2012 14:00:41 +0000 (16:00 +0200)
the component hierarchy

src/com/vaadin/ui/Form.java

index 1e30eb94bfd438f20736fd17c2b6e7e1576704f1..c4ae0457a9b52673654332e0962977f89ec839d3 100644 (file)
@@ -4,6 +4,7 @@
 
 package com.vaadin.ui;
 
+import java.io.Serializable;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -65,7 +66,7 @@ import com.vaadin.terminal.gwt.client.ui.FormConnector;
 @ClientWidget(FormConnector.class)
 @Deprecated
 public class Form extends AbstractField<Object> implements Item.Editor,
-        Buffered, Item, Validatable, Action.Notifier {
+        Buffered, Item, Validatable, Action.Notifier, HasComponents {
 
     private Object propertyValue;
 
@@ -1357,4 +1358,66 @@ public class Form extends AbstractField<Object> implements Item.Editor,
         }
     }
 
+    public Iterator<Component> iterator() {
+        return getComponentIterator();
+    }
+
+    /**
+     * Modifiable and Serializable Iterator for the components, used by
+     * {@link Form#getComponentIterator()}.
+     */
+    private class ComponentIterator implements Iterator<Component>,
+            Serializable {
+
+        int i = 0;
+
+        public boolean hasNext() {
+            if (i < getComponentCount()) {
+                return true;
+            }
+            return false;
+        }
+
+        public Component next() {
+            if (!hasNext()) {
+                return null;
+            }
+            i++;
+            if (i == 1) {
+                return layout != null ? layout : formFooter;
+            } else if (i == 2) {
+                return formFooter;
+            }
+            return null;
+        }
+
+        public void remove() {
+            if (i == 1) {
+                if (layout != null) {
+                    setLayout(null);
+                    i = 0;
+                } else {
+                    setFooter(null);
+                }
+            } else if (i == 2) {
+                setFooter(null);
+            }
+        }
+    }
+
+    public Iterator<Component> getComponentIterator() {
+        return new ComponentIterator();
+    }
+
+    public int getComponentCount() {
+        int count = 0;
+        if (layout != null) {
+            count++;
+        }
+        if (formFooter != null) {
+            count++;
+        }
+
+        return count;
+    }
 }