Component implements HasElement, AttachNotifier, DetachNotifier { protected <T> T get(PropertyDescriptor<?, T> descriptor) { assert descriptor != null; return descriptor.get(this); } 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 testAttachListener_eventOrder_childFirst() { UI ui = new UI(); TestComponentContainer parent = new TestComponentContainer(); TestComponent child = new TestComponent(); child.track(); parent.track(); child.addAttachListener(event -> { Assert.assertEquals(0, parent.getAttachEvents().get()); }); parent.addAttachListener(event -> { Assert.assertEquals(1, child.getAttachEvents().get()); }); parent.add(child); child.assertAttachEvents(0); parent.assertAttachEvents(0); ui.add(parent); child.assertAttachEvents(1); parent.assertAttachEvents(1); }
@Test public void testDetachListener_eventOrder_childFirst() { UI ui = new UI(); TestComponentContainer parent = new TestComponentContainer(); TestComponent child = new TestComponent(); child.track(); parent.track(); child.addDetachListener(event -> { Assert.assertEquals(0, parent.getDetachEvents().get()); }); parent.addDetachListener(event -> { Assert.assertEquals(1, child.getDetachEvents().get()); }); parent.add(child); ui.add(parent); child.assertDetachEvents(0); parent.assertDetachEvents(0); ui.remove(parent); child.assertDetachEvents(1); parent.assertDetachEvents(1); }
@Test public void testAttachDetach_elementMoved_bothEventsTriggered() { UI ui = new UI(); TestComponentContainer parent = new TestComponentContainer(); TestComponent child = new TestComponent(); parent.add(child); ui.add(parent); child.track(); child.addAttachListener(event -> { Assert.assertEquals(1, child.getDetachEvents().get()); }); child.addDetachListener(event -> { Assert.assertEquals(0, child.getAttachEvents().get()); }); ui.add(child); child.assertAttachEvents(1); child.assertDetachEvents(1); }