@Override public void afterNavigation(AfterNavigationEvent event) { // <2> /* handle the parameters value */ Notification.show("Parameter value: " + this.parameter); }
@Override public void onNotificationAdded(Notification notification) { if (!isOpened()) { NotificationViewWithoutWrapper view = new NotificationViewWithoutWrapper(notification, holder); view.setWidth("200px"); com.vaadin.flow.component.notification.Notification notificationView = new com.vaadin.flow.component.notification.Notification(view); notificationView.setPosition(com.vaadin.flow.component.notification.Notification.Position.TOP_END); notificationView.setDuration(2000); notificationView.open(); } }
/** * Creates a Notification with given text String, duration and position * <P> * Set to {@code 0} or a negative number to disable the notification * auto-closing. * * @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 */ public Notification(String text, int duration, Position position) { initBaseElementsAndListeners(); setText(text); setDuration((double) duration); setPosition(position); }
/** * 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; }
@Override public void validationStatusChange(ValidationStatusEvent<S> statusChangeEvent) { if (statusChangeEvent.isInvalid()) { String error = showAllErrors ? statusChangeEvent.getErrorMessages().stream().collect(Collectors.joining("<br/>")) : statusChangeEvent.getErrorMessage(); if (error == null || error.trim().equals("")) { error = "Validation error"; } if (notification != null) { notification.setText(error); notification.open(); } else { Notification.show(error); } } else { if (notification != null) { notification.close(); } } }
/** * 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); }
/** * <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); }
/** * 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()); }
/** * 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); }
/** * 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); }
@Override public void showError(CrudOperation operation, Exception e) { if (errorListener != null) { errorListener.accept(e); } else { if (CrudOperationException.class.isAssignableFrom(e.getClass())) { // FIXME no Notification.Type Notification.show(e.getMessage()); } else { Notification.show(e.getMessage()); throw new RuntimeException("Error executing " + operation.name() + " operation", e); } } }
@OnShow // <1> public void processParameters() { /* handle the parameters value */ Notification.show("Parameter value: " + this.parameter); }
protected Button buildOperationButton(CrudOperation operation, T domainObject, ComponentEventListener<ClickEvent<Button>> clickListener) { if (clickListener == null) { return null; } String caption = buttonCaptions.get(operation); Icon icon = buttonIcons.get(operation); Button button = icon != null ? new Button(caption, icon) : new Button(caption); if (buttonStyleNames.containsKey(operation)) { buttonStyleNames.get(operation).stream().filter(styleName -> styleName != null).forEach(styleName -> button.addClassName(styleName)); } if (buttonThemes.containsKey(operation)) { button.getElement().setAttribute("theme", buttonThemes.get(operation)); } button.addClickListener(event -> { if (binder.writeBeanIfValid(domainObject)) { try { clickListener.onComponentEvent(event); } catch (Exception e) { showError(operation, e); } } else { Notification.show(validationErrorMessage); } }); return button; }
protected void findAllButtonClicked() { grid.asSingleSelect().clear(); refreshGrid(); Notification.show(String.format(rowCountCaption, grid.getDataProvider().size(new Query()))); }
public void listing28() { // tag::listing28[] PropertyListing.builder(SUBJECT) // .validationStatusHandler(event -> { // <1> if (event.isInvalid()) { Notification.show("Validation falied: " + event.getErrorMessage()); } }).validationStatusHandler(NAME, event -> { // <2> /* omitted */ }).build(); // end::listing28[] }
public void input36() { // tag::input36[] PropertyInputForm form = PropertyInputForm.formLayout(SUBJECT) // .validationStatusHandler(event -> { // <1> if (event.isInvalid()) { Notification.show("Validation falied: " + event.getErrorMessage()); } }).validationStatusHandler(NAME, event -> { // <2> /* omitted */ }).build(); // end::input36[] }
protected void showForm(CrudOperation operation, T domainObject, boolean readOnly, String successMessage, ComponentEventListener<ClickEvent<Button>> buttonClickListener) { Component form = crudFormFactory.buildNewForm(operation, domainObject, readOnly, cancelClickEvent -> { if (clickRowToUpdate) { grid.asSingleSelect().clear(); } else { T selected = grid.asSingleSelect().getValue(); crudLayout.hideForm(); grid.asSingleSelect().clear(); grid.asSingleSelect().setValue(selected); } }, operationPerformedClickEvent -> { crudLayout.hideForm(); buttonClickListener.onComponentEvent(operationPerformedClickEvent); Notification.show(successMessage); }); crudLayout.showForm(operation, form); }
public void listing18() { // tag::listing18[] PropertyListing listing = PropertyListing.builder(SUBJECT) // .contextMenu() // <1> .withItem("Context menu item 1") // <2> .withClickListener(e -> { // <3> PropertyBox rowItem = e.getItem(); // <4> e.getItemListing(); // <5> Notification.show("Context menu item clicked on row id " + rowItem.getValue(ID)); }).add() // <6> .withItem("Context menu item 2", "item.message.code", e -> { /* do something */}) // <7> .withItem(new Button("Context menu item 3"), e -> { /* do something */}) // <8> .add() // <9> .build(); // end::listing18[] }