Java Code Examples for com.vaadin.ui.Notification

The following examples show how to use com.vaadin.ui.Notification. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: sidemenu-addon   Source File: DemoUI.java    License: Apache License 2.0 6 votes vote down vote up
private void initTreeMenu() {
    sideMenu.addTreeItem("Tree item", () -> Notification.show("Parent!"));
    sideMenu.addTreeItem("Tree item", "sub item", () -> {
        Notification.show("Sub item!");
        sideMenu.addComponent(
            new Button(
                "Add sub sub item",
                event -> subSubTreeItem = sideMenu.addTreeItem("sub item", "sub sub item", () -> Notification.show("Inception!"))));
        sideMenu.addComponent(new Button("Remove sub sub item", event -> {
            if (null != subSubTreeItem) {
                subSubTreeItem.remove();
                subSubTreeItem = null;
            }
        }));
    });
}
 
Example 2
Source Project: sidemenu-addon   Source File: DemoUI.java    License: Apache License 2.0 6 votes vote down vote up
private void setUser(String name, Resource icon) {
	sideMenu.setUserName(name);
	sideMenu.setUserIcon(icon);

	sideMenu.clearUserMenu();
       sideMenu.addUserMenuItem("Settings", VaadinIcons.WRENCH, () -> Notification.show("Showing settings", Type.TRAY_NOTIFICATION));
       sideMenu.addUserMenuItem("Sign out", () -> Notification.show("Logging out..", Type.TRAY_NOTIFICATION));

	sideMenu.addUserMenuItem("Hide logo", () -> {
		if (!logoVisible) {
			sideMenu.setMenuCaption(menuCaption, logo);
		} else {
			sideMenu.setMenuCaption(menuCaption);
		}
		logoVisible = !logoVisible;
	});
}
 
Example 3
Source Project: cuba   Source File: SystemInfoWindowCompanion.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void addCopyButton(ComponentContainer container, String description,
                          String successMessage, String failMessage,
                          String cubaCopyLogContentClass, UiComponents uiComponents) {
    if (CubaCopyButtonExtension.browserSupportCopy()) {
        Button copyButton = uiComponents.create(Button.class);

        copyButton.setIconFromSet(CubaIcon.CLIPBOARD);
        copyButton.setId("copy");
        copyButton.setVisible(false);
        copyButton.setDescription(description);

        copyButton.withUnwrapped(com.vaadin.ui.Button.class, vButton -> {
            CubaCopyButtonExtension copyExtension =
                    CubaCopyButtonExtension.copyWith(vButton, cubaCopyLogContentClass);
            copyExtension.addCopyListener(event ->
                    Notification.show(event.isSuccess() ? successMessage : failMessage,
                            Notification.Type.TRAY_NOTIFICATION));
        });

        container.add(copyButton);
    }
}
 
Example 4
Source Project: cuba   Source File: WebNotifications.java    License: Apache License 2.0 6 votes vote down vote up
protected com.vaadin.ui.Notification.Type convertType(NotificationType notificationType) {
    switch (notificationType) {
        case TRAY:
            return com.vaadin.ui.Notification.Type.TRAY_NOTIFICATION;

        case HUMANIZED:
            return com.vaadin.ui.Notification.Type.HUMANIZED_MESSAGE;

        case WARNING:
            return com.vaadin.ui.Notification.Type.WARNING_MESSAGE;

        case ERROR:
            return com.vaadin.ui.Notification.Type.ERROR_MESSAGE;

        default:
            throw new UnsupportedOperationException("Unsupported notification type");
    }
}
 
