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, String description, Type type) 

Source Link

Document

Shows a notification message the current page.

Usage

From source file:annis.gui.AdminUI.java

License:Apache License

@Override
public void showInfo(String info, String description) {
    Notification.show(info, description, Notification.Type.HUMANIZED_MESSAGE);
}

From source file:annis.gui.AdminUI.java

License:Apache License

@Override
public void showBackgroundInfo(String info, String description) {
    Notification.show(info, description, Notification.Type.TRAY_NOTIFICATION);
}

From source file:annis.gui.AdminUI.java

License:Apache License

@Override
public void showWarning(String error, String description) {
    Notification.show(error, description, Notification.Type.WARNING_MESSAGE);
}

From source file:annis.gui.AdminUI.java

License:Apache License

@Override
public void showError(String error, String description) {
    Notification.show(error, description, Notification.Type.ERROR_MESSAGE);
}

From source file:annis.gui.controller.CountCallback.java

License:Apache License

@Override
public void run() {
    Future futureCount = ui.getQueryState().getExecutedTasks().get(QueryUIState.QueryType.COUNT);
    final MatchAndDocumentCount countResult;
    MatchAndDocumentCount tmpCountResult = null;
    if (futureCount != null) {
        UniformInterfaceException cause = null;
        try {/*from   ww  w .  jav  a2  s.  c om*/
            tmpCountResult = (MatchAndDocumentCount) futureCount.get();
        } catch (InterruptedException ex) {
            log.warn(null, ex);
        } catch (ExecutionException root) {
            if (root.getCause() instanceof UniformInterfaceException) {
                cause = (UniformInterfaceException) root.getCause();
            } else {
                log.error("Unexcepted ExecutionException cause", root);
            }
        } finally {
            countResult = tmpCountResult;
        }
        ui.getQueryState().getExecutedTasks().remove(QueryUIState.QueryType.COUNT);
        final UniformInterfaceException causeFinal = cause;
        ui.accessSynchronously(new Runnable() {
            @Override
            public void run() {
                if (causeFinal == null) {
                    if (countResult != null) {
                        String documentString = countResult.getDocumentCount() > 1 ? "documents" : "document";
                        String matchesString = countResult.getMatchCount() > 1 ? "matches" : "match";
                        ui.getControlPanel().getQueryPanel()
                                .setStatus("" + countResult.getMatchCount() + " " + matchesString + "\nin "
                                        + countResult.getDocumentCount() + " " + documentString);
                        if (countResult.getMatchCount() > 0 && panel != null) {
                            panel.getPaging().setPageSize(pageSize, false);
                            panel.setCount(countResult.getMatchCount());
                        }
                    }
                } else {
                    if (causeFinal.getResponse().getStatus() == 400) {
                        List<AqlParseError> errors = causeFinal.getResponse()
                                .getEntity(new GenericType<List<AqlParseError>>() {
                                });
                        String errMsg = Joiner.on("\n").join(errors);

                        Notification.show("parsing error", errMsg, Notification.Type.WARNING_MESSAGE);
                        ui.getControlPanel().getQueryPanel().setStatus(errMsg);
                    } else if (causeFinal.getResponse().getStatus() == 504) {
                        String errMsg = "Timeout: query execution took too long.";
                        Notification.show(errMsg,
                                "Try to simplyfiy your query e.g. by replacing \"node\" with an annotation name or adding more constraints between the nodes.",
                                Notification.Type.WARNING_MESSAGE);
                        ui.getControlPanel().getQueryPanel().setStatus(errMsg);
                    } else if (causeFinal.getResponse().getStatus() == 403) {
                        String errMsg = "You don't have the access rights to query this corpus. "
                                + "You might want to login to access more corpora.";
                        Notification.show(errMsg, Notification.Type.WARNING_MESSAGE);
                        ui.getControlPanel().getQueryPanel().setStatus(errMsg);
                    } else {
                        log.error("Unexpected exception:  " + causeFinal.getLocalizedMessage(), causeFinal);
                        ExceptionDialog.show(causeFinal);
                        ui.getControlPanel().getQueryPanel()
                                .setStatus("Unexpected exception:  " + causeFinal.getMessage());
                    }
                } // end if cause != null
                ui.getControlPanel().getQueryPanel().setCountIndicatorEnabled(false);
            }
        });
    }
}

From source file:annis.gui.ExportPanel.java

License:Apache License

public void showResult(File currentTmpFile, boolean manuallyCancelled) {
    btExport.setEnabled(true);/*www  . j  a  v a2s.co  m*/
    btCancel.setEnabled(false);
    progressBar.setVisible(false);
    progressLabel.setValue("");

    // copy the result to the class member in order to delete if
    // when not longer needed
    tmpOutputFile = currentTmpFile;

    if (tmpOutputFile == null) {
        Notification.show("Could not create the Exporter",
                "The server logs might contain more information about this "
                        + "so you should contact the provider of this ANNIS installation " + "for help.",
                Notification.Type.ERROR_MESSAGE);
    } else if (manuallyCancelled) {
        // we were aborted, don't do anything
        Notification.show("Export cancelled", Notification.Type.WARNING_MESSAGE);
    } else {
        if (downloader != null && btDownload.getExtensions().contains(downloader)) {
            btDownload.removeExtension(downloader);
        }
        downloader = new FileDownloader(new FileResource(tmpOutputFile));

        downloader.extend(btDownload);
        btDownload.setEnabled(true);

        Notification.show("Export finished",
                "Click on the button right to the export button to actually download the file.",
                Notification.Type.HUMANIZED_MESSAGE);
    }
}

