Search in sources :

Example 1 with IComponentResolver

use of org.apache.wicket.markup.resolver.IComponentResolver in project wicket by apache.

the class Enclosure method getChildComponent.

/**
 * Resolves the child component which is the controller of this Enclosure
 *
 * @param markupStream
 *            the markup stream of this Enclosure
 * @param enclosureParent
 *            the non-auto parent component of this Enclosure
 * @return The component associated with the {@linkplain #childId}
 */
private Component getChildComponent(final MarkupStream markupStream, MarkupContainer enclosureParent) {
    String fullChildId = getChildId();
    Component controller = enclosureParent.get(fullChildId);
    if (controller == null) {
        int orgIndex = markupStream.getCurrentIndex();
        try {
            while (markupStream.isCurrentIndexInsideTheStream()) {
                markupStream.next();
                if (markupStream.skipUntil(ComponentTag.class)) {
                    ComponentTag tag = markupStream.getTag();
                    if ((tag != null) && (tag.isOpen() || tag.isOpenClose())) {
                        String tagId = tag.getId();
                        if (fullChildId.equals(tagId)) {
                            ComponentTag fullComponentTag = new ComponentTag(tag);
                            fullComponentTag.setId(childId.toString());
                            controller = ComponentResolvers.resolve(enclosureParent, markupStream, fullComponentTag, new ResolverFilter() {

                                @Override
                                public boolean ignoreResolver(final IComponentResolver resolver) {
                                    return resolver instanceof EnclosureHandler;
                                }
                            });
                            break;
                        } else if (fullChildId.startsWith(tagId + PATH_SEPARATOR)) {
                            fullChildId = Strings.afterFirst(fullChildId, PATH_SEPARATOR);
                        }
                    }
                }
            }
        } finally {
            markupStream.setCurrentIndex(orgIndex);
        }
    }
    checkChildComponent(controller);
    return controller;
}
Also used : EnclosureHandler(org.apache.wicket.markup.parser.filter.EnclosureHandler) ComponentTag(org.apache.wicket.markup.ComponentTag) ResolverFilter(org.apache.wicket.markup.resolver.ComponentResolvers.ResolverFilter) Component(org.apache.wicket.Component) IComponentResolver(org.apache.wicket.markup.resolver.IComponentResolver)

Example 2 with IComponentResolver

use of org.apache.wicket.markup.resolver.IComponentResolver in project wicket by apache.

the class AbstractMarkupSourcingStrategy method searchMarkupInTransparentResolvers.

/**
 * If the child has not been directly added to the container, but via a
 * TransparentWebMarkupContainer, then we are in trouble. In general Wicket iterates over the
 * markup elements and searches for associated components, not the other way around. Because of
 * TransparentWebMarkupContainer (or more generally resolvers), there is no "synchronous" search
 * possible.
 *
 * @param container
 *            the parent container.
 * @param
 * 		  containerMarkup
 * 			  the markup of the parent container.
 * @param child
 *            The component to find the markup for.
 * @return the markup fragment for the child, or {@code null}.
 */
protected IMarkupFragment searchMarkupInTransparentResolvers(MarkupContainer container, IMarkupFragment containerMarkup, Component child) {
    IMarkupFragment childMarkupFound = null;
    Iterator<Component> childrenIterator = container.iterator();
    final List<MarkupContainer> componentResolvers = new ArrayList<>();
    // collect all "transparent" (i.e. component resolvers) children
    container.visitChildren(IComponentResolver.class, new IVisitor<MarkupContainer, Void>() {

        @Override
        public void component(MarkupContainer child, IVisit<Void> visit) {
            componentResolvers.add(child);
        }
    });
    while (childrenIterator.hasNext() && childMarkupFound == null) {
        Component sibling = childrenIterator.next();
        if (sibling == child || !sibling.isVisible() || !(sibling instanceof MarkupContainer)) {
            continue;
        }
        IMarkupFragment siblingMarkup = containerMarkup.find(sibling.getId());
        if (siblingMarkup != null) {
            if (sibling instanceof IComponentResolver) {
                childMarkupFound = searchInNestedTransparentResolvers(containerMarkup, child, componentResolvers);
            } else {
                childMarkupFound = searchMarkupInTransparentResolvers((MarkupContainer) sibling, siblingMarkup, child);
            }
        }
    }
    return childMarkupFound;
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) ArrayList(java.util.ArrayList) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment) Component(org.apache.wicket.Component) IComponentResolver(org.apache.wicket.markup.resolver.IComponentResolver)

