Example usage for com.vaadin.ui Notification getCaption

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

Introduction

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

Prototype

public String getCaption() 

Source Link

Document

Gets the caption part of the notification message.

Usage

From source file:de.unioninvestment.eai.portal.support.vaadin.junit.NotificationMatcher.java

License:Apache License

@Override
public boolean matches(Object argument) {
    if (argument instanceof Notification) {
        Notification notification = (Notification) argument;
        if (Objects.equal(notification.getCaption(), caption)
                && Objects.equal(notification.getDescription(), description)) {
            return true;
        }//from  w w w  .  j  a  v  a 2 s.c o  m
    }
    return false;
}

From source file:org.apache.ace.webui.vaadin.VaadinClient.java

License:Apache License

private void initGrid() {
    User user = (User) getUser();/*from  ww w .  ja v a2s  .  com*/
    Authorization auth = m_userAdmin.getAuthorization(user);
    int count = 0;
    for (String role : new String[] { "viewArtifact", "viewFeature", "viewDistribution", "viewTarget" }) {
        if (auth.hasRole(role)) {
            count++;
        }
    }

    final GenericUploadHandler uploadHandler = new GenericUploadHandler(m_sessionDir) {
        @Override
        public void updateProgress(long readBytes, long contentLength) {
            Float percentage = new Float(readBytes / (float) contentLength);
            m_progress.setValue(percentage);
        }

        @Override
        protected void artifactsUploaded(List<UploadHandle> uploadedArtifacts) {
            StringBuilder failedMsg = new StringBuilder();
            StringBuilder successMsg = new StringBuilder();
            Set<String> selection = new HashSet<>();

            for (UploadHandle handle : uploadedArtifacts) {
                if (!handle.isSuccessful()) {
                    // Upload failed, so let's report this one...
                    appendFailure(failedMsg, handle);

                    m_log.log(LogService.LOG_ERROR, "Upload of " + handle.getFile() + " failed.",
                            handle.getFailureReason());
                } else {
                    try {
                        // Upload was successful, try to upload it to our OBR...
                        ArtifactObject artifact = uploadToOBR(handle);
                        if (artifact != null) {
                            selection.add(artifact.getDefinition());

                            appendSuccess(successMsg, handle);
                        }
                    } catch (ArtifactAlreadyExistsException exception) {
                        appendFailureExists(failedMsg, handle);

                        m_log.log(LogService.LOG_WARNING,
                                "Upload of " + handle.getFilename() + " failed, as it already exists!");
                    } catch (Exception exception) {
                        appendFailure(failedMsg, handle, exception);

                        m_log.log(LogService.LOG_ERROR, "Upload of " + handle.getFilename() + " failed.",
                                exception);
                    }
                }

                // We're done with this (temporary) file, so we can remove it...
                handle.cleanup();
            }

            m_artifactsPanel.setValue(selection);

            // Notify the user what the overall status was...
            Notification notification = createNotification(failedMsg, successMsg);
            getMainWindow().showNotification(notification);

            m_progress.setStyleName("invisible");
            m_statusLine.setStatus(notification.getCaption() + "...");
        }

        @Override
        protected void uploadStarted(UploadHandle upload) {
            m_progress.setStyleName("visible");
            m_progress.setValue(new Float(0.0f));

            m_statusLine.setStatus("Upload of '%s' started...", upload.getFilename());
        }

        private void appendFailure(StringBuilder sb, UploadHandle handle) {
            appendFailure(sb, handle, handle.getFailureReason());
        }

        private void appendFailure(StringBuilder sb, UploadHandle handle, Exception cause) {
            sb.append("<li>'").append(handle.getFile().getName()).append("': failed");
            if (cause != null) {
                sb.append(", possible reason:<br/>").append(cause.getMessage());
            }
            sb.append("</li>");
        }

        private void appendFailureExists(StringBuilder sb, UploadHandle handle) {
            sb.append("<li>'").append(handle.getFile().getName())
                    .append("': already exists in repository</li>");
        }

        private void appendSuccess(StringBuilder sb, UploadHandle handle) {
            sb.append("<li>'").append(handle.getFile().getName()).append("': added to repository</li>");
        }

        private Notification createNotification(StringBuilder failedMsg, StringBuilder successMsg) {
            String caption = "Upload completed";
            int delay = 500; // msec.
            StringBuilder notification = new StringBuilder();
            if (failedMsg.length() > 0) {
                caption = "Upload completed with failures";
                delay = -1;
                notification.append("<ul>").append(failedMsg).append("</ul>");
            }
            if (successMsg.length() > 0) {
                notification.append("<ul>").append(successMsg).append("</ul>");
            }
            if (delay < 0) {
                notification.append("<p>(click to dismiss this notification).</p>");
            }

            Notification summary = new Notification(caption, notification.toString(),
                    Notification.TYPE_TRAY_NOTIFICATION);
            summary.setDelayMsec(delay);
            return summary;
        }

        private ArtifactObject uploadToOBR(UploadHandle handle) throws IOException {
            return UploadHelper.importRemoteBundle(m_artifactRepository, handle.getFile());
        }
    };

    m_grid = new GridLayout(count, 4);
    m_grid.setSpacing(true);
    m_grid.setSizeFull();

    m_mainToolbar = createToolbar();
    m_grid.addComponent(m_mainToolbar, 0, 0, count - 1, 0);

    m_artifactsPanel = createArtifactsPanel();
    m_artifactToolbar = createArtifactToolbar();

    final DragAndDropWrapper artifactsPanelWrapper = new DragAndDropWrapper(m_artifactsPanel);
    artifactsPanelWrapper.setDragStartMode(DragStartMode.HTML5);
    artifactsPanelWrapper.setDropHandler(new ArtifactDropHandler(uploadHandler));
    artifactsPanelWrapper.setCaption(m_artifactsPanel.getCaption());
    artifactsPanelWrapper.setSizeFull();

    count = 0;
    if (auth.hasRole("viewArtifact")) {
        m_grid.addComponent(artifactsPanelWrapper, count, 2);
        m_grid.addComponent(m_artifactToolbar, count, 1);
        count++;
    }

    m_featuresPanel = createFeaturesPanel();
    m_featureToolbar = createFeatureToolbar();

    if (auth.hasRole("viewFeature")) {
        m_grid.addComponent(m_featuresPanel, count, 2);
        m_grid.addComponent(m_featureToolbar, count, 1);
        count++;
    }

    m_distributionsPanel = createDistributionsPanel();
    m_distributionToolbar = createDistributionToolbar();

    if (auth.hasRole("viewDistribution")) {
        m_grid.addComponent(m_distributionsPanel, count, 2);
        m_grid.addComponent(m_distributionToolbar, count, 1);
        count++;
    }

    m_targetsPanel = createTargetsPanel();
    m_targetToolbar = createTargetToolbar();

    if (auth.hasRole("viewTarget")) {
        m_grid.addComponent(m_targetsPanel, count, 2);
        m_grid.addComponent(m_targetToolbar, count, 1);
    }

    m_statusLine = new StatusLine();

    m_grid.addComponent(m_statusLine, 0, 3, 2, 3);

    m_progress = new ProgressIndicator(0f);
    m_progress.setStyleName("invisible");
    m_progress.setIndeterminate(false);
    m_progress.setPollingInterval(1000);

    m_grid.addComponent(m_progress, 3, 3);

    m_grid.setRowExpandRatio(2, 1.0f);

    m_grid.setColumnExpandRatio(0, 0.31f);
    m_grid.setColumnExpandRatio(1, 0.23f);
    m_grid.setColumnExpandRatio(2, 0.23f);
    m_grid.setColumnExpandRatio(3, 0.23f);

    // Wire up all panels so they have the correct associations...
    m_artifactsPanel.setAssociatedTables(null, m_featuresPanel);
    m_featuresPanel.setAssociatedTables(m_artifactsPanel, m_distributionsPanel);
    m_distributionsPanel.setAssociatedTables(m_featuresPanel, m_targetsPanel);
    m_targetsPanel.setAssociatedTables(m_distributionsPanel, null);

    addListener(m_statusLine, StatefulTargetObject.TOPIC_ALL,
            RepositoryObject.PUBLIC_TOPIC_ROOT.concat(RepositoryObject.TOPIC_ALL_SUFFIX));
    addListener(m_mainToolbar, StatefulTargetObject.TOPIC_ALL, RepositoryAdmin.TOPIC_STATUSCHANGED,
            RepositoryAdmin.TOPIC_LOGIN, RepositoryAdmin.TOPIC_REFRESH);
    addListener(m_artifactsPanel, ArtifactObject.TOPIC_ALL, RepositoryAdmin.TOPIC_STATUSCHANGED,
            RepositoryAdmin.TOPIC_LOGIN, RepositoryAdmin.TOPIC_REFRESH);
    addListener(m_featuresPanel, FeatureObject.TOPIC_ALL, RepositoryAdmin.TOPIC_STATUSCHANGED,
            RepositoryAdmin.TOPIC_LOGIN, RepositoryAdmin.TOPIC_REFRESH);
    addListener(m_distributionsPanel, DistributionObject.TOPIC_ALL, RepositoryAdmin.TOPIC_STATUSCHANGED,
            RepositoryAdmin.TOPIC_LOGIN, RepositoryAdmin.TOPIC_REFRESH);
    addListener(m_targetsPanel, StatefulTargetObject.TOPIC_ALL, TargetObject.TOPIC_ALL,
            RepositoryAdmin.TOPIC_STATUSCHANGED, RepositoryAdmin.TOPIC_LOGIN, RepositoryAdmin.TOPIC_REFRESH);

    m_mainWindow.addComponent(m_grid);
    // Ensure the focus is properly defined (for the shortcut keys to work)...
    m_mainWindow.focus();
}