Example 5
Source Project: hawkbit   Source File: ErrorView.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void enter(final ViewChangeListener.ViewChangeEvent event) {
    final DashboardMenuItem view = dashboardMenu.getByViewName(event.getViewName());
    if (view == null) {
        message.setValue(i18n.getMessage("message.error.view", event.getViewName()));
        return;
    }
    if (dashboardMenu.isAccessDenied(event.getViewName())) {
        final Notification nt = new Notification("Access denied",
                i18n.getMessage("message.accessdenied.view", event.getViewName()), Type.ERROR_MESSAGE, false);
        nt.setStyleName(SPUIStyleDefinitions.SP_NOTIFICATION_ERROR_MESSAGE_STYLE);
        nt.setPosition(Position.BOTTOM_RIGHT);
        nt.show(UI.getCurrent().getPage());
        message.setValue(i18n.getMessage("message.accessdenied.view", event.getViewName()));
    }
}
 
Example 6
Source Project: jpa-invoicer   Source File: MyAccount.java    License: The Unlicense 6 votes vote down vote up
public void save(Invoicer entity) {
    try {
        if (entity.getId() == null) {
            cf.save(entity);
            session.getUser().getAdministrates().add(entity);
        } else {
            cf.save(entity);
        }
        Notification.show("Saved!");
    } catch (Exception e) {
        Notification.show("Saving failed!",
                "Most probably concurrently edited",
                Notification.Type.WARNING_MESSAGE);
    }
    listEntities();
    form.getPopup().close();
}
 
Example 7
Source Project: cia   Source File: LogoutClickListener.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public final void buttonClick(final ClickEvent event) {
	final ServiceResponse response = getApplicationManager().service(logoutRequest);


	if (ServiceResult.SUCCESS == response.getResult()) {
		UI.getCurrent().getNavigator().navigateTo(CommonsViews.MAIN_VIEW_NAME);
		UI.getCurrent().getSession().close();
		VaadinService.getCurrentRequest().getWrappedSession().invalidate();
	} else {
		showNotification(LOGOUT_FAILED,
                  ERROR_MESSAGE,
                  Notification.Type.WARNING_MESSAGE);
		LOGGER.info(LOG_MSG_LOGOUT_FAILURE,logoutRequest.getSessionId());
	}
}
 
Example 8
Source Project: cia   Source File: SearchDocumentClickListener.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public final void buttonClick(final ClickEvent event) {
	final SearchDocumentResponse response = (SearchDocumentResponse) getApplicationManager().service(reqisterRequest);
	if (ServiceResult.SUCCESS == response.getResult()) {
		LOGGER.info(LOG_MSG_SEARCH_DOCUMENT,reqisterRequest.getSearchExpression());
		showNotification(SEARCH_SUCCESS,
                  "Found :" + response.getResultElement().size(),
                  Notification.Type.HUMANIZED_MESSAGE);
		responseHandler.handle(response);

	} else {
		showNotification(SEARCH_FAILED,
                  ERROR_MESSAGE,
                  Notification.Type.WARNING_MESSAGE);
		LOGGER.info(LOG_MSG_SEARCH_DOCUMENT_FAILURE,reqisterRequest.getSearchExpression());
	}
}
 
Example 9
Source Project: context-menu   Source File: GridWithGenericListener.java    License: Apache License 2.0 6 votes vote down vote up
private void onGenericContextMenu(ContextMenuOpenEvent event) {
    GridContextClickEvent<String[]> gridE = (GridContextClickEvent<String[]>) event
            .getContextClickEvent();
    ContextMenu menu = event.getContextMenu();
    menu.removeItems();
    if (gridE.getColumn() != null) {
        menu.addItem(
                "Called from column " + gridE.getColumn().getCaption()
                        + " on row " + gridE.getRowIndex(),
                f -> Notification.show("did something"));
    } else if (gridE.getRowIndex() >= 0) {
        menu.addItem("Called on row " + gridE.getRowIndex(),
                f -> Notification.show("did something"));
    } else {
        menu.addItem("Called on background",
                f -> Notification.show("did something"));

    }
}
 
