/** * Checks if the given custom component or composite may accept a root * component. * <p> * For internal use only. * * @param customComponent * the custom component or composite * @return * @since 8.4 * */ public static boolean canSetRoot(Component customComponent) { if (customComponent instanceof CustomComponent) { return true; } if (customComponent instanceof Composite) { return ((Composite) customComponent).getCompositionRoot() == null; } return false; } }
private Component getRootOrThrow() { Component root = getCompositionRoot(); if (root == null) { throw new IllegalStateException( "Composition root has not been set"); } return root; }
@Override public Iterator<Component> iterator() { if (getCompositionRoot() != null) { return Collections.singletonList(getCompositionRoot()).iterator(); } else { return Collections.<Component> emptyList().iterator(); } }
private <T> T getRootPropertyOrNull( SerializableFunction<Component, T> getter) { Component root = getCompositionRoot(); return root == null ? null : getter.apply(root); }
@Override public String getStyleName() { Component root = getCompositionRoot(); return root == null ? "" : root.getStyleName(); }
private <T> T getRootAbstractComponentPropertyOrNull( SerializableFunction<AbstractComponent, T> getter) { Component root = getCompositionRoot(); if (root instanceof AbstractComponent) { return getter.apply((AbstractComponent) root); } return null; }
@Override public void beforeClientResponse(boolean initial) { super.beforeClientResponse(initial); if (getCompositionRoot() == null) { throw new IllegalStateException( "A composite must always have a composition root"); } }