/** * Returns the innermost component from a {@link Composite} chain, i.e. the * first content which is not a {@link Composite}. * * @param composite * a composite in the chain * @return the innermost component */ public static Component getInnermostComponent(Composite<?> composite) { Component content = composite.getContent(); while (content instanceof Composite) { content = ((Composite<?>) content).getContent(); } return content; }
/** * Gets the parent of the given component, which is inside the given * composite. * <p> * This method is meant for internal use only. * * @param composite * the composite containing the component * @param component * the component to get the parent for, must be inside the * composite or a nested composite * @return the parent of the component, never <code>null</code> */ public static Component getParentUsingComposite(Composite<?> composite, Component component) { // If this is the component inside a composite or a nested // composite, we need to traverse the composite hierarchy to find // the parent Composite<?> compositeAncestor = composite; while (true) { Component compositeChild = compositeAncestor.getContent(); if (compositeChild == component) { return compositeAncestor; } compositeAncestor = (Composite<?>) compositeAncestor.getContent(); } }
/** * Gets the child components of this composite. * <p> * A composite always has one child component, returned by * {@link #initContent()}. * * @return the child component of this composite */ @Override public Stream<Component> getChildren() { return Stream.of(getContent()); } }
private void addComponentHierarchy(UI ui, Set<Class<? extends Component>> hierarchyStorage, Component component) { hierarchyStorage.add(component.getClass()); if (component instanceof Composite) { addComponentHierarchy(ui, hierarchyStorage, ((Composite<?>) component).getContent()); } }
/** * Gets the root element of this composite. * <p> * For a composite, the root element is the same as the root element of the * content of the composite. * * @return the root element of this component */ @Override public Element getElement() { return getContent().getElement(); }
/** * Checks if the given component is inside a {@link Composite} chain, i.e. * it is a composite in the chain or the content of the innermost * {@link Composite}. * * @param composite * the first composite * @param component * the component to look for * @return <code>true</code> if the component is inside the composite chain, * <code>false</code> otherwise */ public static boolean isCompositeContent(Composite<?> composite, Component component) { Component compositeContent = composite.getContent(); if (compositeContent == component) { return true; } else if (compositeContent instanceof Composite) { // Nested composites return isCompositeContent((Composite<?>) compositeContent, component); } else { return false; } }
static void invokeMethod(Component instance, Class<?> clazz, String methodName, JsonArray args) { assert instance != null; Optional<Method> method = findMethod(instance, clazz, methodName); if (method.isPresent()) { invokeMethod(instance, method.get(), args); } else if (instance instanceof Composite) { Component compositeContent = ((Composite<?>) instance).getContent(); invokeMethod(compositeContent, compositeContent.getClass(), methodName, args); } else { String msg = String.format("Neither class '%s' " + "nor its super classes declare event handler method '%s'", instance.getClass().getName(), methodName); throw new IllegalStateException(msg); } }
boolean initialAttach) { if (component instanceof Composite) { onComponentAttach(((Composite<?>) component).getContent(), initialAttach);
onComponentDetach(((Composite<?>) component).getContent());