Java Code Examples for com.vaadin.flow.dom.Element#getParent()

The following examples show how to use com.vaadin.flow.dom.Element#getParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractNavigationStateRenderer.java    From flow with Apache License 2.0 6 votes vote down vote up
private static boolean isComponentElementEqualsOrChild(
        BeforeEnterHandler eventHandler, Component component) {
    if (eventHandler instanceof HasElement) {
        HasElement hasElement = (HasElement) eventHandler;

        final Element componentElement = component.getElement();

        Element element = hasElement.getElement();
        while (element != null) {
            if (element.equals(componentElement)) {
                return true;
            }

            element = element.getParent();
        }
    }

    return false;
}
 
Example 2
Source File: ComponentUtil.java    From flow with Apache License 2.0 5 votes vote down vote up
/**
 * Finds the first component by traversing upwards in the element hierarchy,
 * starting from the given element.
 *
 * @param element
 *            the element from which to begin the search
 * @return optional of the component, empty if no component is found
 */
public static Optional<Component> findParentComponent(Element element) {
    Element mappedElement = element;
    while (mappedElement != null
            && !mappedElement.getComponent().isPresent()) {
        mappedElement = mappedElement.getParent();
    }
    if (mappedElement == null) {
        return Optional.empty();
    }

    return Optional.of(getInnermostComponent(mappedElement));
}
 
Example 3
Source File: ComponentUtil.java    From flow with Apache License 2.0 5 votes vote down vote up
private static boolean checkParentChainState(Element element) {
    if (!element.getNode().isEnabledSelf()) {
        return false;
    }

    Element parent = element.getParent();
    if (parent != null) {
        if (isAttachedToParent(element, parent)) {
            return checkParentChainState(parent);
        }
    }

    return true;
}
 
Example 4
Source File: Renderer.java    From flow with Apache License 2.0 4 votes vote down vote up
/**
 * Handles the rendering of the model objects by using the given
 * {@code <template>} element in the given container.
 * <p>
 * Subclasses of Renderer usually override this method to provide additional
 * features.
 * 
 * @param container
 *            the element in which the template will be attached to, not
 *            {@code null}
 * @param keyMapper
 *            mapper used internally to fetch items by key and to provide
 *            keys for given items. It is required when either event
 *            handlers or {@link DataGenerator} are supported
 * @param contentTemplate
 *            the {@code <template>} element to be used for rendering in the
 *            container, not {@code null}
 * @return the context of the rendering, that can be used by the components
 *         to provide extra customization
 */
public Rendering<SOURCE> render(Element container,
        DataKeyMapper<SOURCE> keyMapper, Element contentTemplate) {
    Objects.requireNonNull(template,
            "The template string is null. Either build the Renderer by using the 'Renderer(String)' constructor or override the 'render' method to provide custom behavior");

    contentTemplate.setProperty("innerHTML", template);

    if (contentTemplate.getParent() != container) {
        container.appendChild(contentTemplate);
    }

    if (keyMapper != null) {
        RendererUtil.registerEventHandlers(this, contentTemplate, container,
                keyMapper::get);
    }
    return new TemplateRendering(contentTemplate);
}