Author: jdonnerstag
Date: Fri Jul  8 21:02:23 2011
New Revision: 1144511

URL: http://svn.apache.org/viewvc?rev=1144511&view=rev
Log:
fixed childFirst issue in "visitChildren and friends require inner classes. 
Replace with iterators"
Issue: WICKET-3789

Modified:
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/iterator/AbstractHierarchyIterator.java
    
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/iterator/AbstractHierarchyIteratorTest.java

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/iterator/AbstractHierarchyIterator.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/iterator/AbstractHierarchyIterator.java?rev=1144511&r1=1144510&r2=1144511&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/iterator/AbstractHierarchyIterator.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/util/iterator/AbstractHierarchyIterator.java
 Fri Jul  8 21:02:23 2011
@@ -80,6 +80,16 @@ public abstract class AbstractHierarchyI
 
        /**
         * 
+        * @param childFirst
+        *            If true, than children are visited before their parent is.
+        */
+       public final void setChildFirst(final boolean childFirst)
+       {
+               this.childFirst = childFirst;
+       }
+
+       /**
+        * 
         * @param node
         * @return True, if node is a container and has at least one child.
         */
@@ -121,7 +131,7 @@ public abstract class AbstractHierarchyI
                }
 
                // Do we need to traverse into the next level?
-               if (traverse)
+               if (!childFirst && traverse)
                {
                        // Try to find the next element
                        if (moveDown(data.lastNode) == false)
@@ -209,9 +219,6 @@ public abstract class AbstractHierarchyI
                                        // No more elements
                                        return false;
                                }
-
-                               // We did traverse the children already
-                               traverse = false;
                        }
 
                        // The user interested in the node?
@@ -274,7 +281,7 @@ public abstract class AbstractHierarchyI
                data = stack.pop();
 
                // If we are on childFirst, than it's now time to handle the 
parent
-               if (traverse)
+               if (childFirst)
                {
                        hasNextWasLast = true;
                        if (onFilter(data.lastNode) == true)

Modified: 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/iterator/AbstractHierarchyIteratorTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/iterator/AbstractHierarchyIteratorTest.java?rev=1144511&r1=1144510&r2=1144511&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/iterator/AbstractHierarchyIteratorTest.java
 (original)
+++ 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/util/iterator/AbstractHierarchyIteratorTest.java
 Fri Jul  8 21:02:23 2011
@@ -294,6 +294,40 @@ public class AbstractHierarchyIteratorTe
        }
 
        /** */
+       @Test
+       public void childFirst()
+       {
+               Page page = new MyPage();
+               WebComponent a;
+               page.add(a = new WebComponent("a"));
+               WebMarkupContainer b;
+               page.add(b = new WebMarkupContainer("b"));
+               WebMarkupContainer b1;
+               b.add(b1 = new WebMarkupContainer("b1"));
+               WebMarkupContainer b2;
+               b.add(b2 = new WebMarkupContainer("b2"));
+               WebMarkupContainer b12;
+               b1.add(b12 = new WebMarkupContainer("b12"));
+               WebMarkupContainer b121;
+               b12.add(b121 = new WebMarkupContainer("b121"));
+
+               // Filter leaf components only
+               int count = 0;
+               String buf = "";
+               ComponentHierarchyIterator iter = new 
ComponentHierarchyIterator(page);
+               iter.setChildFirst(true);
+               while (iter.hasNext())
+               {
+                       Component component = iter.next();
+                       count += 1;
+                       buf += component.getId();
+               }
+
+               assertEquals(6, count);
+               assertEquals("ab121b12b1b2b", buf);
+       }
+
+       /** */
        public static class MyPage extends WebPage
        {
                private static final long serialVersionUID = 1L;


Reply via email to