Example usage for com.vaadin.client.ui VNotification show

List of usage examples for com.vaadin.client.ui VNotification show

Introduction

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

Prototype

public void show(String html, Position position, String styleName) 

Source Link

Usage

From source file:com.haulmont.cuba.web.toolkit.ui.client.jqueryfileupload.CubaFileUploadWidget.java

License:Apache License

public CubaFileUploadWidget() {
    submitButton = new VButton();
    submitButton.addClickHandler(new ClickHandler() {
        @Override//from w  ww. j  a  v  a 2  s.c  om
        public void onClick(ClickEvent event) {
            fireNativeClick(getFileInputElement());
        }
    });
    add(submitButton);
    submitButton.setTabIndex(-1);

    setStyleName(DEFAULT_CLASSNAME);

    Element inputElement = Document.get().createFileInputElement();
    inputElement.setAttribute("name", "files[]");
    inputElement.setAttribute("title", " ");
    listenToFocusEvents(inputElement);

    getElement().appendChild(inputElement);

    fileUpload = new JQueryFileUploadOverlay(this) {
        protected boolean canceled = false;

        @Override
        protected boolean isValidFile(String name, double size) {
            if (fileSizeLimit > 0 && size > fileSizeLimit) {
                if (filePermissionsHandler != null) {
                    filePermissionsHandler.fileSizeLimitExceeded(name);
                }
                return false;
            }

            if (hasInvalidExtension(name)) {
                if (filePermissionsHandler != null) {
                    filePermissionsHandler.fileExtensionNotAllowed(name);
                }
                return false;
            }

            return true;
        }

        protected boolean hasInvalidExtension(String name) {
            if (permittedExtensions != null && !permittedExtensions.isEmpty()) {
                if (name.lastIndexOf(".") > 0) {
                    String fileExtension = name.substring(name.lastIndexOf("."), name.length());
                    return !permittedExtensions.contains(fileExtension.toLowerCase());
                }
                return true;
            }
            return false;
        }

        @Override
        protected void queueUploadStart() {
            // listen to events of new input element
            listenToFocusEvents(getFileInputElement());

            progressWindow = new CubaFileUploadProgressWindow();
            progressWindow.setOwner(CubaFileUploadWidget.this);
            progressWindow.addStyleName(getStylePrimaryName() + "-progresswindow");

            progressWindow.setVaadinModality(true);
            progressWindow.setDraggable(true);
            progressWindow.setResizable(false);
            progressWindow.setClosable(true);

            progressWindow.setCaption(progressWindowCaption);
            progressWindow.setCancelButtonCaption(cancelButtonCaption);

            progressWindow.closeListener = new CubaFileUploadProgressWindow.CloseListener() {
                @Override
                public void onClose() {
                    canceled = true;
                    // null progress to prevent repeated hide() call inside cancelUploading
                    progressWindow = null;

                    cancelUploading();

                    if (queueUploadListener != null) {
                        queueUploadListener.uploadFinished();
                    }
                }
            };

            progressWindow.setVisible(false);
            progressWindow.show();
            progressWindow.center();
            progressWindow.setVisible(true);

            canceled = false;
        }

        @Override
        protected void fileUploadStart(String fileName) {
            if (progressWindow != null) {
                progressWindow.setCurrentFileName(fileName);
            }
        }

        @Override
        protected void fileUploadSucceed(String fileName) {
            if (fileUploadedListener != null) {
                fileUploadedListener.fileUploaded(fileName);
            }
        }

        @Override
        protected void uploadProgress(double loaded, double total) {
            if (progressWindow != null) {
                float ratio = (float) (loaded / total);
                progressWindow.setProgress(ratio);
            }
        }

        @Override
        protected void queueUploadStop() {
            if (progressWindow != null) {
                progressWindow.hide();
                progressWindow = null;
            }

            getFileInputElement().focus();

            if (queueUploadListener != null) {
                queueUploadListener.uploadFinished();
            }
        }

        @Override
        protected void uploadFailed(String textStatus, String errorThrown) {
            if (ignoreExceptions) {
                if (progressWindow != null)
                    progressWindow.hide();
                return;
            }

            if (!canceled) {
                if (unableToUploadFileMessage != null) {
                    // show notification without server round trip, server may be unreachable
                    VNotification notification = VNotification.createNotification(-1,
                            CubaFileUploadWidget.this);
                    String fileName = "";
                    if (progressWindow != null) {
                        fileName = progressWindow.getCurrentFileName();
                    }

                    String message = "<h1>"
                            + WidgetUtil.escapeHTML(unableToUploadFileMessage.replace("%s", fileName))
                            + "</h1>";
                    notification.show(message, Position.MIDDLE_CENTER, "error");
                }

                canceled = true;
                cancelUploading();
            }
        }
    };
}

From source file:com.haulmont.cuba.web.widgets.client.jqueryfileupload.CubaFileUploadWidget.java

License:Apache License

