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, Type type, boolean htmlContentAllowed) 

Source Link

Document

Creates a notification message of the specified type, with a bigger caption and smaller description.

Usage

From source file:annis.gui.admin.NewPasswordWindow.java

License:Apache License

public NewPasswordWindow(final String userName, final List<UserListView.Listener> listeners) {
    setCaption("Set new password for user \"" + userName + "\"");
    setModal(true);/*from w ww.  j  a  va  2s  . c  o m*/

    FormLayout layout = new FormLayout();
    setContent(layout);

    final PasswordField txtPassword1 = new PasswordField("Enter new password");
    final PasswordField txtPassword2 = new PasswordField("Repeat new password");

    txtPassword1.setValidationVisible(true);
    txtPassword1.setRequired(true);

    txtPassword2.addValidator(new Validator() {

        @Override
        public void validate(Object value) throws Validator.InvalidValueException {
            String asString = (String) value;
            if (asString != null && !asString.equals(txtPassword1.getValue())) {
                throw new InvalidValueException("Passwords are not the same");
            }
        }
    });
    txtPassword2.setRequired(true);
    txtPassword2.setValidationVisible(true);

    Button btOk = new Button("Ok");
    btOk.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    btOk.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                txtPassword1.validate();
                txtPassword2.validate();

                if (txtPassword1.isValid() && txtPassword2.isValid()) {
                    for (UserListView.Listener l : listeners) {
                        l.passwordChanged(userName, txtPassword1.getValue());
                    }
                    UI.getCurrent().removeWindow(NewPasswordWindow.this);
                    Notification.show("Password for user \"" + userName + "\" was changed");
                } else {

                }
            } catch (Validator.InvalidValueException ex) {
                Notification n = new Notification("Validation failed", ex.getHtmlMessage(), Type.ERROR_MESSAGE,
                        true);
                n.show(Page.getCurrent());
            }
        }
    });

    Button btCancel = new Button("Cancel");
    btCancel.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            UI.getCurrent().removeWindow(NewPasswordWindow.this);
        }
    });

    HorizontalLayout actionLayout = new HorizontalLayout(btOk, btCancel);

    layout.addComponent(txtPassword1);
    layout.addComponent(txtPassword2);
    layout.addComponent(actionLayout);
}

From source file:annis.gui.exporter.CSVExporter.java

License:Apache License

@Override
public boolean convertText(String queryAnnisQL, int contextLeft, int contextRight, Set<String> corpora,
        List<String> keys, String argsAsString, WebResource annisResource, Writer out, EventBus eventBus) {
    //this is a full result export

    try {//from  w  ww  .  j a v a 2s.  c om
        WebResource res = annisResource.path("search").path("matrix").queryParam("csv", "true")
                .queryParam("corpora", StringUtils.join(corpora, ","))
                .queryParam("q", Helper.encodeJersey(queryAnnisQL));

        if (argsAsString.startsWith("metakeys=")) {
            res = res.queryParam("metakeys", argsAsString.substring("metakeys".length() + 1));
        }

        try (InputStream result = res.get(InputStream.class)) {
            IOUtils.copy(result, out);
        }

        out.flush();

        return true;
    } catch (UniformInterfaceException ex) {
        log.error(null, ex);
        Notification n = new Notification("Service exception", ex.getResponse().getEntity(String.class),
                Notification.Type.WARNING_MESSAGE, true);
        n.show(Page.getCurrent());
    } catch (ClientHandlerException ex) {
        log.error(null, ex);
    } catch (IOException ex) {
        log.error(null, ex);
    }
    return false;
}

From source file:annis.gui.exporter.WekaExporter.java

License:Apache License

