List of usage examples for com.vaadin.client.ui VNotification createNotification
public static VNotification createNotification(int delayMsec, Widget owner)
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/*w ww . j av a2 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[]"); 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/*from w ww.ja v a2 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:com.wcs.wcslib.vaadin.widget.multifileupload.client.VCustomUpload.java
License:Apache License
private boolean isValidFileSize(VHtml5File file) { if (file.getSize() > maxFileSize || file.getSize() <= 0) { String formattedErrorMsg = UploadClientUtil.getSizeErrorMessage(sizeErrorMsg, maxFileSize, file.getSize(), file.getName()); VNotification.createNotification(1000, client.getUIConnector().getWidget()).show(formattedErrorMsg, VNotification.CENTERED, "warning"); return false; }// w w w . j ava 2s. c o m return true; }
From source file:com.wcs.wcslib.vaadin.widget.multifileupload.client.VCustomUpload.java
License:Apache License
private boolean isValidMimeType(VHtml5File file) { if (acceptedMimeTypes != null && !acceptedMimeTypes.isEmpty() && !acceptedMimeTypes.contains(file.getType())) { String formattedErrorMsg = UploadClientUtil.getMimeTypeErrorMessage(mimeTypeErrorMsg, file.getName()); VNotification.createNotification(1000, client.getUIConnector().getWidget()).show(formattedErrorMsg, VNotification.CENTERED, "warning"); return false; }/* ww w . j ava 2 s. co m*/ return true; }
From source file:com.wcs.wcslib.vaadin.widget.multifileupload.client.VMultiUpload.java
License:Apache License
private void submit() { if (!enabled) { VConsole.log("Submit cancelled (disabled)"); return;//from ww w.j av a 2s . c o m } int files = getFileCount(fu.getElement()); List<String> filedetails = new ArrayList<String>(); StringBuilder errorMsg = new StringBuilder(); for (int i = 0; i < files; i++) { VHtml5File file = getFile(fu.getElement(), i); if (!isValidFileSize(file, errorMsg) || !isValidMimeType(file, errorMsg)) { continue; } FileWrapper wrapper = queueFilePost(file); filedetails.add(wrapper.serialize()); } client.updateVariable(paintableId, "filequeue", filedetails.toArray(new String[filedetails.size()]), true); if (!errorMsg.toString().isEmpty()) { VNotification.createNotification(1000, client.getUIConnector().getWidget()).show(errorMsg.toString(), VNotification.CENTERED, "warning"); } disableUpload(); }
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/*w w w. ja v a 2 s.c o m*/ * 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. *///w w w.ja v a2s . 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); }