From 5874f0bd70621264cfc686217a2911cd765ebee8 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 13 Mar 2012 12:13:16 +0200 Subject: [PATCH] #8500 Made Form implement HasComponents to properly support sending the component hierarchy --- src/com/vaadin/ui/Form.java | 65 ++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/com/vaadin/ui/Form.java b/src/com/vaadin/ui/Form.java index 1e30eb94bf..c4ae0457a9 100644 --- a/src/com/vaadin/ui/Form.java +++ b/src/com/vaadin/ui/Form.java @@ -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 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 implements Item.Editor, } } + public Iterator iterator() { + return getComponentIterator(); + } + + /** + * Modifiable and Serializable Iterator for the components, used by + * {@link Form#getComponentIterator()}. + */ + private class ComponentIterator implements Iterator, + 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 getComponentIterator() { + return new ComponentIterator(); + } + + public int getComponentCount() { + int count = 0; + if (layout != null) { + count++; + } + if (formFooter != null) { + count++; + } + + return count; + } } -- 2.39.5