Example usage for org.apache.wicket Component visitParents

List of usage examples for org.apache.wicket Component visitParents

Introduction

In this page you can find the example usage for org.apache.wicket Component visitParents.

Prototype

public final <R, C extends MarkupContainer> R visitParents(final Class<C> parentClass,
        final IVisitor<C, R> visitor) 

Source Link

Document

Traverses all parent components of the given class in this parentClass, calling the visitor's visit method at each one.

Usage

From source file:com.doculibre.constellio.wicket.utils.WicketResourceUtils.java

License:Open Source License

public static Component findOutputMarkupIdParent(Component child) {
    Component matchingParent;//from  w ww.  j  av  a 2 s  .  com
    Component firstParent = child.getParent();
    if (firstParent != null) {
        if (firstParent.getOutputMarkupId()) {
            matchingParent = firstParent;
        } else {
            // Starts with current object despite what method name lets you think...
            matchingParent = (Component) firstParent.visitParents(Component.class, new IVisitor() {
                @Override
                public Object component(Component component) {
                    if (component.getOutputMarkupId()) {
                        return component;
                    } else {
                        return CONTINUE_TRAVERSAL;
                    }
                }
            });
        }
    } else {
        matchingParent = null;
    }
    return matchingParent;
}

From source file:org.apache.isis.viewer.wicket.ui.panels.FormExecutorDefault.java

License:Apache License

private void addComponentsToRedraw(final AjaxRequestTarget target) {
    final List<Component> componentsToRedraw = Lists.newArrayList();
    final List<Component> componentsNotToRedraw = Lists.newArrayList();

    final Page page = target.getPage();
    page.visitChildren(new IVisitor<Component, Object>() {
        @Override//from w w  w  .  j  ava  2s  .c o m
        public void component(final Component component, final IVisit<Object> visit) {
            if (component.getOutputMarkupId() && !(component instanceof Page)) {
                List<Component> listToAddTo = shouldRedraw(component) ? componentsToRedraw
                        : componentsNotToRedraw;
                listToAddTo.add(component);
            }
        }

        private boolean shouldRedraw(final Component component) {

            // hmm... this doesn't work, because I think that the components
            // get removed after they've been added to target.
            // so.. still getting WARN log messages from XmlPartialPageUpdate

            //                final Page page = component.findParent(Page.class);
            //                if(page == null) {
            //                    // as per logic in XmlPartialPageUpdate, this has already been
            //                    // removed from page so don't attempt to redraw it
            //                    return false;
            //                }

            final Object defaultModel = component.getDefaultModel();
            if (!(defaultModel instanceof ScalarModel)) {
                return true;
            }
            final ScalarModel scalarModel = (ScalarModel) defaultModel;
            final UnchangingFacet unchangingFacet = scalarModel.getFacet(UnchangingFacet.class);
            return unchangingFacet == null || !unchangingFacet.value();
        }
    });

    for (Component componentNotToRedraw : componentsNotToRedraw) {
        MarkupContainer parent = componentNotToRedraw.getParent();
        while (parent != null) {
            parent = parent.getParent();
        }

        componentNotToRedraw.visitParents(MarkupContainer.class, new IVisitor<MarkupContainer, Object>() {
            @Override
            public void component(final MarkupContainer parent, final IVisit<Object> visit) {
                componentsToRedraw.remove(parent); // no-op if not in that list
            }
        });
        if (componentNotToRedraw instanceof MarkupContainer) {
            final MarkupContainer containerNotToRedraw = (MarkupContainer) componentNotToRedraw;
            containerNotToRedraw.visitChildren(new IVisitor<Component, Object>() {
                @Override
                public void component(final Component parent, final IVisit<Object> visit) {
                    componentsToRedraw.remove(parent); // no-op if not in that list
                }
            });
        }
    }

    if (LOG.isDebugEnabled()) {
        debug(componentsToRedraw, componentsNotToRedraw);
    }

    for (Component component : componentsToRedraw) {
        target.add(component);
    }
}

From source file:org.dcm4chee.web.common.secure.ExtendedSwarmStrategy.java

License:LGPL

private MarkupContainer findLowestSecureContainer(Component component) {

    final MarkupContainer[] lowestSecureParent = new MarkupContainer[1];

    component.visitParents(MarkupContainer.class, new IVisitor<Component>() {
        public Object component(Component component) {
            if (component instanceof ISecureComponent) {
                lowestSecureParent[0] = (MarkupContainer) component;
                return IVisitor.STOP_TRAVERSAL;
            }//from w  w w .jav a 2s .  c  o m
            return null;
        }
    });

    if (null == lowestSecureParent[0]) {
        try {
            lowestSecureParent[0] = component.getPage();
        } catch (IllegalStateException e) {
            throw new SecurityException(
                    this.getClass() + ": Unable to create alias for component: " + component, e);
        }
    }

    MarkupContainer markupContainer = lowestSecureParent[0];
    return markupContainer;
}

From source file:org.dcm4chee.wizard.common.login.secure.ExtendedSwarmStrategy.java

License:LGPL

private MarkupContainer findLowestSecureContainer(Component component) {

    final MarkupContainer[] lowestSecureParent = new MarkupContainer[1];

    component.visitParents(MarkupContainer.class, new IVisitor<MarkupContainer, Void>() {
        public void component(MarkupContainer component, IVisit<Void> visit) {
            if (component instanceof ISecureComponent) {
                lowestSecureParent[0] = component;
                visit.stop();//  www  .  ja v  a  2 s.  co  m
            }
        }
    });

    if (null == lowestSecureParent[0]) {
        try {
            lowestSecureParent[0] = component.getPage();
        } catch (IllegalStateException e) {
            throw new SecurityException(
                    this.getClass() + ": Unable to create alias for component: " + component, e);
        }
    }

    MarkupContainer markupContainer = lowestSecureParent[0];
    return markupContainer;
}