private static Element toElement(HasElement hasElement) { return hasElement != null ? hasElement.getElement() : null; } }
/** * Gets the property value for the given component. * * @param hasElement * the component for which to get the value, not * <code>null</code> * @return the property value */ default G get(HasElement hasElement) { assert hasElement != null; return get(hasElement.getElement()); }
/** * Sets the property value for the given component. * * @param hasElement * the component for which to set the value, not * <code>null</code> * @param value * the property value to set */ default void set(HasElement hasElement, S value) { assert hasElement != null; set(hasElement.getElement(), value); }
private void removeFromParent(HasElement component) { if (component != null) { component.getElement().removeFromParent(); } }
/** * Removes every child element of the parent that are in the specified slot. * * @param parent * the component whose slot to clear * @param slot * the name of the slot to clear */ public static void clearSlot(HasElement parent, String slot) { getElementsInSlot(parent, slot) .collect(Collectors.toList()) .forEach(parent.getElement()::removeChild); }
/** * An action which toggles the target's {@code attribute} based on its * highlight state. * * @param <C> * the target type * @param attribute * the attribute to toggle * @return the highlight action */ public static <C extends HasElement> HighlightAction<C> toggleAttribute( String attribute) { return (component, highlight) -> component.getElement() .setAttribute(attribute, highlight); }
/** * Collect all Components implementing {@link LocaleChangeObserver} * connected to the tree of all given Components in list. * * @param components * components to search * @return navigation listeners */ public static List<LocaleChangeObserver> collectLocaleChangeObservers( List<HasElement> components) { Stream<Element> elements = components.stream().flatMap( component -> flattenDescendants(component.getElement())); return getImplementingComponents(elements, LocaleChangeObserver.class) .collect(Collectors.toList()); }
/** * Gets all the child elements of the parent that are in the specified slot. * * @param parent * the component to get children from, not {@code null} * @param slot * the name of the slot inside the parent, not {@code null} * @return the child elements of the parent that are inside the slot */ public static Stream<Element> getElementsInSlot(HasElement parent, String slot) { return parent.getElement().getChildren() .filter(child -> slot.equals(child.getAttribute("slot"))); }
/** * Constructor. * @param component Component to configure (not null) * @param deferrableLocalization Optional {@link HasDeferrableLocalization} reference */ public DefaultHasHtmlTextConfigurator(HasElement component, HasDeferrableLocalization deferrableLocalization) { super(text -> component.getElement().setProperty(INNER_HTML_PROPERTY, text), deferrableLocalization); ObjectUtils.argumentNotNull(component, "The component to configure must be not null"); this.component = component; }
/** * Shows the content of the layout which is the router target component * annotated with a {@link Route @Route}. * <p> * <strong>Note</strong> implementors should not care about old * {@code @Route} content, because {@link Router} automatically removes * it before calling the method. * </p> * * @param content the content component or {@code null} if the layout content is to be cleared. */ default void showRouterLayoutContent(HasElement content) { if (content != null) { getElement().appendChild(Objects.requireNonNull(content.getElement())); } }
@Override public void setAppLayoutContent(HasElement content) { if (content != null) { this.content.getElement().appendChild(content.getElement()); } }
/** * Gets the flex grow property of a given element container. * * @param elementContainer * the element container to read the flex grow property from * @return the flex grow property, or 0 if none was set */ default public double getFlexGrow(HasElement elementContainer) { String ratio = elementContainer.getElement().getStyle() .get(FlexConstants.FLEX_GROW_CSS_PROPERTY); if (ratio == null || ratio.isEmpty()) { return 0; } try { return Double.parseDouble(ratio); } catch (Exception e) { throw new IllegalStateException( "The flex grow property of the element container is not parseable to double: " + ratio, e); } }
@Override public void setAppLayoutContent(HasElement content) { if (content != null) { this.content.getElement().appendChild(content.getElement()); } }
/** * An action which toggles {@code theme} on the target based on its * highlight state. * * @param <C> * the target type * @param theme * the theme to toggle * @return the highlight action */ public static <C extends HasElement> HighlightAction<C> toggleTheme( String theme) { return (component, highlight) -> component.getElement().getThemeList() .set(theme, highlight); }
Element chainRootElement = chainRoot.getElement();
@Override public void setAppLayoutContent(HasElement content) { if (content != null) { this.content.getElement().appendChild(content.getElement()); setUpBackNavigation(content); } }
container.getElement().getStyle() .remove(FlexConstants.FLEX_GROW_CSS_PROPERTY); container.getElement().getStyle().set( FlexConstants.FLEX_GROW_CSS_PROPERTY, String.valueOf(flexGrow));
/** * Gets the individual alignment of a given element container. * <p> * The default alignment for individual element containers is * {@link Alignment#AUTO}. * * @param container * The element container (component) which individual layout * should be read * @return the alignment of the container, never <code>null</code> */ default public Alignment getAlignSelf(HasElement container) { return Alignment.toAlignment(container.getElement().getStyle() .get(FlexConstants.ALIGN_SELF_CSS_PROPERTY), Alignment.AUTO); }
if (alignment == null) { for (HasElement container : elementContainers) { container.getElement().getStyle() .remove(FlexConstants.ALIGN_SELF_CSS_PROPERTY); container.getElement().getStyle().set( FlexConstants.ALIGN_SELF_CSS_PROPERTY, alignment.getFlexValue());
@Override public void showRouterLayoutContent(HasElement content) { Component component = content.getElement().getComponent().get(); String target = null; if (component instanceof RouteNotFoundError) { getAppLayoutMenu().selectMenuItem(null); } else { target = UI.getCurrent().getRouter() .getUrl(component.getClass()); getAppLayoutMenu().getMenuItemTargetingRoute(target) .ifPresent(item -> getAppLayoutMenu().selectMenuItem(item, false)); } beforeNavigate(target, content); getAppLayout().setContent(content.getElement()); afterNavigate(target, content); }