Example usage for com.vaadin.ui Notification Notification

List of usage examples for com.vaadin.ui Notification Notification

Introduction

In this page you can find the example usage for com.vaadin.ui Notification Notification.

Prototype

public Notification(String caption, String description) 

Source Link

Document

Creates a "humanized" notification message with a bigger caption and smaller description.

Usage

From source file:annis.gui.components.HelpButton.java

License:Apache License

@Override
public void buttonClick(ClickEvent event) {
    String caption = "Help";
    if (getCaption() != null && !getCaption().isEmpty()) {
        caption = "Help for \"" + getCaption();
    }/*from  www.  ja v  a2  s  .c  o m*/
    caption = caption + "<br/><br/>(Click here to close)";
    Notification notify = new Notification(caption, Notification.Type.HUMANIZED_MESSAGE);
    notify.setHtmlContentAllowed(true);
    notify.setDescription(field.getDescription());
    notify.setDelayMsec(-1);
    notify.show(UI.getCurrent().getPage());
}

From source file:ch.bfh.blue.UI.RegisterView.java

License:Open Source License

/**
 * configure handlers and settings for the buttons here
 *///from   w ww.ja v a  2 s .c  om
private void configureButtons() {
    buttonBar.addComponents(homeBtn, registerBtn);
    //buttonBar.setMargin(true);
    buttonBar.setSpacing(true);

    registerBtn.addClickListener(e -> {
        if (passwd.getValue().equals(retypepw.getValue())) {
            controller.createPerson(email.getValue(), user.getValue(), passwd.getValue());
            navigator.navigateTo("home");
            Notification notif = new Notification(REGISTRATION_SUCCESS, Notification.Type.WARNING_MESSAGE);
            notif.setDelayMsec(3500);
            notif.show(Page.getCurrent());
        } else {
            notif.setCaption(REGISTRATION_FAIL_PW_MISSMATCH);
            notif.show(Page.getCurrent());
        }

    });

    homeBtn.addClickListener(e -> {
        navigator.navigateTo("home");
    });
}

From source file:ch.bfh.ti.soed.hs16.srs.black.view.loginView.LoginController.java

License:Open Source License

public void login(Button.ClickEvent event) {
    String userName = loginView.getUsernameField().getValue();
    String password = loginView.getPasswordField().getValue();

    try {//from   w w  w. j  a v  a 2 s . c  om
        Customer customer = dataModel.getCustomer(userName);
        if (customer.getPassword().equals(password)) {
            // Store the current user in the service session
            VaadinSession.getCurrent().setAttribute("user", userName);

            // Navigate to the reservation view
            navigator.navigateTo(ReservationView.NAME);

            // Clear the fields of the login view
            loginView.getUsernameField().clear();
            loginView.getPasswordField().clear();
        } else {
            throw new AuthenticationException();
        }
    } catch (Exception e) {
        Notification accessDeniedNf = new Notification("Access Denied!",
                "Please enter a valid username/password combination.");
        accessDeniedNf.show(Page.getCurrent());
        accessDeniedNf.setDelayMsec(2000);
        loginView.getPasswordField().clear();
        loginView.getPasswordField().focus();
    }
}

From source file:com.github.daytron.twaattin.presenter.LoginBehaviour.java

License:Open Source License

@Override
public void buttonClick(Button.ClickEvent event) {
    try {//from   www  . ja  v  a2 s  .  co m
        String pin = loginField.getValue();

        Principal user = new TwitterAuthenticationStrategy().authenticate(pin);

        VaadinSession.getCurrent().setAttribute(Principal.class, user);

        TimelineScreen aTimelineScreen = new TimelineScreen();
        UI.getCurrent().setContent(aTimelineScreen);

        Notification authenticatedNotification = new Notification("You're now authenticated to Twaattin!",
                Notification.Type.TRAY_NOTIFICATION);
        authenticatedNotification.setPosition(Position.TOP_CENTER);
        authenticatedNotification.show(Page.getCurrent());

    } catch (AuthenticationException e) {
        Notification errorNotification = new Notification(e.getMessage(), "Cick this box to close.",
                Notification.Type.ERROR_MESSAGE);
        errorNotification.show(Page.getCurrent());
    }
}

From source file:com.github.daytron.twaattin.presenter.LogoutBehaviour.java

License:Open Source License

@Override
public void buttonClick(Button.ClickEvent event) {
    VaadinSession.getCurrent().setAttribute(Principal.class, null);

    UI.getCurrent().setContent(new LoginScreen());

    Notification logoutNotification = new Notification("You've been logout",
            Notification.Type.TRAY_NOTIFICATION);
    logoutNotification.setPosition(Position.TOP_CENTER);
    logoutNotification.show(Page.getCurrent());
}

From source file:com.haulmont.cuba.web.LoginWindow.java

License:Apache License

