Example usage for com.vaadin.ui Notification show

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

Introduction

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

Prototype

public static Notification show(String caption) 

Source Link

Document

Shows a notification message on the middle of the current page.

Usage

From source file:annis.gui.SearchView.java

License:Apache License

@Override
public void notifyCannotPlayMimeType(String mimeType) {
    if (mimeType == null) {
        return;//from   ww  w. j a  v  a2 s .c  om
    }

    if (mimeType.startsWith("audio/ogg") || mimeType.startsWith("video/web")) {
        String browserList = "<ul>"
                + "<li>Mozilla Firefox: <a href=\"http://www.mozilla.org/firefox\" target=\"_blank\">http://www.mozilla.org/firefox</a></li>"
                + "<li>Google Chrome: <a href=\"http://www.google.com/chrome\" target=\"_blank\">http://www.google.com/chrome</a></li>"
                + "</ul>";

        WebBrowser browser = Page.getCurrent().getWebBrowser();

        // IE9 users can install a plugin
        Set<String> supportedByIE9Plugin = new HashSet<>();
        supportedByIE9Plugin.add("video/webm");
        supportedByIE9Plugin.add("audio/ogg");
        supportedByIE9Plugin.add("video/ogg");

        if (browser.isIE() && browser.getBrowserMajorVersion() >= 9
                && supportedByIE9Plugin.contains(mimeType)) {
            Notification n = new Notification("Media file type unsupported by your browser",
                    "Please install the WebM plugin for Internet Explorer 9 from "
                            + "<a target=\"_blank\" href=\"https://tools.google.com/dlpage/webmmf\">https://tools.google.com/dlpage/webmmf</a> "
                            + " or use a browser from the following list "
                            + "(these are known to work with WebM or OGG files)<br/>" + browserList
                            + "<br/><br /><strong>Click on this message to hide it</strong>",
                    Notification.Type.WARNING_MESSAGE, true);
            n.setDelayMsec(15000);

            n.show(Page.getCurrent());
        } else {
            Notification n = new Notification("Media file type unsupported by your browser",
                    "Please use a browser from the following list "
                            + "(these are known to work with WebM or OGG files)<br/>" + browserList
                            + "<br/><br /><strong>Click on this message to hide it</strong>",
                    Notification.Type.WARNING_MESSAGE, true);
            n.setDelayMsec(15000);
            n.show(Page.getCurrent());
        }
    } else {
        Notification.show("Media file type \"" + mimeType + "\" unsupported by your browser!",
                "Try to check your browsers documentation how to enable "
                        + "support for the media type or inform the corpus creator about this problem.",
                Notification.Type.WARNING_MESSAGE);
    }

}

From source file:by.bigvova.backend.MyBackendBean.java

License:Apache License

