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:org.opensingular.form.wicket.util.WicketFormUtils.java

License:Apache License

public static Component resolveRefreshingComponent(Component component) {
    Component comp = component;
    while ((comp != null) && (comp.getParent() != null) && (!comp.getParent().isVisibleInHierarchy()))
        comp = comp.getParent();/*w w w. ja va  2  s  . c  om*/
    return comp;
}

From source file:org.opensingular.lib.wicket.util.util.WicketUtils.java

License:Apache License

/**
 * Retorna uma lista de parent containers, ordenados do filho para o pai.
 * @param child//  www . j  a  v  a 2s. c om
 * @param topParentInclusive parent mais alto na hierarquia a ser includo na lista
 * @return 
 */
public static List<MarkupContainer> listParents(Component child, MarkupContainer topParentInclusive) {
    List<MarkupContainer> list = new ArrayList<>();
    if (child != null) {
        MarkupContainer container = child.getParent();
        while (container != null) {
            list.add(container);
            if (container == topParentInclusive)
                break;
            container = container.getParent();
        }
        if (topParentInclusive != container) {
            throw new IllegalArgumentException("Top parent not found");
        }
    }
    return list;
}

From source file:org.opensingular.lib.wicket.util.util.WicketUtils.java

License:Apache License

/**
 * Adiciona os parent containers  lista, ordenados do filho para o pai.
 * @param child//w  w w .  jav a  2s. co  m
 * @param topParentInclusive parent mais alto na hierarquia a ser includo na lista
 */
public static void appendListOfParents(List<? super MarkupContainer> list, Component child,
        Component topParentInclusive) {
    if (child != null) {
        MarkupContainer container = child.getParent();
        while (container != null) {
            list.add(container);
            if (container == topParentInclusive)
                break;
            container = container.getParent();
        }
        if (topParentInclusive != container) {
            throw new IllegalArgumentException("Top parent not found");
        }
    }
}

From source file:org.patientview.radar.web.components.ComponentHelper.java

License:Open Source License

public static void updateComponentsIfParentIsVisible(AjaxRequestTarget target,
        List<? extends Component> componentsToUpdate) {
    for (Component component : componentsToUpdate) {
        if (component.getParent().isVisibleInHierarchy()) {
            target.add(component);/*from   ww w.  ja v  a  2  s .  c o  m*/
        }
    }
}

From source file:org.projectforge.web.wicket.ErrorHighlightBehavior.java

License:Open Source License

@Override
public void onComponentTag(final Component component, final ComponentTag tag) {
    if (component instanceof FormComponent<?>) {
        final FormComponent<?> fc = (FormComponent<?>) component;
        if (fc instanceof AbstractSelectPanel<?> == true) {
            // Do ignore the AbstractSelectPanels, otherwise the icons looks not very pretty on colored background.
            return;
        }/*ww w .  j  a  va  2s . com*/
        if (fc.isValid() == true) {
            return;
        }
    } else if (component.getParent() != null && component.getParent() instanceof FieldsetPanel) {
        final FieldsetPanel fs = (FieldsetPanel) component.getParent();
        if (fs.isValid() == true) {
            return;
        }
    } else {
        return;
    }
    final String value = tag.getAttribute("class");
    if (StringUtils.isEmpty(value) == true) {
        tag.put("class", "error");
    } else {
        tag.put("class", value + " error");
    }
}

From source file:org.projectforge.web.wicket.ShinyFormVisitor.java

License:Open Source License

/** Avoid borders arround components and child components. */
private boolean hasInvalidParent(final Component component) {
    if (component == null) {
        return false;
    }//w ww  .  j  a v a 2 s .co  m
    if (component instanceof FieldsetPanel && ((FieldsetPanel) component).isValid() == false) {
        return true;
    }
    if (component instanceof FormComponent<?> && ((FormComponent<?>) component).isValid() == false) {
        return true;
    }
    return hasInvalidParent(component.getParent());
}

From source file:org.projectforge.web.wicket.WicketPageTestBase.java

License:Open Source License

/**
 * Searches FormComponents (model object), LabeledWebmarkupContainers (label model) and ContentMenuEntryPanels (label).
 * @param container//from w w  w  .  j  av a2s  .  c o  m
 * @param label i18n key of the label or label (for buttons).
 * @return Found component with the given label or null if no such component found.
 * @see FormComponent#getModelObject()
 * @see LabeledWebMarkupContainer#getLabel()
 * @see ContentMenuEntryPanel#getLabel()
 */
public Component findComponentByLabel(final MarkupContainer container, final String label) {
    String str = label;
    try {
        str = container.getString(label);
    } catch (final MissingResourceException ex) {
        // OK
    }
    final String locLabel = str;
    final Component[] component = new Component[1];
    container.visitChildren(new IVisitor<Component, Void>() {
        @Override
        public void component(final Component object, final IVisit<Void> visit) {
            if (object instanceof AbstractLink) {
                final MarkupContainer parent = object.getParent();
                if (parent instanceof ContentMenuEntryPanel) {
                    if (labelEquals(((ContentMenuEntryPanel) parent).getLabel(), label, locLabel) == true) {
                        component[0] = object;
                        visit.stop();
                    }
                } else if (object.getId().equals(locLabel) == true) {
                    component[0] = object;
                    visit.stop();
                }
            } else {
                if (object instanceof LabeledWebMarkupContainer) {
                    final IModel<String> labelModel = ((LabeledWebMarkupContainer) object).getLabel();
                    if (labelModel != null) {
                        if (labelEquals(labelModel.getObject(), label, locLabel) == true) {
                            component[0] = object;
                            visit.stop();
                        }
                    }
                }
                if (object instanceof FormComponent<?>) {
                    final Object modelObject = ((FormComponent<?>) object).getModelObject();
                    if (modelObject instanceof String) {
                        if (labelEquals((String) modelObject, label, locLabel) == true) {
                            component[0] = object;
                            visit.stop();
                        }
                    }
                }
            }
        }
    });
    return component[0];
}

From source file:org.projectforge.web.wicket.WicketUtils.java

License:Open Source License

public static boolean isParent(final Component parent, final Component descendant) {
    final MarkupContainer p = descendant.getParent();
    if (p == null) {
        return false;
    } else if (p == parent) {
        return true;
    } else {/*  ww w  .j  a  v a 2  s.co  m*/
        return isParent(parent, p);
    }
}

From source file:org.wickedsource.wickedforms.wicket6.components.fields.AbstractFormElementPanel.java

License:Apache License

public FormPanel getParentFormPanel() {
    Component parent = getParent();
    while (parent != null) {
        if (parent instanceof FormPanel) {
            return (FormPanel) parent;
        }//w  ww.java2s .c o m
        parent = parent.getParent();
    }
    return null;
}

From source file:org.wickedsource.wickedforms.wicket6.components.fields.AbstractFormElementPanel.java

License:Apache License

public SectionPanel getParentSectionPanel() {
    Component parent = getParent();
    while (parent != null) {
        if (parent instanceof SectionPanel) {
            return (SectionPanel) parent;
        }//from  w w  w.j a v  a2 s  .c o m
        parent = parent.getParent();
    }
    return null;
}