From source file:annis.gui.MainToolbar.java

License:Apache License

@Subscribe
public void handleLoginDataLostException(LoginDataLostException ex) {

    Notification.show("Login data was lost, please login again.",
            "Due to a server misconfiguration the login-data was lost. Please contact the adminstrator of this ANNIS instance.",
            Notification.Type.WARNING_MESSAGE);

    for (LoginListener l : loginListeners) {
        try {//www  .  j  av  a2 s. c o  m
            l.onLogout();
        } catch (Exception loginEx) {
            log.error("exception thrown while notifying login listeners", loginEx);
        }
    }
    updateUserInformation();

}

From source file:annis.gui.QueryController.java

License:Apache License

/**
 * Show errors that occured during the execution of a query to the user.
 *
 * @param ex The exception to report in the user interface
 * @param showNotification If true a notification is shown instead of only
 * displaying the error in the status label.
 *///  w  ww  . ja v a  2  s  . com
public void reportServiceException(UniformInterfaceException ex, boolean showNotification) {
    QueryPanel qp = searchView.getControlPanel().getQueryPanel();

    String caption = null;
    String description = null;

    if (ex.getResponse().getStatus() == 400) {
        List<AqlParseError> errors = ex.getResponse().getEntity(new GenericType<List<AqlParseError>>() {
        });
        caption = "Parsing error";
        description = Joiner.on("\n").join(errors);
        qp.setStatus(description);
        qp.setErrors(errors);
    } else if (ex.getResponse().getStatus() == 504) {
        caption = "Timeout";
        description = "Query execution took too long.";
        qp.setStatus(caption + ": " + description);
    } else if (ex.getResponse().getStatus() == 403) {

        if (Helper.getUser() == null) {
            // not logged in
            qp.setStatus("You don't have the access rights to query this corpus. "
                    + "You might want to login to access more corpora.");
            searchView.getMainToolbar().showLoginWindow(true);
        } else {
            // logged in but wrong user
            caption = "You don't have the access rights to query this corpus. "
                    + "You might want to login as another user to access more corpora.";
            qp.setStatus(caption);
        }
    } else {
        log.error("Exception when communicating with service", ex);
        qp.setStatus("Unexpected exception:  " + ex.getMessage());
        ExceptionDialog.show(ex, "Exception when communicating with service.");
    }

    if (showNotification && caption != null) {
        Notification.show(caption, description, Notification.Type.WARNING_MESSAGE);
    }

}

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.ReportBugWindow.java

License:Apache License

private boolean sendBugReport(String bugEMailAddress, byte[] screenImage, String imageMimeType) {
    MultiPartEmail mail = new MultiPartEmail();
    try {/*from  w w  w  . j  av  a 2  s.com*/
        // server setup
        mail.setHostName("localhost");

        // content of the mail
        mail.addReplyTo(form.getField("email").getValue().toString(),
                form.getField("name").getValue().toString());
        mail.setFrom(bugEMailAddress);
        mail.addTo(bugEMailAddress);

        mail.setSubject("[ANNIS BUG] " + form.getField("summary").getValue().toString());

        // TODO: add info about version etc.
        StringBuilder sbMsg = new StringBuilder();

        sbMsg.append("Reporter: ").append(form.getField("name").getValue().toString()).append(" (")
                .append(form.getField("email").getValue().toString()).append(")\n");
        sbMsg.append("Version: ").append(VersionInfo.getVersion()).append("\n");
        sbMsg.append("Vaadin Version: ").append(Version.getFullVersion()).append("\n");
        sbMsg.append("Browser: ").append(Page.getCurrent().getWebBrowser().getBrowserApplication())
                .append("\n");
        sbMsg.append("URL: ").append(UI.getCurrent().getPage().getLocation().toASCIIString()).append("\n");

        sbMsg.append("\n");

        sbMsg.append(form.getField("description").getValue().toString());
        mail.setMsg(sbMsg.toString());

        if (screenImage != null) {
            try {
                mail.attach(new ByteArrayDataSource(screenImage, imageMimeType), "screendump.png",
                        "Screenshot of the browser content at time of problem report");
            } catch (IOException ex) {
                log.error(null, ex);
            }
        }

        File logfile = new File(VaadinService.getCurrent().getBaseDirectory(), "/WEB-INF/log/annis-gui.log");
        if (logfile.exists() && logfile.isFile() && logfile.canRead()) {
            mail.attach(new FileDataSource(logfile), "annis-gui.log",
                    "Logfile of the GUI (shared by all users)");
        }

        if (cause != null) {
            try {
                mail.attach(new ByteArrayDataSource(Helper.convertExceptionToMessage(cause), "text/plain"),
                        "exception.txt", "Exception that caused the user to report the problem");
            } catch (IOException ex) {
                log.error(null, ex);
            }
        }

        mail.send();
        return true;

    } catch (EmailException ex) {
        Notification.show("E-Mail not configured on server",
                "If this is no Kickstarter version please ask the administrator (" + bugEMailAddress
                        + ") of this ANNIS-instance for assistance. "
                        + "Problem reports are not available for ANNIS Kickstarter",
                Notification.Type.ERROR_MESSAGE);
        log.error(null, ex);
        return false;
    }
}