Example usage for org.apache.wicket Component getParent

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

Introduction

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

Prototype

@Override
public final MarkupContainer getParent() 

Source Link

Document

Gets any parent container, or null if there is none.

Usage

From source file:de.alpharogroup.wicket.base.util.ComponentFinder.java

License:Apache License

/**
 * Finds the first parent of the given childComponent from the given parentClass.
 *
 * @param childComponent/*from  w  w  w.j a v  a2 s.c  o m*/
 *            the child component
 * @param parentClass
 *            the parent class
 * @return the component
 */
public static Component findParentByClassname(final Component childComponent,
        final Class<? extends Component> parentClass) {
    Component parent = childComponent.getParent();
    while (parent != null) {
        if (ClassExtensions.equalsByClassName(parentClass, parent.getClass())) {
            break;
        }
        parent = parent.getParent();
    }
    return parent;
}

From source file:de.micromata.genome.junittools.wicket.TpsbWicketMatchers.java

License:Apache License

public static Matcher<Component> matchParent(Matcher<Component> matcher) {
    return new AbstractSelectorMatcher(matcher) {
        @Override/*from  ww  w .  j av a 2s. c o  m*/
        public Component selectMatched(Component found) {
            return found.getParent();
        }

        @Override
        public String toString() {
            return "ParentOf(" + super.toString() + ")";
        }

    };
}

From source file:fiftyfive.wicket.css.IterationCssBehavior.java

License:Apache License

/**
 * Assume that the component has an immediate parent of {@link ListView}, {@link Loop}, or
 * {@link RepeatingView} and use what we know about those implementations to infer the
 * size of the list that is being iterated. Note that in the case of pagination, this is the
 * size of the visible items (i.e the current page), not the total size that includes other
 * pages.//from  ww  w  .  j a v  a  2 s.c o  m
 * 
 * @throws UnsupportedOperationException if the parent component is not one of the three
 *                                       supported types
 */
protected int getSize(Component component) {
    MarkupContainer parent = component.getParent();

    if (parent instanceof ListView) {
        return ((ListView) parent).getViewSize();
    }
    if (parent instanceof Loop) {
        return ((Loop) parent).getIterations();
    }
    if (parent instanceof RepeatingView) {
        // TODO: more efficent way?
        int size = 0;
        Iterator iter = parent.iterator();
        while (iter.hasNext()) {
            iter.next();
            size++;
        }
        return size;
    }

    throw new IllegalStateException(String.format(
            "Don't know how to find the size of the repeater that contains component " + "%s (%s). "
                    + "Only list.ListItem, list.LoopItem and repeater.Item are supported. "
                    + "Perhaps you attached IterationCssBehavior to the wrong component?",
            component.getPath(), component.getClass()));
}

From source file:net.databinder.components.hib.DataForm.java

License:Open Source License

/** 
 * @return the effective compound model for this form, which may be
 * attached to a parent component/* w  w w. j  ava  2  s.c  om*/
 */
protected CompoundPropertyModel getCompoundModel() {
    IModel model = getModel();
    Component cur = this;
    while (cur != null) {
        model = cur.getDefaultModel();
        if (model != null && model instanceof CompoundPropertyModel)
            return (CompoundPropertyModel) model;
        cur = cur.getParent();
    }
    throw new WicketRuntimeException("DataForm has no parent compound model");
}

From source file:net.rrm.ehour.ui.common.event.EventPublisher.java

License:Open Source License

private static void recursivePublishAjaxEvent(Component container, AjaxEvent event) {
    boolean proceed = true;

    if (container instanceof AjaxEventListener) {
        proceed = ((AjaxEventListener) container).ajaxEventReceived(event);
    }/*from w ww  .j av a 2 s  .c om*/

    if (proceed && !(container instanceof Page)) {
        MarkupContainer parent = container.getParent();

        if (parent == null) {
            parent = container.getPage();
        }

        recursivePublishAjaxEvent(parent, event);
    }
}

From source file:org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable.CollectionContentsAsAjaxTablePanel.java

License:Apache License

private BulkActionsProvider getBulkActionsProvider() {
    Component component = this;
    while (component != null) {
        if (component instanceof BulkActionsProvider) {
            return (BulkActionsProvider) component;
        }/*from  w ww .  j  a v  a2 s  .  com*/
        component = component.getParent();
    }
    return null;
}

From source file:org.apache.isis.viewer.wicket.ui.components.collectioncontents.selector.links.CollectionContentsLinksSelectorPanel.java

License:Apache License

/**
 * Iterates up the component hierarchy looking for a parent
 * {@link CollectionPanel}, and if so adds to ajax target so that it'll
 * be repainted.//ww  w  . ja v  a  2s . com
 * 
 * <p>
 * Yeah, agreed, it's a little bit hacky doing it this way, because it bakes
 * in knowledge that this component is created, somehow, by a parent {@link CollectionPanel}.
 * Perhaps it could be refactored to use a more general purpose observer pattern?
 */
protected void onSelect(AjaxRequestTarget target) {
    super.onSelect(target);
    Component component = this;
    while (component != null) {
        if (component instanceof CollectionPanel) {
            CollectionPanel collectionPanel = (CollectionPanel) component;
            final boolean expanded = collectionPanel.onSelect(target);
            if (additionalLinks != null) {
                applyCssVisibility(additionalLinks, expanded);
            }
            return;
        }
        component = component.getParent();
    }
}

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  ww .j a  va  2 s  .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.apache.isis.viewer.wicket.viewer.integration.wicket.LocalizerForIsis.java

License:Apache License

/**
 * Search up this component instance's hierarchy looking for containing page.
 *//*from  www .java2 s.  co m*/
private Component pageOf(final Component component) {
    if (component instanceof Page) {
        return component;
    }
    final MarkupContainer parent = component.getParent();
    if (parent != null) {
        return pageOf(parent);
    }
    return component;
}

From source file:org.apache.isis.viewer.wicket.viewer.integration.wicket.LocalizerForIsis.java

License:Apache License

/**
 * Search up this component instance's hierarchy, and use the first form or panel that is a parent
 * of this component./*  w w w  .ja va 2 s .co  m*/
 */
private Component parentFormOrPanelOf(final Component component) {
    if (component instanceof Form || component instanceof Panel) {
        return component;
    }
    final MarkupContainer parent = component.getParent();
    if (parent != null) {
        return parentFormOrPanelOf(parent);
    }
    return parent;
}