public CubaFileUploadWidget() {
    submitButton = new VButton();
    submitButton.addClickHandler(new ClickHandler() {
        @Override/*  ww w .  j av a  2  s .co m*/
        public void onClick(ClickEvent event) {
            fireNativeClick(getFileInputElement());
        }
    });
    add(submitButton);
    submitButton.setTabIndex(-1);

    setStyleName(DEFAULT_CLASSNAME);

    Element inputElement = Document.get().createFileInputElement();
    inputElement.setAttribute("name", "files[]");
    if (!BrowserInfo.get().isIE() && !BrowserInfo.get().isEdge()) {
        inputElement.setAttribute("title", " ");
    }
    listenToFocusEvents(inputElement);

    getElement().appendChild(inputElement);

    fileUpload = new JQueryFileUploadOverlay(this) {
        protected boolean canceled = false;

        @Override
        protected boolean isValidFile(String name, double size) {
            if (fileSizeLimit > 0 && size > fileSizeLimit) {
                if (filePermissionsHandler != null) {
                    filePermissionsHandler.fileSizeLimitExceeded(name);
                }
                return false;
            }

            if (hasInvalidExtension(name)) {
                if (filePermissionsHandler != null) {
                    filePermissionsHandler.fileExtensionNotAllowed(name);
                }
                return false;
            }

            return true;
        }

        protected boolean hasInvalidExtension(String name) {
            if (permittedExtensions != null && !permittedExtensions.isEmpty()) {
                if (name.lastIndexOf(".") > 0) {
                    String fileExtension = name.substring(name.lastIndexOf("."), name.length());
                    return !permittedExtensions.contains(fileExtension.toLowerCase());
                }
                return true;
            }
            return false;
        }

        @Override
        protected void queueUploadStart() {
            // listen to events of new input element
            listenToFocusEvents(getFileInputElement());

            progressWindow = new CubaFileUploadProgressWindow();
            progressWindow.setOwner(CubaFileUploadWidget.this);
            progressWindow.addStyleName(getStylePrimaryName() + "-progresswindow");

            progressWindow.setVaadinModality(true);
            progressWindow.setDraggable(true);
            progressWindow.setResizable(false);
            progressWindow.setClosable(true);

            progressWindow.setCaption(progressWindowCaption);
            progressWindow.setCancelButtonCaption(cancelButtonCaption);

            progressWindow.closeListener = new CubaFileUploadProgressWindow.CloseListener() {
                @Override
                public void onClose() {
                    canceled = true;
                    // null progress to prevent repeated hide() call inside cancelUploading
                    progressWindow = null;

                    cancelUploading();

                    if (queueUploadListener != null) {
                        queueUploadListener.uploadFinished();
                    }
                }
            };

            progressWindow.setVisible(false);
            progressWindow.show();
            progressWindow.center();
            progressWindow.setVisible(true);

            canceled = false;
        }

        @Override
        protected void fileUploadStart(String fileName) {
            if (progressWindow != null) {
                progressWindow.setCurrentFileName(fileName);
            }
        }

        @Override
        protected void fileUploadSucceed(String fileName) {
            if (fileUploadedListener != null) {
                fileUploadedListener.fileUploaded(fileName);
            }
        }

        @Override
        protected void uploadProgress(double loaded, double total) {
            if (progressWindow != null) {
                float ratio = (float) (loaded / total);
                progressWindow.setProgress(ratio);
            }
        }

        @Override
        protected void queueUploadStop() {
            if (progressWindow != null) {
                progressWindow.hide();
                progressWindow = null;
            }

            getFileInputElement().focus();

            if (queueUploadListener != null) {
                queueUploadListener.uploadFinished();
            }
        }

        @Override
        protected void uploadFailed(String textStatus, String errorThrown) {
            if (ignoreExceptions) {
                if (progressWindow != null)
                    progressWindow.hide();
                return;
            }

            if (!canceled) {
                if (unableToUploadFileMessage != null) {
                    // show notification without server round trip, server may be unreachable
                    VNotification notification = VNotification.createNotification(-1,
                            CubaFileUploadWidget.this);
                    String fileName = "";
                    if (progressWindow != null) {
                        fileName = progressWindow.getCurrentFileName();
                    }

                    String message = "<h1>"
                            + WidgetUtil.escapeHTML(unableToUploadFileMessage.replace("%s", fileName))
                            + "</h1>";
                    notification.show(message, Position.MIDDLE_CENTER, "error");
                }

                canceled = true;
                cancelUploading();
            }
        }
    };
}

From source file:org.eclipse.hawkbit.ui.dd.client.criteria.ViewClientCriterion.java

License:Open Source License

/**
 * Displays a message box telling that the action is not allowed.
 *
 * @param drag//from  ww w.ja  v  a  2 s. c  om
 *            the current drag event holding the context.
 */
private void showErrorNotification(final VDragEvent drag) {
    final VNotification n = VNotification.createNotification(SPUILabelDefinitions.SP_DELAY,
            drag.getTransferable().getDragSource().getWidget());
    n.show(getDraggableTemplate().notificationMsg(errorMessage).asString(), Position.BOTTOM_RIGHT,
            SPUIStyleDefinitions.SP_NOTIFICATION_ERROR_MESSAGE_STYLE);
}

From source file:org.vaadin.gridfiledownloader.client.GridFileDownloaderConnector.java

License:Apache License

/**
 * Display notification for informing the user that a new download couldn't
 * be triggered because previous download is still processing.
 *//*  ww w  .  ja  v  a  2s. c o m*/
protected void downloadIgnoredBecauseProcessing() {
    VNotification n = VNotification.createNotification(getState().notificationDelay, grid);
    n.getElement().getStyle().setTextAlign(TextAlign.LEFT);
    n.show("<h1>" + getState().processingCaption + "</h1><br />"
            + getState().processingDescription.replace("\n", "<br/>\n"), VNotification.CENTERED,
            getState().processingNotificationType);
}