/** * Set position of the notification. * <P> * * @param position * the position of the notification. Valid enumerate values are * {@code TOP_STRETCH, TOP_START, TOP_CENTER, TOP_END, MIDDLE, BOTTOM_START, BOTTOM_CENTER, BOTTOM_END, BOTTOM_STRETCH}, * not {@code null} */ public void setPosition(Position position) { setPosition(position.getClientName()); }
/** * {@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); }
/** * Opens the notification. */ @Override public void open() { setOpened(true); }
@Override public void afterNavigation(AfterNavigationEvent event) { // <2> /* handle the parameters value */ Notification.show("Parameter value: " + this.parameter); }
/** * Shows a notification in the current page with given text, duration and * position. * * @param text * the text of the Notification * @param duration * the duration in milliseconds to show the notification * @param position * the position of the notification. Valid enumerate values are * TOP_STRETCH, TOP_START, TOP_CENTER, TOP_END, MIDDLE, * BOTTOM_START, BOTTOM_CENTER, BOTTOM_END, BOTTOM_STRETCH * @return the notification */ public static Notification show(String text, int duration, Position position) { Notification notification = new Notification(text, duration, position); notification.open(); return notification; }
/** * <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 value to set */ public void setDuration(int duration) { setDuration((double) duration); }
private void initBaseElementsAndListeners() { getElement().appendChild(templateElement); getElement().appendVirtualChild(container); getElement().addEventListener("opened-changed", event -> { if (autoAddedToTheUi && !isOpened()) { getElement().removeFromParent(); autoAddedToTheUi = false; } }); }
/** * <p> * Description copied from corresponding location in WebComponent: * </p> * <p> * Opens the notification. * </p> */ protected void open() { getElement().callFunction("open"); }
/** * {@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); }
@Override public Registration addOpenedChangeListener( ComponentEventListener<OpenedChangeEvent<Notification>> listener) { return super.addOpenedChangeListener(listener); }
/** * Creates a notification with given components inside. * <p> * Note: To mix text and child components in a component that also supports * child components, use the {@link Text} component for the textual parts. * * @param components * the components inside the notification * @see #add(Component...) */ public Notification(Component... components) { this(); add(components); }
public OpenedChangeEvent(R source, boolean fromClient) { super(source, fromClient); this.opened = source.isOpenedBoolean(); }
/** * <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 */ public boolean isOpened() { return isOpenedBoolean(); }
/** * <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 */ public int getDuration() { return (int) getDurationDouble(); }
Position() { this.clientName = name().toLowerCase(Locale.ENGLISH).replace('_', '-'); }
/** * Shows a notification in the current page with given text. * <p> * This is the convenience method for {@link #show(String, int, Position)} * which uses default web-component values for duration (which is 5000 ms) * and position ({@literal Position.BOTTOM_START}). * * * @param text * the text of the Notification * @return the notification */ public static Notification show(String text) { return show(text, DEFAULT_DURATION, DEFAULT_POSITION); }
/** * <p> * Description copied from corresponding location in WebComponent: * </p> * <p> * Closes the notification. * </p> */ protected void close() { getElement().callFunction("close"); }
/** * Closes the notification. * <p> * Note: This method also removes the notification component from the DOM * after closing it, unless you have added the component manually. */ @Override public void close() { setOpened(false); }
@OnShow // <1> public void processParameters() { /* handle the parameters value */ Notification.show("Parameter value: " + this.parameter); }
/** * <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); }