@Override public DefaultComponentConfigurator withDetachListener(ComponentEventListener<DetachEvent> listener) { component.addDetachListener(listener); return this; }
private void registerLifecycleOwner(Component owner) { assert owner != null; lifecycleOwner = owner; // since we are attached, UI should be available Registration attachRegistration = owner.addAttachListener(e -> queueBeforeExecutionCallback()); // remove shortcut listener when detached Registration detachRegistration = owner.addDetachListener(e -> removeListenerRegistration()); lifecycleRegistration = new CompoundRegistration(attachRegistration, detachRegistration); }
private void registerOwnerListener() { assert listenOnSupplier != null; listenOnComponent = listenOnSupplier.get(); if (listenOnComponent == null) { throw new IllegalStateException( String.format("Could register shortcut listener for %s. " + "%s<%s> supplied a null value.", this.toString(), SerializableSupplier.class.getSimpleName(), Component.class.getSimpleName())); } if (!(listenOnComponent instanceof UI)) { listenOnAttachListenerRegistration = new CompoundRegistration(); listenOnAttachListenerRegistration.addRegistration( listenOnComponent.addAttachListener( attachEvent -> updateHandlerListenerRegistration())); listenOnAttachListenerRegistration.addRegistration( listenOnComponent.addDetachListener( detachEvent -> removeListenerRegistration())); } // either the scope is an active UI, or the component is attached to an // active UI - in either case, we want to update dom registration if (listenOnComponent.getUI().isPresent()) { updateHandlerListenerRegistration(); } }
/** * Assigns the tooltip to a specific component. * <p> * The tooltip is removed from the parent after the component that the tooltip is * attached is detached. * * @param component the tooltip is attached to this component * @param appended <code>true</code> the tooltip is automatically appended * to the component's father.<code>false</code>, * it is not appended. It should be added to a layout manually. */ public void attachToComponent(Component component, boolean appended) { Objects.requireNonNull(component); getElement().getNode().runWhenAttached(ui -> { ui.getPage().executeJavaScript("$0.targetElement = $1;", getElement(), component.getElement() ); }); if ( appended ){ component.getElement().getNode().runWhenAttached(ui -> { component.getElement().getParentNode().appendChild(getElement()); }); } if ( detachedRegistration != null ){ detachedRegistration.remove(); } detachedRegistration = component.addDetachListener(event -> { this.getElement().removeFromParent(); }); }