Example 10
Source Project: context-menu   Source File: ContextMenuUI.java    License: Apache License 2.0 6 votes vote down vote up
private void addTree(VerticalLayout layout) {
    TreeData<String> data = new TreeData<>();
    data.addItem(null, "Dad");
    data.addItem("Dad", "Daughter");
    data.addItem("Daughter", "Granddaughter");
    data.addItem("Dad", "Son");
    data.addItem("Daughter", "Grandson");

    Tree<String> tree = new Tree<>("A family", data);
    TreeContextMenu<String> treeContextMenu = new TreeContextMenu<>(tree);
    treeContextMenu.addTreeContextMenuListener(e -> {
        treeContextMenu.removeItems();
        //The path is /resources/images/kitten.jpg
        ClassResource ico = new ClassResource("/images/kitten.jpg");
        treeContextMenu.addItem("Who?",ico, menuItem -> Notification.show(e.getItem()));
    });

    layout.addComponent(tree);
}
 
Example 11
Source Project: gantt   Source File: Util.java    License: Apache License 2.0 6 votes vote down vote up
public static TextField createNumberEditor(String caption, float value, final Component component,
        final NumberValueChange valueChange) {
    TextField field = new TextField(caption);
    field.setMaxLength(5);
    field.setValue("" + value);
    field.addValueChangeListener(new ValueChangeListener<String>() {

        @Override
        public void valueChange(ValueChangeEvent<String> event) {
            Object v = event.getValue();
            try {
                float f = Float.parseFloat("" + v);
                valueChange.onValueChange(f);
            } catch (NumberFormatException e) {
                Notification.show("Invalid floating number! Format is 123.345");
            }
        }
    });
    return field;
}
 
Example 12
Source Project: serverside-elements   Source File: Html5InputDemo.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Component getDemoView() {
    input.bindAttribute("value", "change");
    input.addEventListener("change", arguments -> {
        Notification
                .show("Value changed to " + input.getAttribute("value"));
    });

    typeSelector.setEmptySelectionAllowed(false);
    typeSelector.addValueChangeListener(event -> {
        String type = String.valueOf(typeSelector.getValue());

        input.setAttribute("value", "");
        input.setAttribute("type", type);

        playground.setCaption("input type=" + type);
    });
    typeSelector.setValue("range");

    Root root = ElementIntegration.getRoot(playground);
    root.appendChild(input);
    HorizontalLayout layout = new HorizontalLayout(typeSelector,
            playground);
    layout.setSpacing(true);
    return layout;
}
 
Example 13
Source Project: viritin   Source File: UploadFileHandlerExample.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Component getTestComponent() {
    UploadFileHandler uploadFileHandler = new UploadFileHandler(
            (InputStream content, String fileName, String mimeType) -> {
                try {
                    int b = 0;
                    int count = 0;
                    while ((b = content.read()) != -1) {
                        if (b == "\n".getBytes()[0]) {
                            count++;
                        }
                    }
                    String msg = "Counted " + count + " lines";
                    getUI().access(() -> Notification.show(msg));
                } catch (IOException ex) {
                    Logger.getLogger(UploadFileHandlerExample.class.getName()).log(Level.SEVERE, null, ex);
                }
            });
    return uploadFileHandler;
}
 
Example 14
Source Project: viritin   Source File: Issue131.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Component getTestComponent() {
    Member m = new Member();
    m.initials = "MT";
    m.lastName = "Tahvonen";
    final MemberForm2 memberForm2 = new MemberForm2(m);
    memberForm2.setSavedHandler(new AbstractForm.SavedHandler<Member>() {
        private static final long serialVersionUID = -4100482203816246947L;

        @Override
        public void onSave(Member entity) {
            Notification.show(entity.toString());
        }
    });
    return memberForm2;
}
 
Example 15
Source Project: viritin   Source File: ElementCollectionWithPopupEditor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Component getTestComponent() {
    PersonFormManualAddressAddition form = new PersonFormManualAddressAddition();

    Person p = Service.getPerson();
    form.setEntity(p);

    form.setSavedHandler(new AbstractForm.SavedHandler<Person>() {

        private static final long serialVersionUID = 5522176287160062623L;

        @Override
        public void onSave(Person entity) {
            Notification.show(entity.toString());
        }
    });

    return new MVerticalLayout(form);
}
 
