private void initBaseElementsAndListeners() { getElement().appendChild(templateElement); getElement().appendVirtualChild(container); getElement().addEventListener("opened-changed", event -> { if (autoAddedToTheUi && !isOpened()) { getElement().removeFromParent(); autoAddedToTheUi = false; } }); }
private void attachComponentTemplate() { deferredJob = new AttachComponentTemplate(); getElement().getNode().runWhenAttached(ui -> ui .beforeClientResponse(this, context -> deferredJob.accept(ui))); } }
/** * Opens or closes the notification. * <p> * Note: You don't need to add the component anywhere before opening it. * Since {@code <vaadin-notification>}'s location in the DOM doesn't really * matter, opening a notification will automatically add it to the * {@code <body>} if it's not yet attached anywhere. * * @param opened * {@code true} to open the notification, {@code false} to close * it */ @Override public void setOpened(boolean opened) { UI ui = UI.getCurrent(); if (ui == null) { throw new IllegalStateException("UI instance is not available. " + "It means that you are calling this method " + "out of a normal workflow where it's always implicitely set. " + "That may happen if you call the method from the custom thread without " + "'UI::access' or from tests without proper initialization."); } if (opened && getElement().getNode().getParent() == null) { ui.beforeClientResponse(ui, context -> { ui.add(this); autoAddedToTheUi = true; }); } super.setOpened(opened); }
/** * Default constructor. Create an empty notification with component support * and non-auto-closing * <p> * Note: To mix text and child components in notification that also supports * child components, use the {@link Text} component for the textual parts. */ public Notification() { initBaseElementsAndListeners(); getElement().getNode().runWhenAttached(ui -> ui .beforeClientResponse(this, context -> deferredJob.accept(ui))); setPosition(DEFAULT_POSITION); setDuration(0); }