Example usage for com.vaadin.ui Notification setDelayMsec

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

Introduction

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

Prototype

public void setDelayMsec(int delayMsec) 

Source Link

Document

Sets the delay before the notification disappears.

Usage

From source file:edu.vserver.exercises.videoMcq.QuestionWindow.java

License:Apache License

/**
 * Sets a Notification about the correctness of the given answer to the browser window.
 * /*from   w ww  . ja  v  a2s . c  o  m*/
 * @param question latest answered question.
 */
private void informUser(Question question) {
    if (this.isInformative()) {
        Notification n;
        if (question.isCorrectAnswer()) {
            n = new Notification("CORRECT", Notification.Type.HUMANIZED_MESSAGE);
            n.setIcon(new ThemeResource(SPH_Theme.CORRECT_ICON_48PX));
            n.setStyleName("correctAnswer");
        } else {
            n = new Notification("INCORRECT", Notification.Type.HUMANIZED_MESSAGE);
            n.setIcon(new ThemeResource(SPH_Theme.INCORRECT_ICON_48PX));
            n.setStyleName("incorrectAnswer");
        }
        if (question.containsAnswerDescription()) {
            n.setDescription(question.getAnswerDescription());
            n.setDelayMsec(Notification.DELAY_FOREVER);
        } else {
            n.setDelayMsec(500);
        }
        n.setPosition(com.vaadin.shared.Position.MIDDLE_CENTER);
        n.show(Page.getCurrent());
    }

}

From source file:eu.maxschuster.vaadin.autocompletetextfield.demo.DemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    setContent(l);/*from ww  w .  j  a v  a2s . c om*/

    final AutocompleteTextField languageField = l.languageField.withSuggestionProvider(languageProvider)
            .withMinChars(1).withSuggestionLimit(5).withTextChangeListener(this::onAutocompleteTextChange)
            .withValueChangeListener(this::onAutocompleteValueChange);

    l.scrollBehavior.setContainerDataSource(
            new BeanItemContainer<>(ScrollBehavior.class, Arrays.asList(ScrollBehavior.values())));

    l.theme.addItems(Arrays.asList(Themes.values()));
    l.theme.setValue(Themes.VALO);
    l.theme.addValueChangeListener(this::onThemeValueChange);

    l.addIcon.addItems(Arrays.asList(Icons.values()));
    l.addIcon.setValue(Icons.NONE);

    l.visible.setValue(true);
    l.visible.addValueChangeListener(e -> {
        languageField.setVisible((boolean) e.getProperty().getValue());
    });

    l.enabled.setValue(true);
    l.enabled.addValueChangeListener(e -> {
        languageField.setEnabled((boolean) e.getProperty().getValue());
    });

    optionsGroup.setItemDataSource(languageField);
    optionsGroup.bind(l.delay, "delay");
    optionsGroup.bind(l.minChars, "minChars");
    optionsGroup.bind(l.suggestionLimit, "suggestionLimit");
    optionsGroup.bind(l.inputPrompt, "inputPrompt");
    optionsGroup.bind(l.scrollBehavior, "scrollBehavior");
    optionsGroup.bind(l.cache, "cache");

    l.apply.addClickListener(e -> {
        try {
            optionsGroup.commit();
        } catch (FieldGroup.CommitException ex) {
            getLogger().log(Level.SEVERE, null, ex);
            Notification notification = new Notification("Error applying changes!",
                    Notification.Type.ERROR_MESSAGE);
            notification.setDelayMsec(2000);
            notification.show(Page.getCurrent());
        }
    });

    l.reset.addClickListener(e -> reset());

    optionsGroup.addCommitHandler(new FieldGroup.CommitHandler() {
        @Override
        public void preCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException {

        }

        @Override
        public void postCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException {
            Notification.show("Options applied!");
        }
    });

    l.windowTest.addClickListener(e -> openTestWindow());

    l.demoOverlayTest.setSuggestionProvider(languageProvider);

}