@Override
public void populateDB() {
    try {/*from  w w w  . java 2s  .  com*/
        ScriptUtils.executeSqlScript(dataSource.getConnection(),
                ctx.getResource("classpath:db/initAndPopulateBigDB.sql"));
        controller.cacheEvict();
        Notification.show("Done!!!");
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

From source file:by.bigvova.MainUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    EventBus.register(this);
    getPage().setTitle("FoodNote");
    UI.getCurrent().setLocale(Locale.forLanguageTag("ru-RU"));
    // Let's register a custom error handler to make the 'access denied' messages a bit friendlier.
    setErrorHandler(new DefaultErrorHandler() {
        @Override/*from ww w.j a  v a 2s.c  o  m*/
        public void error(com.vaadin.server.ErrorEvent event) {
            if (SecurityExceptionUtils.isAccessDeniedException(event.getThrowable())) {
                Notification.show("Sorry, you don't have access to do that.");
            } else {
                super.error(event);
            }
        }
    });
    HorizontalLayout layout = new HorizontalLayout();
    layout.setSizeFull();

    // By adding a security item filter, only views that are accessible to the user will show up in the side bar.
    sideBar.setItemFilter(new VaadinSecurityItemFilter(vaadinSecurity));
    sideBar.setHeader(new CssLayout() {
        {
            Label header = new Label("<span>Food</span>Note", ContentMode.HTML);
            header.setWidth(100, Unit.PERCENTAGE);
            header.setHeightUndefined();
            addComponent(header);
            addComponent(buildUserMenu());
        }
    });
    sideBar.getHeader().setStyleName("branding");
    layout.addComponent(sideBar);

    CssLayout viewContainer = new CssLayout();
    viewContainer.setSizeFull();
    layout.addComponent(viewContainer);
    layout.setExpandRatio(viewContainer, 1f);

    Navigator navigator = new Navigator(this, viewContainer);
    // Without an AccessDeniedView, the view provider would act like the restricted views did not exist at all.
    springViewProvider.setAccessDeniedViewClass(AccessDeniedView.class);
    navigator.addProvider(springViewProvider);
    navigator.setErrorView(ErrorView.class);
    navigator.navigateTo(navigator.getState());

    setContent(layout); // Call this here because the Navigator must have been configured before the Side Bar can be attached to a UI.
}

From source file:by.bigvova.ui.LoginUI.java

License:Apache License

private void notification() {
    Notification notification = new Notification("Welcome to Dashboard Demo");
    notification.setDescription(//from  w w w . j av  a  2  s.  co  m
            "<span>This application is not real, it only demonstrates an application built with the <a href=\"https://vaadin.com\">Vaadin framework</a>.</span> <span>No username or password is required, just click the <b>Sign In</b> button to continue.</span>");
    notification.setHtmlContentAllowed(true);
    notification.setStyleName("tray dark small closable login-help");
    notification.setPosition(Position.BOTTOM_CENTER);
    notification.setDelayMsec(20000);
    notification.show(Page.getCurrent());
}

From source file:by.bigvova.views.AdminView.java

License:Apache License

@Autowired
public AdminView(MyBackend backend) {
    this.backend = backend;
    Button button = new Button("Call admin backend", new Button.ClickListener() {
        @Override/* w w w. ja v  a  2s  .c o  m*/
        public void buttonClick(Button.ClickEvent event) {
            Notification.show(AdminView.this.backend.adminOnlyEcho("Hello Admin World!"));
        }
    });
    setCompositionRoot(button);
}

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

License:Open Source License

/**
 * configure handlers and settings for the buttons here
 *///w  ww. ja va  2  s .  c o  m
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  ww  .ja v a2s .  c o m*/
        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:ch.bfh.ti.soed.hs16.srs.black.view.reservationView.ReservationController.java

License:Open Source License

public ReservationController(DataModel dataModel, ReservationView reservationView, Navigator navigator) {
    this.dataModel = dataModel;
    this.reservationView = reservationView;
    this.navigator = navigator;

    reservationView.getLogoutButton().addClickListener(clickEvent -> {
        // Logout the user / end the session
        VaadinSession.getCurrent().setAttribute("user", null);

        // Refresh this view, the navigator should redirect to login view$
        navigator.navigateTo(LoginView.NAME);
    });/*from w w w.  j  a  va 2s .c om*/

    reservationView.getRoomSelect()
            .addValueChangeListener(e -> roomNumber = Integer.parseInt(e.getProperty().getValue().toString()));

    for (int i = 1; i < dataModel.getRooms().size() + 1; i++) {
        reservationView.getRoomSelect().addItem(i);
        reservationView.getRoomSelect().setItemCaption(i, "Room " + i);
    }

    reservationView.getMakeReservationButton().addClickListener(clickEvent -> {
        Date begin = reservationView.getFromField().getValue();
        Date end = reservationView.getToField().getValue();
        SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm");
        Notification notification = new Notification("");
        notification.setDelayMsec(2000);
        String username = String.valueOf(VaadinSession.getCurrent().getAttribute("user"));

        try {
            Customer customer = dataModel.getCustomer(username);
            Room room = dataModel.getRoom(roomNumber);
            dataModel.addReservation(customer, room, begin, end);
            notification.setCaption("Success");
            notification.setDescription("Added reservation for: " + username + ", Room Nr.: " + roomNumber
                    + ", From: " + df.format(begin) + " until " + df.format(end));
            notification.show(Page.getCurrent());
            try {
                createList(username);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (IllegalArgumentException iae) {
            notification.setCaption("Error!");
            notification.setDescription("Please check the entries you made for your reservation.");
            notification.show(Page.getCurrent());
        } catch (RuntimeException re) {
            notification.setCaption("Error!");
            notification.setDescription("Room couldn't be found.\nCurrently available rooms: "
                    + dataModel.getRooms().stream().map(Object::toString).collect(Collectors.joining(", "))
                            .replaceAll("[^\\d , ][^\\@]*\\@", ""));
            notification.show(Page.getCurrent());
        } catch (Exception e) {
            notification.setCaption("Error!");
            notification.setDescription("There already exists a reservation for the chosen time range.");
            notification.show(Page.getCurrent());
        }
    });

    reservationView.getLogoutButton().addClickListener(clickEvent -> {
        reservationView.getFromField().clear();
        reservationView.getToField().clear();
        reservationView.getRoomSelect().clear();
    });
}

From source file:ch.bfh.ti.soed.hs16.srs.black.view.signUpView.SignUpController.java

License:Open Source License

public void addUser(Button.ClickEvent event) {
    String username = signUpView.getUsernameField().getValue();
    String password = signUpView.getPasswordField().getValue();
    String passwordRepeat = signUpView.getPasswordFieldRepeat().getValue();
    Notification alertNf = new Notification("");
    alertNf.setDelayMsec(2000);/* w  w w. j  a v a2 s.  com*/

    if (username.isEmpty() || password.isEmpty() || passwordRepeat.isEmpty()) {
        alertNf.setCaption("Please fill out the complete form!");
        alertNf.show(Page.getCurrent());
    } else if (!password.equals(passwordRepeat)) {
        alertNf.setCaption("The given passwords aren't identical!");
        alertNf.show(Page.getCurrent());
        signUpView.getPasswordFieldRepeat().clear();
        signUpView.getPasswordFieldRepeat().focus();
    } else {
        try {
            dataModel.addCustomer(username, password);
            navigator.navigateTo(ReservationView.NAME);
            alertNf.setCaption("Account: " + username + " has been successfully created.");
            alertNf.setDescription("You can now login with your credentials.");
            alertNf.show(Page.getCurrent());
        } catch (IllegalStateException e) {
            alertNf.setCaption("User already exists!");
            alertNf.setDescription("Please enter a different username.");
            alertNf.show(Page.getCurrent());
            signUpView.getUsernameField().focus();
        } finally {
            signUpView.getUsernameField().clear();
            signUpView.getPasswordField().clear();
            signUpView.getPasswordFieldRepeat().clear();
        }
    }
}

From source file:ch.bfh.ti.soed.hs16.srs.yellow.views.LoginView.java

License:Open Source License

public LoginView() {

    setSizeFull();/*from  w w  w.j  ava 2s  . c  o m*/

    lUName.setRequired(true);
    lPwd.setRequired(true);

    lUName.setSizeFull();
    lPwd.setSizeFull();
    lLoginBtn.setSizeFull();

    loginFormLayout.addComponents(lUName, lPwd, lLoginBtn);
    loginFormLayout.setMargin(true);
    loginFormLayout.setWidth(500, Sizeable.Unit.PIXELS);

    lHeader.addComponent(lbackBtn);

    lbackBtn.addClickListener(e -> {
        navigationRoot.navigator.navigateTo(NavigationRoot.MAINVIEW);
    });

    lLoginBtn.addClickListener(evt -> {
        Long cID = jpaProxyDataAccessor.authentifyCustomer(lUName.getValue(), lPwd.getValue());
        if (cID != null) {
            Notification.show("Successfully authentified");
            lbackBtn.click();
        } else {
            Notification.show("Sorry, could not authentify. Please check your credentials one more time");
        }
    });

    loginVLayout.addComponents(lHeader, loginFormLayout);
    loginVLayout.setSpacing(true);
    loginVLayout.setComponentAlignment(loginFormLayout, Alignment.MIDDLE_CENTER);
    loginVLayout.setComponentAlignment(lHeader, Alignment.TOP_RIGHT);

    setCompositionRoot(loginVLayout);
}