@Override
public boolean convertText(String queryAnnisQL, int contextLeft, int contextRight, Set<String> corpora,
        List<String> keys, String argsAsString, WebResource annisResource, Writer out, EventBus eventBus) {
    //this is a full result export

    try {//from w  w  w .ja  va2s .  c o m
        WebResource res = annisResource.path("search").path("matrix")
                .queryParam("corpora", StringUtils.join(corpora, ","))
                .queryParam("q", Helper.encodeJersey(queryAnnisQL));

        if (argsAsString.startsWith("metakeys=")) {
            res = res.queryParam("metakeys", argsAsString.substring("metakeys".length() + 1));
        }

        try (InputStream result = res.get(InputStream.class)) {
            IOUtils.copy(result, out);
        }

        out.flush();

        return true;
    } catch (UniformInterfaceException ex) {
        log.error(null, ex);
        Notification n = new Notification("Service exception", ex.getResponse().getEntity(String.class),
                Notification.Type.WARNING_MESSAGE, true);
        n.show(Page.getCurrent());
    } catch (ClientHandlerException ex) {
        log.error(null, ex);
    } catch (IOException ex) {
        log.error(null, ex);
    }
    return false;
}

From source file:annis.gui.ReportBugWindow.java

License:Apache License

public ReportBugWindow(final String bugEMailAddress, final byte[] screenImage, final String imageMimeType,
        Throwable cause) {//from   w w w .j a  v a  2 s  . c  o m
    this.cause = cause;

    setSizeUndefined();
    setCaption("Report Problem");

    ReportFormLayout layout = new ReportFormLayout();
    setContent(layout);

    layout.setWidth("100%");
    layout.setHeight("-1px");

    setHeight("420px");
    setWidth("750px");

    form = new FieldGroup(new BeanItem<>(new BugReport()));
    form.bindMemberFields(layout);
    form.setBuffered(true);

    final ReportBugWindow finalThis = this;
    btSubmit = new Button("Submit problem report", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            try {
                form.commit();

                if (sendBugReport(bugEMailAddress, screenImage, imageMimeType)) {
                    Notification.show("Problem report was sent",
                            "We will answer your problem report as soon as possible",
                            Notification.Type.HUMANIZED_MESSAGE);
                }

                UI.getCurrent().removeWindow(finalThis);

            } catch (FieldGroup.CommitException ex) {
                List<String> errorFields = new LinkedList<>();
                for (Field f : form.getFields()) {
                    if (f instanceof AbstractComponent) {
                        AbstractComponent c = (AbstractComponent) f;
                        if (f.isValid()) {
                            c.setComponentError(null);
                        } else {
                            errorFields.add(f.getCaption());
                            c.setComponentError(new UserError("Validation failed: "));
                        }
                    }
                } // for each field
                String message = "Please check the error messages "
                        + "(place mouse over red triangle) for the following fields:<br />";
                message = message + StringUtils.join(errorFields, ",<br/>");
                Notification notify = new Notification("Validation failed", message,
                        Notification.Type.WARNING_MESSAGE, true);
                notify.show(UI.getCurrent().getPage());
            } catch (Exception ex) {
                log.error("Could not send bug report", ex);
                Notification.show("Could not send bug report", ex.getMessage(),
                        Notification.Type.WARNING_MESSAGE);
            }
        }
    });

    btCancel = new Button("Cancel", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            form.discard();
            UI.getCurrent().removeWindow(finalThis);
        }
    });

    addScreenshotPreview(layout, screenImage, imageMimeType);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.addComponent(btSubmit);
    buttons.addComponent(btCancel);

    layout.addComponent(buttons);

}

From source file:annis.gui.SearchView.java

License:Apache License

