diff options
author | Ahmed Ashour <asashour@yahoo.com> | 2017-09-29 14:13:37 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-09-29 15:13:37 +0300 |
commit | 46950473fdb3cfb9d44660b3a642a9229cecded2 (patch) | |
tree | 76caf6a1ffe1fdb9c111b551a42a2507b3dda4b4 /client | |
parent | 3c7a9514117b348336b89306de735d92c8e9f463 (diff) | |
download | vaadin-framework-46950473fdb3cfb9d44660b3a642a9229cecded2.tar.gz vaadin-framework-46950473fdb3cfb9d44660b3a642a9229cecded2.zip |
UIDL to implement Iterable (#10101)
Diffstat (limited to 'client')
7 files changed, 42 insertions, 28 deletions
diff --git a/client/src/main/java/com/vaadin/client/UIDL.java b/client/src/main/java/com/vaadin/client/UIDL.java index 332b7aae9d..2c66568d65 100644 --- a/client/src/main/java/com/vaadin/client/UIDL.java +++ b/client/src/main/java/com/vaadin/client/UIDL.java @@ -32,8 +32,8 @@ import com.vaadin.ui.Component; * from the server. * <p> * UIDL is hierarchical, and there are a few methods to retrieve the children, - * {@link #getChildCount()}, {@link #getChildIterator()} - * {@link #getChildString(int)}, {@link #getChildUIDL(int)}. + * {@link #getChildCount()}, {@link #iterator()} {@link #getChildString(int)}, + * {@link #getChildUIDL(int)}. * </p> * <p> * It can be helpful to keep in mind that UIDL was originally modeled in XML, so @@ -42,7 +42,7 @@ import com.vaadin.ui.Component; * but will be skipped by the methods mentioned above. * </p> */ -public final class UIDL extends JavaScriptObject { +public final class UIDL extends JavaScriptObject implements Iterable<Object> { protected UIDL() { } @@ -62,7 +62,8 @@ public final class UIDL extends JavaScriptObject { * Gets the name of this UIDL section, as created with * {@link PaintTarget#startTag(String) PaintTarget.startTag()} in the * server-side {@link Component#paint(PaintTarget) Component.paint()} or - * (usually) {@link com.vaadin.ui.AbstractComponent#paintContent(PaintTarget) + * (usually) + * {@link com.vaadin.ui.AbstractComponent#paintContent(PaintTarget) * AbstractComponent.paintContent()}. Note that if the UIDL corresponds to a * Paintable, a component identifier will be returned instead - this is used * internally and is not needed within @@ -287,8 +288,33 @@ public final class UIDL extends JavaScriptObject { * </p> * * @return an iterator for iterating over UIDL children + * @deprecated As of 8.2, please use {@link #iterator()} instead */ + @Deprecated public Iterator<Object> getChildIterator() { + return iterator(); + } + + /** + * Gets an iterator that can be used to iterate trough the children of this + * UIDL. + * <p> + * The Object returned by <code>next()</code> will be appropriately typed - + * if it's UIDL, {@link #getTag()} can be used to check which section is in + * question. + * </p> + * <p> + * The basic use case is to iterate over the children of an UIDL update, and + * update the appropriate part of the widget for each child encountered, e.g + * if <code>getTag()</code> returns "color", one would update the widgets + * color to reflect the value of the "color" section. + * </p> + * + * @return an iterator for iterating over UIDL children + * @since + */ + @Override + public Iterator<Object> iterator() { return new Iterator<Object>() { @@ -545,9 +571,7 @@ public final class UIDL extends JavaScriptObject { * @return the child UIDL or null if child wit given name was not found */ public UIDL getChildByTagName(String tagName) { - Iterator<Object> childIterator = getChildIterator(); - while (childIterator.hasNext()) { - Object next = childIterator.next(); + for (Object next : this) { if (next instanceof UIDL) { UIDL childUIDL = (UIDL) next; if (childUIDL.getTag().equals(tagName)) { diff --git a/client/src/main/java/com/vaadin/client/VUIDLBrowser.java b/client/src/main/java/com/vaadin/client/VUIDLBrowser.java index 9ed6229281..7068f7c790 100644 --- a/client/src/main/java/com/vaadin/client/VUIDLBrowser.java +++ b/client/src/main/java/com/vaadin/client/VUIDLBrowser.java @@ -15,7 +15,6 @@ */ package com.vaadin.client; -import java.util.Iterator; import java.util.Set; import com.google.gwt.core.client.JsArray; @@ -311,9 +310,7 @@ public class VUIDLBrowser extends SimpleTree { // Ignored, no variables } - final Iterator<Object> i = uidl.getChildIterator(); - while (i.hasNext()) { - final Object child = i.next(); + for (final Object child : uidl) { try { add(new UIDLItem((UIDL) child)); } catch (final Exception e) { diff --git a/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java b/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java index 9679473c80..d85643099c 100644 --- a/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java +++ b/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java @@ -83,9 +83,8 @@ public class ShortcutActionHandler { */ public void updateActionMap(UIDL c) { actions.clear(); - final Iterator<?> it = c.getChildIterator(); - while (it.hasNext()) { - final UIDL action = (UIDL) it.next(); + for (final Object child : c) { + final UIDL action = (UIDL) child; int[] modifiers = null; if (action.hasAttribute("mk")) { diff --git a/client/src/main/java/com/vaadin/client/ui/VEmbedded.java b/client/src/main/java/com/vaadin/client/ui/VEmbedded.java index 551bf161d7..a6045848a7 100644 --- a/client/src/main/java/com/vaadin/client/ui/VEmbedded.java +++ b/client/src/main/java/com/vaadin/client/ui/VEmbedded.java @@ -17,7 +17,6 @@ package com.vaadin.client.ui; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import com.google.gwt.dom.client.Element; @@ -195,10 +194,7 @@ public class VEmbedded extends HTML { public static Map<String, String> getParameters(UIDL uidl) { Map<String, String> parameters = new HashMap<>(); - Iterator<Object> childIterator = uidl.getChildIterator(); - while (childIterator.hasNext()) { - - Object child = childIterator.next(); + for (Object child : uidl) { if (child instanceof UIDL) { UIDL childUIDL = (UIDL) child; diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VAbstractDropHandler.java b/client/src/main/java/com/vaadin/client/ui/dd/VAbstractDropHandler.java index c88a3079fb..89d33881ff 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VAbstractDropHandler.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VAbstractDropHandler.java @@ -50,7 +50,7 @@ public abstract class VAbstractDropHandler implements VDropHandler { * contained in given uidl node */ if (!uidl.getTag().equals("-ac")) { - Iterator<Object> childIterator = uidl.getChildIterator(); + Iterator<Object> childIterator = uidl.iterator(); while (!uidl.getTag().equals("-ac") && childIterator.hasNext()) { uidl = (UIDL) childIterator.next(); } diff --git a/client/src/main/java/com/vaadin/client/ui/menubar/MenuBarConnector.java b/client/src/main/java/com/vaadin/client/ui/menubar/MenuBarConnector.java index 72d0784c3e..aa0ee3ab7b 100644 --- a/client/src/main/java/com/vaadin/client/ui/menubar/MenuBarConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/menubar/MenuBarConnector.java @@ -100,7 +100,7 @@ public class MenuBarConnector extends AbstractComponentConnector } UIDL uidlItems = uidl.getChildUIDL(1); - Iterator<Object> itr = uidlItems.getChildIterator(); + Iterator<Object> itr = uidlItems.iterator(); Stack<Iterator<Object>> iteratorStack = new Stack<>(); Stack<VMenuBar> menuStack = new Stack<>(); VMenuBar currentMenu = getWidget(); @@ -137,7 +137,7 @@ public class MenuBarConnector extends AbstractComponentConnector if (item.getChildCount() > 0) { menuStack.push(currentMenu); iteratorStack.push(itr); - itr = item.getChildIterator(); + itr = item.iterator(); currentMenu = new VMenuBar(true, currentMenu); client.getVTooltip().connectHandlersToWidget(currentMenu); // this is the top-level style that also propagates to items - diff --git a/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java b/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java index 749d72b575..6a43b334c1 100644 --- a/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java @@ -21,7 +21,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.logging.Logger; @@ -467,8 +466,8 @@ public class UIConnector extends AbstractSingleComponentContainerConnector /* * Search the UIDL stream for CSS resources and strings to be injected. */ - for (Iterator<?> it = uidl.getChildIterator(); it.hasNext();) { - UIDL cssInjectionsUidl = (UIDL) it.next(); + for (Object child : uidl) { + UIDL cssInjectionsUidl = (UIDL) child; // Check if we have resources to inject if (cssInjectionsUidl.getTag().equals("css-resource")) { @@ -482,9 +481,8 @@ public class UIConnector extends AbstractSingleComponentContainerConnector getHead().appendChild(link); // Check if we have CSS string to inject } else if (cssInjectionsUidl.getTag().equals("css-string")) { - for (Iterator<?> it2 = cssInjectionsUidl.getChildIterator(); it2 - .hasNext();) { - StyleInjector.injectAtEnd((String) it2.next()); + for (Object c : cssInjectionsUidl) { + StyleInjector.injectAtEnd((String) c); StyleInjector.flush(); } } |