protected void login() {
    String login = loginField.getValue();
    String password = passwordField.getValue() != null ? passwordField.getValue() : "";

    if (StringUtils.isEmpty(login) || StringUtils.isEmpty(password)) {
        String message = messages.getMainMessage("loginWindow.emptyLoginOrPassword", resolvedLocale);
        Notification notification = new Notification(message, Type.WARNING_MESSAGE);
        notification.setDelayMsec(WebWindowManager.WARNING_NOTIFICATION_DELAY_MSEC);
        notification.show(ui.getPage());
        return;/*  w  ww.  j av a  2 s.  c om*/
    }

    if (!bruteForceProtectionCheck(login, app.getClientAddress())) {
        return;
    }

    try {
        Locale locale = getUserLocale();
        app.setLocale(locale);

        PasswordEncryption passwordEncryption = AppBeans.get(PasswordEncryption.NAME);

        if (loginByRememberMe && rememberMeAllowed) {
            loginByRememberMe(login, password, locale);
        } else if (configuration.getConfig(WebAuthConfig.class).getExternalAuthentication()) {
            // try to login as externally authenticated user, fallback to regular authentication
            // we use resolved locale for error messages
            if (authenticateExternally(login, password, resolvedLocale)) {
                login = convertLoginString(login);

                ((ExternallyAuthenticatedConnection) connection).loginAfterExternalAuthentication(login,
                        locale);
            } else {
                login(login, passwordEncryption.getPlainHash(password), locale);
            }
        } else {
            login(login, passwordEncryption.getPlainHash(password), locale);
        }
        // locale could be set on the server
        if (connection.getSession() != null) {
            app.setLocale(connection.getSession().getLocale());
            if (globalConfig.getLocaleSelectVisible()) {
                app.addCookie(COOKIE_LOCALE, locale.toLanguageTag());
            }
        }
    } catch (LoginException e) {
        log.info("Login failed: {}", e.toString());

        String message = StringUtils.abbreviate(e.getMessage(), 1000);
        String bruteForceMsg = registerUnsuccessfulLoginAttempt(login, app.getClientAddress());
        if (!Strings.isNullOrEmpty(bruteForceMsg)) {
            message = bruteForceMsg;
        }
        showLoginException(message);
    } catch (Exception e) {
        log.warn("Unable to login", e);
        showException(e);
    }
}

From source file:com.haulmont.cuba.web.WebWindowManager.java

License:Apache License

@Override
protected void checkCanOpenWindow(WindowInfo windowInfo, OpenType openType, Map<String, Object> params) {
    if (openType.getOpenMode() != OpenMode.NEW_TAB && openType.getOpenMode() != OpenMode.NEW_WINDOW) {
        return;/*from   w ww  . ja  v a 2 s.  c om*/
    }

    if (!windowInfo.getMultipleOpen() && getWindow(getHash(windowInfo, params)) != null) {
        //window is already open
        return;
    }

    int maxCount = webConfig.getMaxTabCount();
    if (maxCount > 0 && maxCount <= tabs.size()) {
        Notification notification = new Notification(
                messages.formatMainMessage("tooManyOpenTabs.message", maxCount),
                Notification.Type.WARNING_MESSAGE);
        notification.setDelayMsec(WARNING_NOTIFICATION_DELAY_MSEC);
        notification.show(ui.getPage());

        throw new SilentException();
    }
}

From source file:com.jain.addon.component.upload.JUploader.java

License:Apache License

protected void interruptUpload() {
    upload.interruptUpload();/*  ww w .j  a va 2s  .  c om*/
    I18NProvider provider = ((I18NUI) getUI()).getI18nProvider();
    Notification n = new Notification(provider.getTitle(getLocale(), interruptionMessage),
            Type.TRAY_NOTIFICATION);
    n.setPosition(Position.MIDDLE_CENTER);
    n.setDescription(provider.getMessage(getLocale(), interruptionMessage));
    n.show(getUI().getPage());
    pi.setVisible(false);
    upload.setVisible(true);
}

From source file:com.jain.addon.helper.JNHelper.java

License:Apache License

/**
 * Method to create Notification/*from   w w  w.  j  a v a 2 s.c o m*/
 * @param currentUI
 * @param title
 * @param message
 * @param params
 * @return Notification
 */
public static Notification createNotification(UI currentUI, String title, String message, Object... params) {
    I18NProvider provider = null;
    if (currentUI instanceof I18NUI)
        provider = ((I18NUI) currentUI).getI18nProvider();
    else
        provider = DefaultI18NResourceProvider.instance();

    Notification notification = new Notification(provider.getTitle(currentUI.getLocale(), title, params),
            Notification.Type.TRAY_NOTIFICATION);
    notification.setPosition(Position.MIDDLE_CENTER);
    notification.setDescription(provider.getMessage(currentUI.getLocale(), message, params));
    return notification;
}

From source file:com.jain.common.VaadinHelper.java

License:Apache License

public static Notification createNotificationMessage(String title, String message, Object... params) {
    I18NProvider provider = DefaultI18NResourceProvider.instance();
    AuthenticatedUser currentUser = CDIComponent.getInstance(AuthenticatedUser.class);
    Notification n = new Notification(provider.getTitle(currentUser.getLocale(), title, params),
            Notification.Type.TRAY_NOTIFICATION);
    n.setPosition(Position.MIDDLE_CENTER);
    n.setDescription(provider.getMessage(currentUser.getLocale(), message, params));
    return n;/*from   w w  w.  j a  va  2s . co m*/
}