You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Martin Grigorov <mg...@apache.org> on 2014/02/10 15:21:29 UTC

Re: git commit: WICKET-3335 Attempt to add support for Border component

On Mon, Feb 10, 2014 at 3:18 PM, <mg...@apache.org> wrote:

> Updated Branches:
>   refs/heads/sandbox/component-queueing-2 ec85560ea -> aa04c4312
>
>
> WICKET-3335 Attempt to add support for Border component
>
>
> Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
> Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/aa04c431
> Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/aa04c431
> Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/aa04c431
>
> Branch: refs/heads/sandbox/component-queueing-2
> Commit: aa04c4312dc0b1bdcb7434cd1961d1fe26044552
> Parents: ec85560
> Author: Martin Tzvetanov Grigorov <mg...@apache.org>
> Authored: Mon Feb 10 16:16:59 2014 +0200
> Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
> Committed: Mon Feb 10 16:16:59 2014 +0200
>
> ----------------------------------------------------------------------
>  .../java/org/apache/wicket/MarkupContainer.java | 42 +++++++++++---
>  .../wicket/markup/html/border/Border.java       | 23 +++++++-
>  .../wicket/queueing/ComponentQueueingTest.java  | 59 +++++++++++++++++++-
>  3 files changed, 112 insertions(+), 12 deletions(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/aa04c431/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> ----------------------------------------------------------------------
> diff --git
> a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> index ffd5488..b34a6fc 100644
> --- a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> +++ b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java
> @@ -2018,7 +2018,7 @@ public abstract class MarkupContainer extends
> Component implements Iterable<Comp
>
>         private transient ComponentQueue queue;
>
> -       public void queue(Component... components)
> +       public MarkupContainer queue(Component... components)
>         {
>                 if (queue == null)
>                 {
> @@ -2049,6 +2049,8 @@ public abstract class MarkupContainer extends
> Component implements Iterable<Comp
>                         // TODO WICKET-3335: should we check if
> (!region.dequeueing) ?
>                         region.dequeue();
>                 }
> +
> +               return this;
>         }
>
>         ComponentQueue getQueue()
> @@ -2107,9 +2109,9 @@ public abstract class MarkupContainer extends
> Component implements Iterable<Comp
>                         return;
>                 }
>                 // use arraydeque?
> -               ArrayListStack<ComponentTag> tags = new
> ArrayListStack<ComponentTag>();
> -               ArrayListStack<MarkupContainer> containers = new
> ArrayListStack<MarkupContainer>();
> -               ArrayListStack<Repeater> repeaters = new
> ArrayListStack<Repeater>();
> +               ArrayListStack<ComponentTag> tags = new ArrayListStack<>();
> +               ArrayListStack<MarkupContainer> containers = new
> ArrayListStack<>();
> +               ArrayListStack<Repeater> repeaters = new
> ArrayListStack<>();
>
>                 containers.push(this);
>
> @@ -2182,7 +2184,16 @@ public abstract class MarkupContainer extends
> Component implements Iterable<Comp
>
>                                         if (child != null)
>                                         {
> -
> containers.peek().add(child);
> +                                               MarkupContainer
> parentContainer = containers.peek();
> +//                                             boolean isInBorder =
> isInBorder(tags, parentContainer);
>

Support for Border is almost here but there is no easy way to find out
whether to use border.add() or border.addToBorder() here.
The 'tags' variable doesn't have the parents' tags.

My idea is to check that the containerPeek (the parent) is Border and the
tagsPeek is <wicket:border>. The latter fails me ATM.
I'll be able to debug it more later today or tomorrow.


> +                                               if (parentContainer
> instanceof Border) //(isInBorder)
> +                                               {
> +                                                       ((Border)
> parentContainer).addToBorder(child);
> +                                               }
> +                                               else
> +                                               {
> +
> parentContainer.add(child);
> +                                               }
>
>                                                 if (child instanceof
> IQueueRegion)
>                                                 {
> @@ -2200,7 +2211,7 @@ public abstract class MarkupContainer extends
> Component implements Iterable<Comp
>                                                 for (i = i + 1; i <
> markup.size(); i++)
>                                                 {
>                                                         MarkupElement e =
> markup.get(i);
> -                                                       if (e instanceof
> ComponentTag && ((ComponentTag)e).closes(tag))
> +                                                       if (e instanceof
> ComponentTag && e.closes(tag))
>                                                         {
>                                                                 break;
>                                                         }
> @@ -2240,8 +2251,7 @@ public abstract class MarkupContainer extends
> Component implements Iterable<Comp
>
> for (i = i + 1; i < markup.size(); i++)
>                                                                         {
>
>       MarkupElement e = markup.get(i);
> -
>       if (e instanceof ComponentTag
> -
>               && ((ComponentTag)e).closes(tag))
> +
>       if (e instanceof ComponentTag && e.closes(tag))
>
>       {
>
>               break;
>
>       }
> @@ -2257,7 +2267,7 @@ public abstract class MarkupContainer extends
> Component implements Iterable<Comp
>                                                         for (i = i + 1; i
> < markup.size(); i++)
>                                                         {
>
> MarkupElement e = markup.get(i);
> -                                                               if (e
> instanceof ComponentTag && ((ComponentTag)e).closes(tag))
> +                                                               if (e
> instanceof ComponentTag && e.closes(tag))
>                                                                 {
>
> break;
>                                                                 }
> @@ -2275,4 +2285,18 @@ public abstract class MarkupContainer extends
> Component implements Iterable<Comp
>
>
>         }
> +
> +       private boolean isInBorder(ArrayListStack<ComponentTag> tags,
> MarkupContainer parentContainer)
> +       {
> +               boolean result = false;
> +               if (parentContainer instanceof Border && tags.empty() ==
> false)
> +               {
> +                       ComponentTag parentsTag = tags.peek();
> +                       if (parentsTag instanceof WicketTag &&
> ((WicketTag)parentsTag).isBorderTag())
> +                       {
> +                               result = true;
> +                       }
> +               }
> +               return result;
> +       }
>  }
>
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/aa04c431/wicket-core/src/main/java/org/apache/wicket/markup/html/border/Border.java
> ----------------------------------------------------------------------
> diff --git
> a/wicket-core/src/main/java/org/apache/wicket/markup/html/border/Border.java
> b/wicket-core/src/main/java/org/apache/wicket/markup/html/border/Border.java
> index 705c124..3c5b0d7 100644
> ---
> a/wicket-core/src/main/java/org/apache/wicket/markup/html/border/Border.java
> +++
> b/wicket-core/src/main/java/org/apache/wicket/markup/html/border/Border.java
> @@ -17,6 +17,7 @@
>  package org.apache.wicket.markup.html.border;
>
>  import org.apache.wicket.Component;
> +import org.apache.wicket.IQueueRegion;
>  import org.apache.wicket.MarkupContainer;
>  import org.apache.wicket.markup.ComponentTag;
>  import org.apache.wicket.markup.IMarkupFragment;
> @@ -132,7 +133,7 @@ import org.apache.wicket.util.lang.Args;
>   * @author Jonathan Locke
>   * @author Juergen Donnerstag
>   */
> -public abstract class Border extends WebMarkupContainer implements
> IComponentResolver
> +public abstract class Border extends WebMarkupContainer implements
> IComponentResolver, IQueueRegion
>  {
>         private static final long serialVersionUID = 1L;
>
> @@ -212,6 +213,13 @@ public abstract class Border extends
> WebMarkupContainer implements IComponentRes
>         }
>
>         @Override
> +       public Border queue(Component... components)
> +       {
> +               getBodyContainer().queue(components);
> +               return this;
> +       }
> +
> +       @Override
>         public Border remove(final Component component)
>         {
>                 if (component == body)
> @@ -263,6 +271,19 @@ public abstract class Border extends
> WebMarkupContainer implements IComponentRes
>         }
>
>         /**
> +        * Queues children components to the Border itself
> +        *
> +        * @param children
> +        *            the children components to queue
> +        * @return this
> +        */
> +       public Border queueToBorder(final Component... children)
> +       {
> +               super.queue(children);
> +               return this;
> +       }
> +
> +       /**
>          * Removes child from the Border itself
>          *
>          * @param child
>
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/aa04c431/wicket-core/src/test/java/org/apache/wicket/queueing/ComponentQueueingTest.java
> ----------------------------------------------------------------------
> diff --git
> a/wicket-core/src/test/java/org/apache/wicket/queueing/ComponentQueueingTest.java
> b/wicket-core/src/test/java/org/apache/wicket/queueing/ComponentQueueingTest.java
> index 98d15be..c96ea7b 100644
> ---
> a/wicket-core/src/test/java/org/apache/wicket/queueing/ComponentQueueingTest.java
> +++
> b/wicket-core/src/test/java/org/apache/wicket/queueing/ComponentQueueingTest.java
> @@ -28,6 +28,7 @@ import org.apache.wicket.WicketTestCase;
>  import org.apache.wicket.markup.IMarkupResourceStreamProvider;
>  import org.apache.wicket.markup.html.WebMarkupContainer;
>  import org.apache.wicket.markup.html.WebPage;
> +import org.apache.wicket.markup.html.border.Border;
>  import org.apache.wicket.markup.html.internal.Enclosure;
>  import org.apache.wicket.markup.html.link.Link;
>  import org.apache.wicket.markup.html.list.ListItem;
> @@ -37,6 +38,7 @@ import org.apache.wicket.model.Model;
>  import org.apache.wicket.util.resource.IResourceStream;
>  import org.apache.wicket.util.resource.StringResourceStream;
>  import org.junit.Assert;
> +import org.junit.Ignore;
>  import org.junit.Test;
>
>  public class ComponentQueueingTest extends WicketTestCase
> @@ -255,6 +257,7 @@ public class ComponentQueueingTest extends
> WicketTestCase
>                 tester.startPage(p);
>
>                 assertThat(p, hasPath(new Path(q, r)));
> +               tester.assertContains("<meta/>"); // contributed by
> <wicket:head>
>         }
>
>         @Test
> @@ -544,6 +547,26 @@ public class ComponentQueueingTest extends
> WicketTestCase
>                 assertEquals("<div id=\"wicket__InlineEnclosure_01\"
> style=\"display:none\"></div>", tester.getLastResponseAsString());
>         }
>
> +       @Ignore
> +       @Test
> +       public void dequeueWithBorder1()
> +       {
> +               MarkupContainer a = new A(), b = new B(), r = new R(), s =
> new S();
> +
> +               TestBorder border = new TestBorder("border");
> +               border.setBorderMarkup("<wicket:border><p wicket:id='r'><p
> wicket:id='s'>" +
> +                               "<wicket:body/></p></p></wicket:border>");
> +               border.queueToBorder(r, s);
> +
> +               TestPage p = new TestPage();
> +               p.setPageMarkup("<p wicket:id='a'><p wicket:id='border'><p
> wicket:id='b'></p></p></p>");
> +
> +               p.queue(a, border, b);
> +
> +               tester.startPage(p);
> +
> +               assertThat(p, hasPath(new Path(a, border, r, s)));
> +       }
>
>         private static class A extends WebMarkupContainer
>         {
> @@ -624,7 +647,7 @@ public class ComponentQueueingTest extends
> WicketTestCase
>                         ArrayList<Integer> values = new
> ArrayList<Integer>();
>                         for (int i = 0; i < size; i++)
>                                 values.add(i);
> -                       setModel(new Model<ArrayList<Integer>>(values));
> +                       setModel(new Model<>(values));
>                 }
>         }
>
> @@ -684,7 +707,6 @@ public class ComponentQueueingTest extends
> WicketTestCase
>
>         private static class TestPanel extends Panel implements
> IMarkupResourceStreamProvider
>         {
> -
>                 private String markup;
>
>                 public TestPanel(String id)
> @@ -715,4 +737,37 @@ public class ComponentQueueingTest extends
> WicketTestCase
>                         return new StringResourceStream(getPanelMarkup());
>                 }
>         }
> +
> +       private static class TestBorder extends Border implements
> IMarkupResourceStreamProvider
> +       {
> +               private String markup;
> +
> +               public TestBorder(String id)
> +               {
> +                       super(id);
> +               }
> +
> +               public TestBorder(String id, String markup)
> +               {
> +                       super(id);
> +                       this.markup = markup;
> +               }
> +
> +               protected void setBorderMarkup(String markup)
> +               {
> +                       this.markup = markup;
> +               }
> +
> +               protected String getBorderMarkup()
> +               {
> +                       return markup;
> +               }
> +
> +               @Override
> +               public IResourceStream
> getMarkupResourceStream(MarkupContainer container,
> +                                                              Class<?>
> containerClass)
> +               {
> +                       return new StringResourceStream(getBorderMarkup());
> +               }
> +       }
>  }
>
>