Example 16
Source Project: viritin   Source File: EditDude.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Component getTestComponent() {
    DudeForm form = new DudeForm();

    Dude p = new Dude();
    p.setFirstName("Jorma");
    p.setAge(80);
    p.getAddress().setStreet("Ruukinkatu");
    form.setEntity(p);

    form.setSavedHandler(new AbstractForm.SavedHandler<Dude>() {
        private static final long serialVersionUID = 6646955460224852274L;

        @Override
        public void onSave(Dude entity) {
            Notification.show(entity.toString());
        }
    });

    return new MVerticalLayout(form);
}
 
Example 17
Source Project: viritin   Source File: ElementCollections2.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Component getTestComponent() {
    PersonFormManualAddressAddition form = new PersonFormManualAddressAddition();

    Person p = Service.getPerson();
    form.setEntity(p);

    form.setSavedHandler(new AbstractForm.SavedHandler<Person>() {
        private static final long serialVersionUID = 1008970415395369248L;

        @Override
        public void onSave(Person entity) {
            Notification.show(entity.toString());
        }
    });


    return new MVerticalLayout(form);
}
 
Example 18
@Override
public Component getTestComponent() {
    
    strings.setOptions(Arrays.asList(options));
    strings.withColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
    strings.withRowHeaderMode(Table.RowHeaderMode.ID);
    strings.withProperties();
    
    final Beani beani = new Beani();
    
    MBeanFieldGroup.bindFieldsUnbuffered(beani, this);
    
    
    Button showValue = new Button("show value", new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Notification.show(beani.toString());
        }
    });
    
    return new MVerticalLayout(strings, showValue);
}
 
Example 19
Source Project: cuba   Source File: WebNotifications.java    License: Apache License 2.0 5 votes vote down vote up
protected void setNotificationDelayMsec(com.vaadin.ui.Notification notification, NotificationType type) {
    if (type == NotificationType.HUMANIZED) {
        notification.setDelayMsec(HUMANIZED_NOTIFICATION_DELAY_MSEC);
    } else if (type == NotificationType.WARNING) {
        notification.setDelayMsec(WARNING_NOTIFICATION_DELAY_MSEC);
    }
}
 
Example 20
Source Project: cuba   Source File: App.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Removes all windows in the given {@code uis}.
 *
 * @param uis {@link AppUI} instances
 */
protected void removeAllWindows(List<AppUI> uis) {
    log.debug("Closing all windows in all UIs");
    try {
        for (AppUI ui : uis) {
            Screens screens = ui.getScreens();
            if (screens != null) {
                Screen rootScreen = screens.getOpenedScreens().getRootScreenOrNull();
                if (rootScreen != null) {
                    screens.removeAll();

                    screens.remove(rootScreen);
                }
            }

            // also remove all native Vaadin windows, that is not under CUBA control
            Window[] windows = ui.getWindows().toArray(new Window[0]);

            for (com.vaadin.ui.Window win : windows) {
                ui.removeWindow(win);
            }

            List<Notification> notifications = ui.getExtensions()
                    .stream()
                    .filter(ext -> ext instanceof Notification)
                    .map(ext -> (Notification) ext)
                    .collect(Collectors.toList());

            notifications.forEach(Notification::close);

        }
    } catch (Throwable e) {
        log.error("Error closing all windows", e);
    }
}
 
