Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/renderStrategy/DeepChildFirstVisitor.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/renderStrategy/DeepChildFirstVisitor.java?rev=926476&r1=926475&r2=926476&view=diff ============================================================================== --- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/renderStrategy/DeepChildFirstVisitor.java (original) +++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/renderStrategy/DeepChildFirstVisitor.java Tue Mar 23 06:56:28 2010 @@ -1,174 +1,173 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.markup.renderStrategy; - -import org.apache.wicket.Component; -import org.apache.wicket.MarkupContainer; -import org.apache.wicket.Component.IVisitor; -import org.apache.wicket.util.lang.Checks; - -/** - * - * @author Juergen Donnerstag - */ -public abstract class DeepChildFirstVisitor implements IVisitor<Component> -{ - /** - * Construct. - */ - public DeepChildFirstVisitor() - { - } - - /** - * Render the child hierarchy headers. - * - * @param rootComponent - * @return The object return by component() - */ - public final Object visit(final Component rootComponent) - { - Checks.argumentNotNull(rootComponent, "rootComponent"); - - if (rootComponent instanceof MarkupContainer) - { - final Component[] lastComponent = new Component[1]; - Object rtn = ((MarkupContainer)rootComponent).visitChildren(new Component.IVisitor<Component>() - { - public Object component(Component component) - { - // skip invisible components - if (component.isVisibleInHierarchy()) - { - // In case it is a 'leaf' component, than ... - if (!(component instanceof MarkupContainer) || - ((MarkupContainer)component).size() == 0) - { - // Lets assume we rendered the 1st leaf already and we now reached - // the 2nd leaf. If the 2nd leave has the very same parent, than we - // don't do anything. If not, than we need to render the 1st component's - // parents until such a parent is equal to the 2nd component parent. - if (lastComponent[0] != null) - { - MarkupContainer parent = lastComponent[0].getParent(); - while ((parent != null) && (parent != rootComponent) && - isCommonParent(parent, lastComponent[0], component) == false) - { - // Render the container since all its children have been - // rendered by now - Object rtn = component(parent); - - // If visitor returns a non-null value, it halts the traversal - if ((rtn != IVisitor.CONTINUE_TRAVERSAL) && - (rtn != IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER)) - { - return rtn; - } - - parent = parent.getParent(); - } - } - - // The 'leafs' header - Object rtn = component(component); - - // If visitor returns a non-null value, it halts the traversal - if ((rtn != IVisitor.CONTINUE_TRAVERSAL) && - (rtn != IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER)) - { - return rtn; - } - - // Remember the current leaf, we need it for comparison later on - lastComponent[0] = component; - } - return CONTINUE_TRAVERSAL; - } - else - { - // Remember the current leaf, we need it for comparison later on - lastComponent[0] = component; - return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER; - } - } - - /** - * - * @param parent - * @param lastComponent - * @param currentComponent - * @return true, if parent is a common parent of both components - */ - private boolean isCommonParent(final MarkupContainer parent, - final Component lastComponent, final Component currentComponent) - { - MarkupContainer p = lastComponent.getParent(); - while ((p != null) && (p != rootComponent) && (p != parent)) - { - p = p.getParent(); - } - - if (p == parent) - { - p = currentComponent.getParent(); - while ((p != null) && (p != rootComponent) && (p != parent)) - { - p = p.getParent(); - } - - if (p == parent) - { - return true; - } - } - - return false; - } - }); - - // We still need to render the remaining containers - if (lastComponent[0] != null) - { - MarkupContainer parent = lastComponent[0].getParent(); - while ((parent != null) && (parent != rootComponent)) - { - // Render the container since all its children have been - // rendered by now - rtn = component(parent); - - // If visitor returns a non-null value, it halts the traversal - if ((rtn != IVisitor.CONTINUE_TRAVERSAL) && - (rtn != IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER)) - { - return rtn; - } - - parent = parent.getParent(); - } - } - - return rtn; - } - - return null; - } - - /** - * @see org.apache.wicket.Component.IVisitor#component(org.apache.wicket.Component) - */ - public abstract Object component(Component component); -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.markup.renderStrategy; + +import org.apache.wicket.Component; +import org.apache.wicket.MarkupContainer; +import org.apache.wicket.Component.IVisit; +import org.apache.wicket.Component.IVisitor; +import org.apache.wicket.Component.Visit; +import org.apache.wicket.util.lang.Checks; + +/** + * + * @author Juergen Donnerstag + */ +public abstract class DeepChildFirstVisitor implements IVisitor<Component, Component> +{ + /** + * Construct. + */ + public DeepChildFirstVisitor() + { + } + + /** + * Render the child hierarchy headers. + * + * @param rootComponent + * @return The object return by component() + */ + public final Object visit(final Component rootComponent) + { + Checks.argumentNotNull(rootComponent, "rootComponent"); + + if (rootComponent instanceof MarkupContainer) + { + final Visit<Component> visit = new Visit<Component>(); + final Component[] lastComponent = new Component[1]; + Object rtn = ((MarkupContainer)rootComponent).visitChildren(new Component.IVisitor<Component, Component>() + { + public void component(final Component component, final IVisit<Component> visit) + { + // skip invisible components + if (component.isVisibleInHierarchy()) + { + // In case it is a 'leaf' component, than ... + if (!(component instanceof MarkupContainer) || + ((MarkupContainer)component).size() == 0) + { + // Lets assume we rendered the 1st leaf already and we now reached + // the 2nd leaf. If the 2nd leave has the very same parent, than we + // don't do anything. If not, than we need to render the 1st component's + // parents until such a parent is equal to the 2nd component parent. + if (lastComponent[0] != null) + { + MarkupContainer parent = lastComponent[0].getParent(); + while ((parent != null) && (parent != rootComponent) && + isCommonParent(parent, lastComponent[0], component) == false) + { + // Render the container since all its children have been + // rendered by now + component(parent, visit); + + // If visitor returns a non-null value, it halts the traversal + if (((Visit)visit).isStopped()) + { + return; + } + + parent = parent.getParent(); + } + } + + // The 'leafs' header + component(component, visit); + + // If visitor returns a non-null value, it halts the traversal + if (((Visit)visit).isStopped()) + { + return; + } + + // Remember the current leaf, we need it for comparison later on + visit.stop(component); + } + } + else + { + // Remember the current leaf, we need it for comparison later on + lastComponent[0] = component; + visit.dontGoDeeper(); + } + } + + /** + * + * @param parent + * @param lastComponent + * @param currentComponent + * @return true, if parent is a common parent of both components + */ + private boolean isCommonParent(final MarkupContainer parent, + final Component lastComponent, final Component currentComponent) + { + MarkupContainer p = lastComponent.getParent(); + while ((p != null) && (p != rootComponent) && (p != parent)) + { + p = p.getParent(); + } + + if (p == parent) + { + p = currentComponent.getParent(); + while ((p != null) && (p != rootComponent) && (p != parent)) + { + p = p.getParent(); + } + + if (p == parent) + { + return true; + } + } + + return false; + } + }); + + // We still need to render the remaining containers + if (lastComponent[0] != null) + { + MarkupContainer parent = lastComponent[0].getParent(); + while ((parent != null) && (parent != rootComponent)) + { + // Render the container since all its children have been + // rendered by now + component(parent, visit); + + // If visitor returns a non-null value, it halts the traversal + if (visit.isStopped()) + { + return rtn; + } + + parent = parent.getParent(); + } + } + + return rtn; + } + + return null; + } + + /** + * @see org.apache.wicket.Component.IVisitor#component(org.apache.wicket.Component) + */ + public abstract void component(Component component, IVisit<Component> visit); +}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/renderStrategy/ParentFirstHeaderRenderStrategy.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/renderStrategy/ParentFirstHeaderRenderStrategy.java?rev=926476&r1=926475&r2=926476&view=diff ============================================================================== --- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/renderStrategy/ParentFirstHeaderRenderStrategy.java (original) +++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/renderStrategy/ParentFirstHeaderRenderStrategy.java Tue Mar 23 06:56:28 2010 @@ -1,79 +1,79 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.markup.renderStrategy; - -import org.apache.wicket.Component; -import org.apache.wicket.MarkupContainer; -import org.apache.wicket.markup.html.internal.HtmlHeaderContainer; -import org.apache.wicket.util.lang.Checks; - -/** - * This is Wicket's default header render strategy which uses - * {...@link MarkupContainer#visitChildren(org.apache.wicket.Component.IVisitor)} to traverse the - * hierarchy to render the children headers. - * - * Since child contributions are added to the markup after the parent contributions, children may - * replace / modify existing settings. - * - * Note that in order to mix different render strategies, a "stop traversal" mechanism has been - * implemented. It allows you to use strategy A for Wicket core components and strategy B for your - * own. - * - * @author Juergen Donnerstag - */ -public class ParentFirstHeaderRenderStrategy extends AbstractHeaderRenderStrategy -{ - /** - * Construct. - */ - public ParentFirstHeaderRenderStrategy() - { - } - - /** - * Render the child hierarchy headers. - * - * @param headerContainer - * @param rootComponent - */ - @Override - protected void renderChildHeaders(final HtmlHeaderContainer headerContainer, - final Component rootComponent) - { - Checks.argumentNotNull(headerContainer, "headerContainer"); - Checks.argumentNotNull(rootComponent, "rootComponent"); - - if (rootComponent instanceof MarkupContainer) - { - ((MarkupContainer)rootComponent).visitChildren(new Component.IVisitor<Component>() - { - public Object component(Component component) - { - if (component.isVisibleInHierarchy()) - { - component.renderHead(headerContainer); - return CONTINUE_TRAVERSAL; - } - else - { - return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER; - } - } - }); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.markup.renderStrategy; + +import org.apache.wicket.Component; +import org.apache.wicket.MarkupContainer; +import org.apache.wicket.Component.IVisit; +import org.apache.wicket.markup.html.internal.HtmlHeaderContainer; +import org.apache.wicket.util.lang.Checks; + +/** + * This is Wicket's default header render strategy which uses + * {...@link MarkupContainer#visitChildren(org.apache.wicket.Component.IVisitor)} to traverse the + * hierarchy to render the children headers. + * + * Since child contributions are added to the markup after the parent contributions, children may + * replace / modify existing settings. + * + * Note that in order to mix different render strategies, a "stop traversal" mechanism has been + * implemented. It allows you to use strategy A for Wicket core components and strategy B for your + * own. + * + * @author Juergen Donnerstag + */ +public class ParentFirstHeaderRenderStrategy extends AbstractHeaderRenderStrategy +{ + /** + * Construct. + */ + public ParentFirstHeaderRenderStrategy() + { + } + + /** + * Render the child hierarchy headers. + * + * @param headerContainer + * @param rootComponent + */ + @Override + protected void renderChildHeaders(final HtmlHeaderContainer headerContainer, + final Component rootComponent) + { + Checks.argumentNotNull(headerContainer, "headerContainer"); + Checks.argumentNotNull(rootComponent, "rootComponent"); + + if (rootComponent instanceof MarkupContainer) + { + ((MarkupContainer)rootComponent).visitChildren(new Component.IVisitor<Component, Void>() + { + public void component(final Component component, final IVisit<Void> visit) + { + if (component.isVisibleInHierarchy()) + { + component.renderHead(headerContainer); + } + else + { + visit.dontGoDeeper(); + } + } + }); + } + } +} Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java?rev=926476&r1=926475&r2=926476&view=diff ============================================================================== --- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java (original) +++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java Tue Mar 23 06:56:28 2010 @@ -45,6 +45,7 @@ import org.apache.wicket.RequestListener import org.apache.wicket.Session; import org.apache.wicket.ThreadContext; import org.apache.wicket.WicketRuntimeException; +import org.apache.wicket.Component.IVisit; import org.apache.wicket.Component.IVisitor; import org.apache.wicket.ajax.AbstractAjaxTimerBehavior; import org.apache.wicket.ajax.AjaxRequestTarget; @@ -1462,9 +1463,9 @@ public class BaseWicketTester */ public void executeAllTimerBehaviors(MarkupContainer container) { - container.visitChildren(MarkupContainer.class, new IVisitor<MarkupContainer>() + container.visitChildren(MarkupContainer.class, new IVisitor<MarkupContainer, Void>() { - public Object component(MarkupContainer component) + public void component(final MarkupContainer component, final IVisit<Void> visit) { // get the AbstractAjaxBehaviour which is responsible for // getting the contents of the lazy panel @@ -1483,7 +1484,6 @@ public class BaseWicketTester } } } - return CONTINUE_TRAVERSAL; } }); } Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java?rev=926476&r1=926475&r2=926476&view=diff ============================================================================== --- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java (original) +++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java Tue Mar 23 06:56:28 2010 @@ -27,6 +27,7 @@ import java.util.List; import org.apache.wicket.Component; import org.apache.wicket.WicketRuntimeException; +import org.apache.wicket.Component.IVisit; import org.apache.wicket.Component.IVisitor; import org.apache.wicket.markup.html.form.AbstractTextComponent; import org.apache.wicket.markup.html.form.Check; @@ -66,7 +67,7 @@ public class FormTester /** * TODO need Javadoc from author. */ - private final class SearchOptionByIndexVisitor implements IVisitor<Component> + private final class SearchOptionByIndexVisitor implements IVisitor<Component, Component> { int count = 0; @@ -81,16 +82,15 @@ public class FormTester /** * @see org.apache.wicket.Component.IVisitor#component(org.apache.wicket.Component) */ - public Object component(Component component) + public void component(final Component component, final IVisit<Component> visit) { if (count == index) { - return component; + visit.stop(component); } else { count++; - return CONTINUE_TRAVERSAL; } } } @@ -373,11 +373,12 @@ public class FormTester tester = wicketTester; // fill blank String for Text Component. - workingForm.visitFormComponents(new FormComponent.AbstractVisitor() + workingForm.visitFormComponents(new FormComponent.AbstractVisitor<Void>() { @SuppressWarnings("unchecked") @Override - public void onFormComponent(final FormComponent<?> formComponent) + public void onFormComponent(final FormComponent<?> formComponent, + IVisit<Void> visit) { // do nothing for invisible component if (!formComponent.isVisibleInHierarchy()) @@ -418,16 +419,16 @@ public class FormTester else if (formComponent instanceof CheckGroup) { final Collection<?> checkGroupValues = (Collection<?>)formComponent.getDefaultModelObject(); - formComponent.visitChildren(Check.class, new IVisitor<Component>() + formComponent.visitChildren(Check.class, new IVisitor<Component, Void>() { - public Object component(Component component) + public void component(final Component component, + final IVisit<Void> visit) { if (checkGroupValues.contains(component.getDefaultModelObject())) { addFormComponentValue(formComponent, ((Check<?>)component).getValue()); } - return CONTINUE_TRAVERSAL; } }); } @@ -439,17 +440,21 @@ public class FormTester final Object value = formComponent.getDefaultModelObject(); if (value != null) { - formComponent.visitChildren(Radio.class, new IVisitor<Component>() + formComponent.visitChildren(Radio.class, new IVisitor<Component, Void>() { - public Object component(Component component) + public void component(final Component component, + final IVisit<Void> visit) { if (value.equals(component.getDefaultModelObject())) { addFormComponentValue(formComponent, ((Radio<?>)component).getValue()); - return STOP_TRAVERSAL; + visit.stop(); + } + else + { + visit.dontGoDeeper(); } - return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER; } }); } Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/WicketTesterHelper.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/WicketTesterHelper.java?rev=926476&r1=926475&r2=926476&view=diff ============================================================================== --- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/WicketTesterHelper.java (original) +++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/WicketTesterHelper.java Tue Mar 23 06:56:28 2010 @@ -26,6 +26,7 @@ import junit.framework.Assert; import org.apache.wicket.Component; import org.apache.wicket.IClusterable; import org.apache.wicket.Page; +import org.apache.wicket.Component.IVisit; import org.apache.wicket.Component.IVisitor; import org.apache.wicket.ajax.AjaxEventBehavior; import org.apache.wicket.behavior.IBehavior; @@ -73,9 +74,9 @@ public class WicketTesterHelper if (page != null) { - page.visitChildren(new IVisitor<Component>() + page.visitChildren(new IVisitor<Component, Void>() { - public Object component(final Component component) + public void component(final Component component, final IVisit<Void> visit) { final ComponentData object = new ComponentData(); @@ -101,7 +102,6 @@ public class WicketTesterHelper } data.add(object); - return IVisitor.CONTINUE_TRAVERSAL; } }); } Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/VisitorTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/VisitorTest.java?rev=926476&view=auto ============================================================================== --- wicket/trunk/wicket/src/test/java/org/apache/wicket/VisitorTest.java (added) +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/VisitorTest.java Tue Mar 23 06:56:28 2010 @@ -0,0 +1,156 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket; + +import junit.framework.Assert; + +import org.apache.wicket.Component.IVisit; +import org.apache.wicket.Component.IVisitor; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.form.FormComponent; + +/** + * <code> + * A + * +-B + * +-C + * | +-D + * | +-E + * | +-F + * +-G + * +-H + * </code> + * + * @author igor.vaynberg + */ +public class VisitorTest extends WicketTestCase +{ + + public void testContinueTraversal() + { + final StringBuilder path = new StringBuilder(); + + TestContainer container = new TestContainer(); + container.visitChildren(new IVisitor<Component, Void>() + { + public void component(Component component, IVisit<Void> visit) + { + path.append(component.getId()); + } + }); + + Assert.assertEquals("BCDEFGH", path.toString()); + } + + public void testContinuePostOrder() + { + final StringBuilder path = new StringBuilder(); + + TestContainer container = new TestContainer(); + FormComponent.visitComponentsPostOrder(container, new IVisitor<Component, Void>() + { + public void component(Component component, IVisit<Void> visit) + { + path.append(component.getId()); + } + }); + + Assert.assertEquals("BDFECHGA", path.toString()); + } + + public void testStop() + { + final StringBuilder path = new StringBuilder(); + + TestContainer container = new TestContainer(); + Object result = container.visitChildren(new IVisitor<Component, String>() + { + public void component(Component component, IVisit<String> visit) + { + path.append(component.getId()); + if ("D".equals(component.getId())) + { + visit.stop("RESULT"); + } + } + }); + Assert.assertEquals("BCD", path.toString()); + Assert.assertEquals("RESULT", result); + } + + public void testDoNotGoDeeper1() + { + final StringBuilder path = new StringBuilder(); + + TestContainer container = new TestContainer(); + container.visitChildren(new IVisitor<Component, Void>() + { + public void component(Component component, IVisit<Void> visit) + { + path.append(component.getId()); + if ("C".equals(component.getId())) + { + visit.dontGoDeeper(); + } + } + }); + Assert.assertEquals("BCGH", path.toString()); + } + + public void testDoNotGoDeeper2() + { + final StringBuilder path = new StringBuilder(); + + TestContainer container = new TestContainer(); + container.visitChildren(new IVisitor<Component, Void>() + { + public void component(Component component, IVisit<Void> visit) + { + path.append(component.getId()); + if ("E".equals(component.getId())) + { + visit.dontGoDeeper(); + } + } + }); + Assert.assertEquals("BCDEGH", path.toString()); + } + + + private static class TestContainer extends WebMarkupContainer + { + public TestContainer() + { + super("A"); + WebMarkupContainer b = new WebMarkupContainer("B"); + WebMarkupContainer c = new WebMarkupContainer("C"); + WebMarkupContainer d = new WebMarkupContainer("D"); + WebMarkupContainer e = new WebMarkupContainer("E"); + WebMarkupContainer f = new WebMarkupContainer("F"); + WebMarkupContainer g = new WebMarkupContainer("G"); + WebMarkupContainer h = new WebMarkupContainer("H"); + add(b); + add(c); + c.add(d); + c.add(e); + e.add(f); + add(g); + g.add(h); + } + + } +} Propchange: wicket/trunk/wicket/src/test/java/org/apache/wicket/VisitorTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormTest.java?rev=926476&r1=926475&r2=926476&view=diff ============================================================================== --- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormTest.java (original) +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/FormTest.java Tue Mar 23 06:56:28 2010 @@ -16,7 +16,6 @@ */ package org.apache.wicket.markup.html.form; -import org.apache.wicket.Component; import org.apache.wicket.WicketTestCase; @@ -51,32 +50,6 @@ public class FormTest extends WicketTest }; } - /** - * - */ - public void testShouldContinueTraversalIfListenerAllowsChildProcessing() - { - assertTraversalStatus(Component.IVisitor.CONTINUE_TRAVERSAL, true); - } - - /** - * - */ - public void testShouldContinueTraversalButDontGoDeeperIfListenerDisallowsChildProcessing() - { - assertTraversalStatus(Component.IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER, false); - } - - private void assertTraversalStatus(Object expected, final boolean processChildren) - { - assertEquals(expected, visitor.formComponent(new IFormVisitorParticipant() - { - public boolean processChildren() - { - return processChildren; - } - })); - } /** * @throws Exception Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/upload/FileUploadFieldTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/upload/FileUploadFieldTest.java?rev=926476&r1=926475&r2=926476&view=diff ============================================================================== --- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/upload/FileUploadFieldTest.java (original) +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/form/upload/FileUploadFieldTest.java Tue Mar 23 06:56:28 2010 @@ -27,6 +27,7 @@ import java.util.Set; import org.apache.wicket.Page; import org.apache.wicket.WicketTestCase; +import org.apache.wicket.Component.IVisit; import org.apache.wicket.Component.IVisitor; import org.apache.wicket.util.file.File; import org.apache.wicket.util.tester.FormTester; @@ -136,12 +137,12 @@ public class FileUploadFieldTest extends } }; final MockPageWithFormAndUploadField page = new MockPageWithFormAndUploadField(); - page.getForm().visitChildren(FileUploadField.class, new IVisitor<FileUploadField>() + page.getForm().visitChildren(FileUploadField.class, new IVisitor<FileUploadField, Void>() { - public Object component(FileUploadField uploadField) + public void component(FileUploadField uploadField, IVisit<Void> visit) { uploadField.add(testValidator); - return STOP_TRAVERSAL; + visit.stop(); } });