From: Artur Signell Date: Tue, 13 Mar 2012 10:13:16 +0000 (+0200) Subject: #8500 Made Form implement HasComponents to properly support sending X-Git-Tag: 7.0.0.alpha2~341 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5874f0bd70621264cfc686217a2911cd765ebee8;p=vaadin-framework.git #8500 Made Form implement HasComponents to properly support sending the component hierarchy --- 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; + } }