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.wicketstuff.dojo11.DojoTargetRefresherManager.java

License:Apache License

/**
 * Look for ancestor in the hierarchie//from   w w  w .  ja v a  2  s  .  c o  m
 * @param component 
 * @return
 */
private boolean hasParentAdded(Component component) {
    Component current = component;
    while (current.getParent() != null) {
        if (dojoComponents.containsKey(current.getParent().getMarkupId())
                && (current.getParent() instanceof IDojoWidget)) {
            return true;
        }
        current = current.getParent();
    }
    return false;
}

From source file:org.wicketstuff.extjs.util.ExtConfigResourceLoader.java

License:Apache License

protected String getCacheKey(final String key, final Component component) {
    String cacheKey = key;//  w w  w.j  a v  a2 s  .  co m
    if (component != null) {
        AppendingStringBuffer buffer = new AppendingStringBuffer(200);
        buffer.append(key);

        Component cursor = component;
        while (cursor != null) {
            buffer.append("-").append(cursor.getClass().hashCode());

            if (cursor instanceof Page) {
                break;
            }

            if (cursor.getParent() != null && !(cursor.getParent() instanceof AbstractRepeater)) {
                /*
                 * only append component id if parent is not a repeater because
                 *
                 * (a) these ids are irrelevant when generating resource cache keys
                 *
                 * (b) they cause a lot of redundant keys to be generated
                 */
                buffer.append(":").append(cursor.getId());
            }
            cursor = cursor.getParent();

        }

        buffer.append("-").append(component.getLocale());
        buffer.append("-").append(component.getStyle());
        // TODO 1.4 look if we want to properly separate getstyle/getvariation
        // for now getvariation() is rolled up into getstyle()
        // buffer.append("-").append(component.getVariation());
        cacheKey = buffer.toString();
    }
    return cacheKey;
}

From source file:org.wicketstuff.js.ext.ExtComponent.java

License:Apache License

private void addThemeBehavior() {
    if (isExtRoot()) {
        Component component = this;
        boolean foundTheme = false;
        while (component != null) {
            for (Behavior behavior : component.getBehaviors()) {
                if (behavior instanceof ExtThemeBehavior) {
                    foundTheme = true;//from  w  w w  . j  av a  2  s. c  o  m
                    break;
                }
            }
            if (foundTheme) {
                break;
            }
            component = component.getParent();
        }
        if (!foundTheme) {
            add(getThemeBehavior());
        }
    }
}

From source file:org.wicketstuff.js.ext.util.ExtCustomThemeBehavior.java

License:Apache License

@Override
public void renderHead(Component component, IHeaderResponse response) {
    super.renderHead(component, response);

    Component parent = component.getParent();
    boolean foundTheme = false;
    while (parent != null) {
        for (Behavior behavior : parent.getBehaviors()) {
            if (behavior instanceof ExtThemeBehavior) {
                foundTheme = true;//from   w  ww. j  a  v a 2 s .co m
                break;
            }
        }
        if (foundTheme) {
            break;
        }
        parent = parent.getParent();
    }
    if (!foundTheme) {
        response.render(CssHeaderItem.forReference(EXT_ALL_NOTHEME_REFERENCE));
    }
}

From source file:org.wicketstuff.security.components.SecureComponentHelper.java

License:Apache License

/**
 * Builds a set of aliases for this component. Each alias can be used as name in Permission.
 * //from   w  w  w. jav  a2 s  . com
 * @param component
 * @return an array with aliases for this component
 */
public static String[] containerAliasses(Component component) {
    if (component == null)
        throw new SecurityException("specified component is null");
    MarkupContainer parent = null;
    if (component instanceof MarkupContainer)
        parent = (MarkupContainer) component;
    else
        parent = component.getParent();
    if (parent == null)
        return new String[0];
    String alias = containerAlias(parent);
    String[] split = alias.split(PATH_SEPARATOR);
    String[] result = new String[split.length + (split.length - 1)];
    PrependingStringBuffer buffer = new PrependingStringBuffer(200);
    int index = result.length - 1;
    for (int i = split.length - 1; i >= 0; i--) {
        if (i < split.length - 1) {
            result[index] = split[i];
            index--;
            buffer.prepend(PATH_SEPARATOR);
        }
        buffer.prepend(split[i]);
        result[index] = buffer.toString();
        index--;
    }
    return result;
}

From source file:sf.wicklet.ext.util.WickletUtil.java

License:Apache License

/** Find parent of the component that has the given id attribute. */
public static MarkupContainer getParent(final Component c, final String id) {
    for (MarkupContainer parent = c.getParent(); parent != null; parent = parent.getParent()) {
        if (id.equals(parent.getId())) {
            return parent;
        }/*from  w w  w . ja v  a2 s.  com*/
    }
    return null;
}

From source file:sf.wicklet.gwt.server.ajax.impl.AbstractGwtAjaxResponse.java

License:Apache License

/**
 * Checks if the target contains an ancestor for the given component
 *
 * @param component/*  ww  w  .  j av a2  s  .c o  m*/
 *      the component which ancestors should be checked.
 * @return <code>true</code> if target contains an ancestor for the given component
 */
protected boolean containsAncestorFor(final Component component) {
    Component cursor = component.getParent();
    while (cursor != null) {
        if (markupIdToComponent.containsValue(cursor)) {
            return true;
        }
        cursor = cursor.getParent();
    }
    return false;
}