Example 3 with IComponentResolver

use of org.apache.wicket.markup.resolver.IComponentResolver in project wicket by apache.

the class AbstractMarkupSourcingStrategy method searchInNestedTransparentResolvers.

/**
 * Search for the markup of a child that might be nested inside
 * transparent siblings. For example:
 *
 * <pre>
 * &lt;div wicket:id=&quot;outerTransparent&quot;&gt;
 *	&lt;div wicket:id=&quot;innerTransparent&quot;&gt;
 *	 &lt;span wicket:id=&quot;childComponent&quot;&gt;&lt;/span&gt;
 *	&lt;/div&gt;
 * &lt;/div&gt;
 * </pre>
 *
 * @param
 * 		  containerMarkup
 * 			  the markup of the parent container.
 * @param child
 *            The component to find the markup for.
 * @param componentResolvers
 * 			  the transparent siblings
 *
 * @return the markup fragment for the child, or {@code null}.
 */
protected IMarkupFragment searchInNestedTransparentResolvers(IMarkupFragment containerMarkup, Component child, List<MarkupContainer> componentResolvers) {
    IMarkupFragment childMarkupFound = null;
    for (MarkupContainer componentResolver : componentResolvers) {
        IMarkupFragment resolverMarkup = containerMarkup.find(componentResolver.getId());
        IMarkupFragment childMarkup = resolverMarkup != null ? resolverMarkup.find(child.getId()) : null;
        if (childMarkup != null) {
            IComponentResolver resolverContainer = (IComponentResolver) componentResolver;
            MarkupStream stream = new MarkupStream(childMarkup);
            ComponentTag tag = stream.getTag();
            Component resolvedComponent = componentResolver.get(tag.getId());
            if (resolvedComponent == null) {
                resolvedComponent = resolverContainer.resolve(componentResolver, stream, tag);
            }
            if (child == resolvedComponent) {
                childMarkupFound = childMarkup;
            }
        } else if (resolverMarkup != null) {
            List<MarkupContainer> otherResolvers = new ArrayList<>(componentResolvers);
            otherResolvers.remove(componentResolver);
            childMarkupFound = searchInNestedTransparentResolvers(resolverMarkup, child, otherResolvers);
        }
        if (childMarkupFound != null) {
            break;
        }
    }
    return childMarkupFound;
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) ComponentTag(org.apache.wicket.markup.ComponentTag) MarkupStream(org.apache.wicket.markup.MarkupStream) ArrayList(java.util.ArrayList) List(java.util.List) IMarkupFragment(org.apache.wicket.markup.IMarkupFragment) Component(org.apache.wicket.Component) IComponentResolver(org.apache.wicket.markup.resolver.IComponentResolver)

Aggregations

Component (org.apache.wicket.Component)3 IComponentResolver (org.apache.wicket.markup.resolver.IComponentResolver)3 ArrayList (java.util.ArrayList)2 MarkupContainer (org.apache.wicket.MarkupContainer)2 ComponentTag (org.apache.wicket.markup.ComponentTag)2 IMarkupFragment (org.apache.wicket.markup.IMarkupFragment)2 List (java.util.List)1 MarkupStream (org.apache.wicket.markup.MarkupStream)1 EnclosureHandler (org.apache.wicket.markup.parser.filter.EnclosureHandler)1 ResolverFilter (org.apache.wicket.markup.resolver.ComponentResolvers.ResolverFilter)1