From source file:facs.components.BookAdmin.java

License:Open Source License

private void showErrorNotification(String title, String description) {
    Notification notify = new Notification(title, description);
    notify.setDelayMsec(15000);
    notify.setPosition(Position.TOP_CENTER);
    notify.setIcon(FontAwesome.FROWN_O);
    notify.setStyleName(ValoTheme.NOTIFICATION_ERROR + " " + ValoTheme.NOTIFICATION_CLOSABLE);
    notify.show(Page.getCurrent());/*  w w  w  . ja v a2 s. c  o  m*/
}

From source file:facs.components.BookAdmin.java

License:Open Source License

private void Notification(String title, String description, String type) {
    Notification notify = new Notification(title, description);
    notify.setPosition(Position.TOP_CENTER);
    if (type.equals("error")) {
        notify.setDelayMsec(16000);
        notify.setIcon(FontAwesome.FROWN_O);
        notify.setStyleName(ValoTheme.NOTIFICATION_ERROR + " " + ValoTheme.NOTIFICATION_CLOSABLE);
    } else if (type.equals("success")) {
        notify.setDelayMsec(8000);/* w  w  w.  j  a v a 2s.  c o  m*/
        notify.setIcon(FontAwesome.SMILE_O);
        notify.setStyleName(ValoTheme.NOTIFICATION_SUCCESS + " " + ValoTheme.NOTIFICATION_CLOSABLE);
    } else {
        notify.setDelayMsec(8000);
        notify.setIcon(FontAwesome.MEH_O);
        notify.setStyleName(ValoTheme.NOTIFICATION_TRAY + " " + ValoTheme.NOTIFICATION_CLOSABLE);
    }
    notify.show(Page.getCurrent());
}

From source file:facs.components.Booking.java

License:Open Source License

private void showErrorNotification(String title, String description) {
    Notification notify = new Notification(title, description);
    notify.setDelayMsec(16000);
    notify.setPosition(Position.TOP_CENTER);
    notify.setIcon(FontAwesome.FROWN_O);
    notify.setStyleName(ValoTheme.NOTIFICATION_ERROR + " " + ValoTheme.NOTIFICATION_CLOSABLE);
    notify.show(Page.getCurrent());/*from  w w w. jav a 2 s  .  c  o m*/
}

From source file:facs.components.Booking.java

License:Open Source License

private void showNotification(String title, String description) {
    Notification notify = new Notification(title, description);
    notify.setDelayMsec(8000);
    notify.setPosition(Position.TOP_CENTER);
    notify.setIcon(FontAwesome.MEH_O);//from w  w w.ja va 2  s  . c  o m
    notify.setStyleName(ValoTheme.NOTIFICATION_TRAY + " " + ValoTheme.NOTIFICATION_CLOSABLE);
    notify.show(Page.getCurrent());
}

From source file:facs.components.Booking.java

License:Open Source License

private void showSuccessfulNotification(String title, String description) {
    Notification notify = new Notification(title, description);
    notify.setDelayMsec(8000);
    notify.setPosition(Position.TOP_CENTER);
    notify.setIcon(FontAwesome.SMILE_O);
    notify.setStyleName(ValoTheme.NOTIFICATION_SUCCESS + " " + ValoTheme.NOTIFICATION_CLOSABLE);
    notify.show(Page.getCurrent());// www.  jav  a2  s.  co m
}

From source file:fi.aalto.drumbeat.drumbeatUI.DrumbeatFileHandler.java

License:Open Source License