@Override
public void notifyCannotPlayMimeType(String mimeType) {
    if (mimeType == null) {
        return;/* w ww .java2  s. c  o m*/
    }

    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:annis.gui.SearchView.java

License:Apache License

private void evaluateFragment(String fragment) {
    // do nothing if not changed
    if (fragment == null || fragment.isEmpty() || fragment.equals(lastEvaluatedFragment)) {
        return;//from  www  .j av a  2 s  .co m
    }

    Map<String, String> args = Helper.parseFragment(fragment);

    if (args.containsKey("c")) {
        String[] originalCorpusNames = args.get("c").split("\\s*,\\s*");
        Set<String> corpora = getMappedCorpora(Arrays.asList(originalCorpusNames));

        if (corpora.isEmpty()) {
            if (Helper.getUser() == null && toolbar != null) {
                // not logged in, show login window
                boolean onlyCorpusSelected = args.containsKey("c") && args.size() == 1;
                toolbar.showLoginWindow(!onlyCorpusSelected);
            } else {
                // already logged in or no login system available, just display a message
                new Notification("Linked corpus does not exist",
                        "<div><p>The corpus you wanted to access unfortunally does not (yet) exist"
                                + " in ANNIS.</p>" + "<h2>possible reasons are:</h2>" + "<ul>"
                                + "<li>that it has not been imported yet,</li>"
                                + "<li>you don't have the access rights to see this corpus,</li>"
                                + "<li>or the ANNIS service is not running.</li>" + "</ul>"
                                + "<p>Please ask the responsible person of the site that contained "
                                + "the link to import the corpus.</p></div>",
                        Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());

            }
        } // end if corpus list returned from service is empty
        else {
            if (args.containsKey("c") && args.size() == 1) {
                // special case: we were called from outside and should only select,
                // but not query, the selected corpora
                ui.getQueryState().getSelectedCorpora().setValue(corpora);
            } else if (args.get("cl") != null && args.get("cr") != null) {
                // make sure the properties are not overwritten by the background process
                getControlPanel().getSearchOptions().setUpdateStateFromConfig(false);

                DisplayedResultQuery query = QueryGenerator.displayed().left(Integer.parseInt(args.get("cl")))
                        .right(Integer.parseInt(args.get("cr"))).offset(Integer.parseInt(args.get("s")))
                        .limit(Integer.parseInt(args.get("l"))).segmentation(args.get("seg"))
                        .baseText(args.get("bt")).query(args.get("q")).corpora(corpora).build();

                if (query.getBaseText() == null && query.getSegmentation() != null) {
                    // if no explicit visible segmentation was given use the same as the context
                    query.setBaseText(query.getSegmentation());
                }
                if (query.getBaseText() != null && query.getBaseText().isEmpty()) {
                    // empty string means "null"
                    query.setBaseText(null);
                }

                String matchSelectionRaw = args.get("m");
                if (matchSelectionRaw != null) {
                    for (String selectedMatchNr : Splitter.on(',').omitEmptyStrings().trimResults()
                            .split(matchSelectionRaw)) {
                        try {
                            long nr = Long.parseLong(selectedMatchNr);
                            query.getSelectedMatches().add(nr);
                        } catch (NumberFormatException ex) {
                            log.warn("Invalid long provided as selected match", ex);
                        }
                    }
                }

                if (args.get("o") != null) {
                    try {
                        query.setOrder(OrderType.valueOf(args.get("o").toLowerCase()));
                    } catch (IllegalArgumentException ex) {
                        log.warn("Could not parse query fragment argument for order", ex);
                    }
                }

                // full query with given context
                ui.getQueryController().setQuery(query);
                ui.getQueryController().executeSearch(true, false);
            } else if (args.get("q") != null) {
                // use default context
                ui.getQueryController().setQuery(new Query(args.get("q"), corpora));
                ui.getQueryController().executeSearch(true, true);
            }

            getControlPanel().getCorpusList().scrollToSelectedCorpus();

        } // end if corpus list from server was non-empty
    } // end if there is a corpus definition
}

From source file:annis.libgui.Helper.java

License:Apache License

public static DocumentBrowserConfig getDocBrowserConfig(String corpus) {
    try {//from  w w  w. j av  a  2 s .  co m
        DocumentBrowserConfig docBrowserConfig = Helper.getAnnisWebResource().path("query").path("corpora")
                .path("doc_browser_config").path(urlPathEscape.escape(corpus)).get(DocumentBrowserConfig.class);

        return docBrowserConfig;
    } catch (UniformInterfaceException ex) {
        new Notification(ERROR_MESSAGE_DOCUMENT_BROWSER_HEADER, ERROR_MESSAGE_DOCUMENT_BROWSER_BODY,
                Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
        log.error("problems with fetching document browsing", ex);
    } catch (ClientHandlerException ex) {
        new Notification(ERROR_MESSAGE_DOCUMENT_BROWSER_HEADER, ERROR_MESSAGE_DOCUMENT_BROWSER_BODY,
                Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
        log.error("problems with fetching document browsing", ex);
    }

    return null;
}

From source file:annis.libgui.Helper.java

License:Apache License

/**
 * Loads the corpus config of a specific corpus.
 *
 * @param corpus The name of the corpus, for which the config is fetched.
 * @return A {@link CorpusConfig} object, which wraps a {@link Properties}
 * object. This Properties object stores the corpus configuration as simple
 * key-value pairs./*from   w ww.j  a  va2 s. co m*/
 */
public static CorpusConfig getCorpusConfig(String corpus) {

    if (corpus == null || corpus.isEmpty()) {
        Notification.show("no corpus is selected", "please select at leas one corpus and execute query again",
                Notification.Type.WARNING_MESSAGE);
        return null;
    }

    CorpusConfig corpusConfig = new CorpusConfig();

    try {
        corpusConfig = Helper.getAnnisWebResource().path("query").path("corpora")
                .path(urlPathEscape.escape(corpus)).path("config").get(CorpusConfig.class);
    } catch (UniformInterfaceException | ClientHandlerException ex) {
        new Notification(ERROR_MESSAGE_CORPUS_PROPS_HEADER, ERROR_MESSAGE_CORPUS_PROPS,
                Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
    }

    return corpusConfig;
}

From source file:annis.libgui.Helper.java

License:Apache License

public static CorpusConfig getDefaultCorpusConfig() {

    CorpusConfig defaultCorpusConfig = new CorpusConfig();

    try {//from   w w  w  .  j a  v a 2s . c  o  m
        defaultCorpusConfig = Helper.getAnnisWebResource().path("query").path("corpora").path(DEFAULT_CONFIG)
                .get(CorpusConfig.class);
    } catch (UniformInterfaceException ex) {
        new Notification(ERROR_MESSAGE_CORPUS_PROPS_HEADER, ERROR_MESSAGE_CORPUS_PROPS,
                Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
    } catch (ClientHandlerException ex) {
        new Notification(ERROR_MESSAGE_CORPUS_PROPS_HEADER, ERROR_MESSAGE_CORPUS_PROPS,
                Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
    }

    return defaultCorpusConfig;
}

From source file:annis.libgui.Helper.java

License:Apache License

/**
 * Loads the all available corpus configurations.
 *
 *
 * @return A {@link CorpusConfigMap} object, which wraps a Map of
 * {@link Properties} objects. The keys to the properties are the corpus
 * names. A Properties object stores the corpus configuration as simple
 * key-value pairs. The Map includes also the default corpus configuration.
 *///from w w w . j  a v  a 2s .  co  m
public static CorpusConfigMap getCorpusConfigs() {

    CorpusConfigMap corpusConfigurations = null;

    try {
        corpusConfigurations = Helper.getAnnisWebResource().path("query").path("corpora").path("config")
                .get(CorpusConfigMap.class);
    } catch (UniformInterfaceException | ClientHandlerException ex) {
        UI.getCurrent().access(new Runnable() {

            @Override
            public void run() {
                new Notification(ERROR_MESSAGE_CORPUS_PROPS_HEADER, ERROR_MESSAGE_CORPUS_PROPS,
                        Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
            }
        });
    }

    if (corpusConfigurations == null) {
        corpusConfigurations = new CorpusConfigMap();
    }

    corpusConfigurations.put(DEFAULT_CONFIG, getDefaultCorpusConfig());

    return corpusConfigurations;
}