Example 21
Source Project: jpa-invoicer   Source File: InvoicesView.java    License: The Unlicense 5 votes vote down vote up
@PostConstruct
public void initComponent() {
    table.setColumnCollapsingAllowed(true);
    table.setColumnWidth("invoiceDate", 105);
    table.setColumnWidth("lastEdited", 105);
    table.setColumnWidth("lastEditor", 110);
    if (session.getUser().getAdministrates().isEmpty()) {
        Notification.show("Add invoicer first!");
        ViewMenuUI.getMenu().navigateTo(MyAccount.class);
        return;
    }
    sender.addMValueChangeListener(e -> listEntities());

    form.setResetHandler(this::reset);
    form.setSavedHandler(this::save);

    table.addMValueChangeListener(e -> {
        if (e.getValue() != null) {
            form.setEntity(e.getValue());
            form.openInModalPopup();
        }
    });

    listEntities();

    Button addButton = new Button("Add", e -> {
        final Invoice invoice = facade.createFor(sender.getValue());
        form.setEntity(invoice);
        form.openInModalPopup();
    });

    add(
            new MHorizontalLayout(addButton, sender).space().add(backup)
            .alignAll(Alignment.MIDDLE_LEFT)
    );
    expand(table);
}
 
Example 22
Source Project: jpa-invoicer   Source File: InvoicesView.java    License: The Unlicense 5 votes vote down vote up
private void sendInvoiceClicked(final Invoice invoice) {
    try {
        facade.sendInvoice(invoice);
        Notification.show("Invoice sent");
    } catch (EmailException | IOException e) {
        e.printStackTrace();
        Notification.show("Error sending the invoice",
                Notification.Type.ERROR_MESSAGE);
    }
}
 
Example 23
@Override
public final void buttonClick(final ClickEvent event) {
	final DisableGoogleAuthenticatorCredentialResponse response = (DisableGoogleAuthenticatorCredentialResponse) getApplicationManager().service(googleAuthRequest);

	if (ServiceResult.FAILURE == response.getResult()) {
		showNotification(PROBLEM_DISABLE_GOOGLE_AUTHENTICATOR, ERROR_MESSAGE, Notification.Type.WARNING_MESSAGE);
		LOGGER.info(PROBLEM_DISABLE_GOOGLE_AUTHENTICATOR_SESSIONID, googleAuthRequest.getSessionId());
	}
}
 
Example 24
@Override
public final void buttonClick(final ClickEvent event) {
	final ServiceResponse response = getApplicationManager().service(request);
	if (ServiceResult.SUCCESS == response.getResult()) {
		LOGGER.info(LOG_UPDATE_APPLICATION_CONFIGURATION,request.getApplicationConfigurationId());

		UI.getCurrent().getNavigator().navigateTo(AdminViews.ADMIN_APPLICATIONS_CONFIGURATION_VIEW_NAME + "/" + request.getApplicationConfigurationId());

	} else {
		showNotification(UPDATE_APPLICATION_CONFIGURATION_FAILED,
                  ERROR_MESSAGE,
                  Notification.Type.WARNING_MESSAGE);
		LOGGER.info(LOG_MSG_UPDATE_APPLICATION_CONFIGURATION_FAILURE,request.getApplicationConfigurationId());
	}
}
 
Example 25
Source Project: cia   Source File: ApplicationLoginListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void buttonClick(final ClickEvent event) {
	final LoginResponse response = (LoginResponse) getApplicationManager().service(loginRequest);
	if (ServiceResult.SUCCESS == response.getResult()) {
		LOGGER.info(LOG_MSG_LOGIN_REQUEST,loginRequest.getEmail());

		UI.getCurrent().getNavigator().navigateTo(UserViews.USERHOME_VIEW_NAME);
	} else {
		showNotification(LOGIN_FAILED,
				response.getErrorMessage(),
                  Notification.Type.WARNING_MESSAGE);
		LOGGER.info(LOG_MSG_LOGIN_REQUEST_FAILURE,loginRequest.getEmail());
	}		
}
 