public OutputStream receiveUpload(String filename, String mimeType) {
    file = null;/*from  w  w  w . j ava 2  s.c om*/
    if ((filename == null) || filename.length() == 0) {
        Notification n = new Notification("A file has to be selected", " ", Notification.Type.ERROR_MESSAGE);
        n.setDelayMsec(5000);
        n.show(Page.getCurrent());
        return null;
    }
    if (!filename.toLowerCase().endsWith(".ifc")) {
        Notification n = new Notification("The file extension has to be .ifc", " ",
                Notification.Type.ERROR_MESSAGE);
        n.setDelayMsec(5000);
        n.show(Page.getCurrent());
        return null;

    }

    // Create upload stream
    FileOutputStream fos = null; // Stream to write to
    try {
        // Open the file for writing.
        file = new File(uploads + filename);
        fos = new FileOutputStream(file);
    } catch (final java.io.FileNotFoundException e) {
        Notification n = new Notification("Could not open file ", e.getMessage(),
                Notification.Type.ERROR_MESSAGE);
        n.setDelayMsec(5000);
        n.show(Page.getCurrent());
        return null;
    }
    return fos; // Return the output stream to write to
}

From source file:fi.aalto.drumbeat.drumbeatUI.DrumbeatFileHandler.java

License:Open Source License

public void receiveFileFromURL(String url_string) {
    if (url_string == null || url_string.length() == 0) {
        return;/*from   w w  w  .j  a v a2 s. c o m*/
    }
    if (!url_string.toLowerCase().endsWith(".ifc")) {
        Notification n = new Notification("The file extension has to be .ifc", " ",
                Notification.Type.ERROR_MESSAGE);
        n.setDelayMsec(5000);
        n.show(Page.getCurrent());
        return;
    }
    CloseableHttpClient httpClient = HttpClientBuilder.create().build();
    HttpGet httpget = new HttpGet(url_string);
    HttpResponse response;
    String urlfile = null;
    if (url_string != null) {
        urlfile = url_string.substring(url_string.lastIndexOf('/') + 1, url_string.length());
    }
    if (urlfile == null) {
        return;
    }

    try {
        response = httpClient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream inputStream = entity.getContent();
            File targetFile = new File(uploads + urlfile);
            OutputStream outputStream = new FileOutputStream(targetFile);
            IOUtils.copy(inputStream, outputStream);
            outputStream.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
        Notification n = new Notification("Could not read the URL: ", e.getMessage(),
                Notification.Type.ERROR_MESSAGE);
        n.setDelayMsec(5000);
        n.show(Page.getCurrent());
        return;
    } finally {
        try {
            httpClient.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    File readyFile = new File(uploads + urlfile);
    if (readyFile.exists())
        handleNewFile(readyFile);
}

From source file:fi.aalto.drumbeat.drumbeatUI.DrumbeatFileHandler.java

License:Open Source License

private void handleNewFile(File file) {
    Properties prop = new Properties();
    OutputStream output = null;//from w  w  w.j  a  va  2 s .co m
    if (file == null)
        return;

    String realEstate = parent.getSite();
    // set the properties value
    String[] fname_array = file.getName().split("\\.");

    try {

        output = new FileOutputStream(DrumbeatConstants.marmotta_import_config_file);

        prop.setProperty("context",
                DrumbeatConstants.marmotta_contexts_baseurl + realEstate + "." + fname_array[0]);
        prop.setProperty("label", realEstate + "." + fname_array[0]);
        parent.createDataset(fname_array[0]);
        // save properties to project root folder
        prop.store(output, null);
    } catch (Exception e) {
        e.printStackTrace();
        Notification n = new Notification("File name error", file.getName() + " ; " + e.getMessage(),
                Notification.Type.ERROR_MESSAGE);
        n.setDelayMsec(5000);
        n.show(Page.getCurrent());
        return;
    } finally {
        if (output != null) {
            try {
                output.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    if (!convertIFC2RDFDefault(file, realEstate + "." + fname_array[0]))
        return; // Stop if the conversion fails

    try {
        BIMFileLoader bfl = new BIMFileLoader();
        bfl.load(file);
    } catch (Exception e) {
        Notification n = new Notification("BIMFileLoader error ", e.getMessage(),
                Notification.Type.ERROR_MESSAGE);
        n.setDelayMsec(50000);
        n.show(Page.getCurrent());
        return;
    }
    Notification.show("File was uploaded");
    parent.updateData();
}