/** * {@inheritDoc} * <p> * Note: To listen for opening the notification, you should use * {@link #addOpenedChangeListener(ComponentEventListener)}. */ @Override public Registration addAttachListener( ComponentEventListener<AttachEvent> listener) { return super.addAttachListener(listener); }
/** * {@inheritDoc} * <p> * Note: To listen for closing the notification, you should use * {@link #addOpenedChangeListener(ComponentEventListener)}, as the * component is not necessarily removed from the DOM when closing. */ @Override public Registration addDetachListener( ComponentEventListener<DetachEvent> listener) { return super.addDetachListener(listener); }
@Override public Registration addOpenedChangeListener( ComponentEventListener<OpenedChangeEvent<Notification>> listener) { return super.addOpenedChangeListener(listener); }
/** * <p> * Description copied from corresponding location in WebComponent: * </p> * <p> * Opens the notification. * </p> */ protected void open() { getElement().callFunction("open"); }
public OpenedChangeEvent(R source, boolean fromClient) { super(source, fromClient); this.opened = source.isOpenedBoolean(); }
/** * 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); }
/** * <p> * Description copied from corresponding location in WebComponent: * </p> * <p> * Closes the notification. * </p> */ protected void close() { getElement().callFunction("close"); }
/** * <p> * Description copied from corresponding location in WebComponent: * </p> * <p> * True if the notification is currently displayed. * </p> * * @param opened * the boolean value to set */ protected void setOpened(boolean opened) { getElement().setProperty("opened", opened); }
/** * <p> * Description copied from corresponding location in WebComponent: * </p> * <p> * The duration in milliseconds to show the notification. Set to {@code 0} * or a negative number to disable the notification auto-closing. * </p> * * @param duration * the double value to set */ protected void setDuration(double duration) { getElement().setProperty("duration", duration); }
/** * <p> * Description copied from corresponding location in WebComponent: * </p> * <p> * Alignment of the notification in the viewport Valid values are * {@code top-stretch|top-start|top-center|top-end|middle|bottom-start|bottom-center|bottom-end|bottom-stretch} * </p> * * @param position * the String value to set */ protected void setPosition(String position) { getElement().setProperty("position", position == null ? "" : position); }
/** * <p> * Description copied from corresponding location in WebComponent: * </p> * <p> * The duration in milliseconds to show the notification. Set to {@code 0} * or a negative number to disable the notification auto-closing. * <p> * This property is not synchronized automatically from the client side, so * the returned value may not be the same as in client side. * </p> * * @return the {@code duration} property from the webcomponent */ protected double getDurationDouble() { return getElement().getProperty("duration", 0.0); }
/** * <p> * Description copied from corresponding location in WebComponent: * </p> * <p> * Alignment of the notification in the viewport Valid values are * {@code top-stretch|top-start|top-center|top-end|middle|bottom-start|bottom-center|bottom-end|bottom-stretch} * <p> * This property is not synchronized automatically from the client side, so * the returned value may not be the same as in client side. * </p> * * @return the {@code position} property from the webcomponent */ protected String getPositionString() { return getElement().getProperty("position"); }
/** * <p> * Description copied from corresponding location in WebComponent: * </p> * <p> * True if the notification is currently displayed. * <p> * This property is synchronized automatically from client side when a * 'opened-changed' event happens. * </p> * * @return the {@code opened} property from the webcomponent */ @Synchronize(property = "opened", value = "opened-changed") protected boolean isOpenedBoolean() { return getElement().getProperty("opened", false); }
/** * Adds a listener for {@code opened-changed} events fired by the * webcomponent. * * @param listener * the listener * @return a {@link Registration} for removing the event listener */ protected Registration addOpenedChangeListener( ComponentEventListener<OpenedChangeEvent<R>> listener) { return getElement() .addPropertyChangeListener("opened", event -> listener.onComponentEvent( new OpenedChangeEvent<R>((R) this, event.isUserOriginated()))); } }