Component implements HasElement, AttachNotifier, DetachNotifier { public Optional<UI> getUI() { Optional<Component> parent = getParent(); if (parent.isPresent()) { return parent.flatMap(Component::getUI); } else if (getElement().getParentNode() instanceof ShadowRoot) { parent = ComponentUtil.findParentComponent( ((ShadowRoot) getElement().getParentNode()).getHost()); return parent.flatMap(Component::getUI); } return Optional.empty(); } protected  Component(); protected  Component(Element element); @Override Element getElement(); Optional<Component> getParent(); Stream<Component> getChildren(); Optional<UI> getUI(); void setId(String id); Optional<String> getId(); boolean isAttached(); static T from(Element element,
            Class<T> componentType); void setVisible(boolean visible); boolean isVisible(); void onEnabledStateChanged(boolean enabled); String getTranslation(String key, Object... params); String getTranslation(String key, Locale locale, Object... params);  }
@Test public void getUI_noParent() { TestComponent c = new TestComponent(); assertEmpty(c.getUI()); }
@Test public void getUI_detachedParent() { TestComponentContainer parent = new TestComponentContainer(); TestComponent child = new TestComponent(); parent.add(child); assertEmpty(child.getUI()); }