Example 26
Source Project: cia   Source File: RegisterUserClickListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void buttonClick(final ClickEvent event) {
	final ServiceResponse response = getApplicationManager().service(reqisterRequest);
	if (ServiceResult.SUCCESS == response.getResult()) {
		LOGGER.info(LOG_MSG_REGISTER_USER,reqisterRequest.getUsername());
		UI.getCurrent().getNavigator().navigateTo(UserViews.USERHOME_VIEW_NAME);
	} else {
		showNotification(REGISTER_FAILED,
				response.getErrorMessage(),
                  Notification.Type.WARNING_MESSAGE);
		LOGGER.info(REGISTER_USER_FAILURE,reqisterRequest.getUsername());
	}
}
 
Example 27
Source Project: cia   Source File: ChangePasswordClickListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final void buttonClick(final ClickEvent event) {
	final ChangePasswordResponse response = (ChangePasswordResponse) getApplicationManager().service(changePasswordRequest);

	if (ServiceResult.FAILURE == response.getResult()) {
		showNotification(PROBLEM_CHANGING_PASSWORD, response.getErrorMessage(), Notification.Type.WARNING_MESSAGE);
		LOGGER.info(PROBLEM_CHANGING_PASSWORD_SESSIONID, changePasswordRequest.getSessionId());
	}
}
 
Example 28
Source Project: cia   Source File: SendEmailClickListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final void buttonClick(final ClickEvent event) {
	final ServiceResponse response = getApplicationManager().service(sendEmailRequest);
	if (ServiceResult.SUCCESS == response.getResult()) {
		LOGGER.info(LOG_MSG_SEND_EMAIL,sendEmailRequest.getEmail());
		showNotification(EMAIL_SENT, "desc", Notification.Type.HUMANIZED_MESSAGE);
	} else {
		showNotification(SEND_EMAIL_FAILEDFAILED,
                  response.getErrorMessage(),
                  Notification.Type.WARNING_MESSAGE);
		LOGGER.info(SEND_EMAIL_FAILURE,sendEmailRequest.getEmail());
	}
}
 
Example 29
Source Project: cia   Source File: ManageUserAccountClickListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final void buttonClick(final ClickEvent event) {
	final ServiceResponse response = getApplicationManager().service(manageUserAccountRequest);
	if (ServiceResult.SUCCESS == response.getResult()) {
		LOGGER.info(LOG_MSG,manageUserAccountRequest.getUserAcountId());
		showNotification(OPERATION_COMPLETED, "desc", Notification.Type.HUMANIZED_MESSAGE);
	} else {
		showNotification(OPERATION_FAILED,
                  response.getErrorMessage(),
                  Notification.Type.WARNING_MESSAGE);
		LOGGER.info(OPERATION_FAILURE,manageUserAccountRequest.getUserAcountId());
	}
}
 
Example 30
Source Project: XACML   Source File: PolicyWorkspace.java    License: MIT License 5 votes vote down vote up
protected void	renamePolicy(final File policy) {
	//
	// Run the rename window
	//
	final RenamePolicyFileWindow window = new RenamePolicyFileWindow(policy.getName());
	window.setCaption("Rename Policy");
	window.setModal(true);
	window.addCloseListener(new CloseListener() {
		private static final long serialVersionUID = 1L;
		
		@Override
		public void windowClose(CloseEvent event) {
			String newFilename = window.getNewFilename();
			if (newFilename == null) {
				//
				// User cancelled
				//
				return;
			}
			Path newPolicy = Paths.get(policy.getParent(), newFilename);
			if (Files.exists(newPolicy)) {
				Notification.show("Cannot rename to an existing file", Notification.Type.ERROR_MESSAGE);
				return;
			}
			try {
				if (policy.renameTo(newPolicy.toFile()) == false) {
					throw new Exception("No known error, rename failed");
				}
				self.treeContainer.updateItem(newPolicy.getParent().toFile());
			} catch (Exception e) {
				Notification.show("Failed to rename file: " + e.getLocalizedMessage());
			}
		}
	});
	window.center();
	UI.getCurrent().addWindow(window);
}