Search in sources :

Example 1 with UploadStateWindow

use of com.wcs.wcslib.vaadin.widget.multifileupload.ui.UploadStateWindow in project SORMAS-Project by hzi-braunschweig.

the class DocumentListComponent method buildUploadButton.

private Button buildUploadButton(DocumentRelatedEntityType relatedEntityType, ReferenceDto entityRef) {
    VerticalLayout uploadLayout = new VerticalLayout();
    uploadLayout.setSpacing(true);
    uploadLayout.setMargin(true);
    uploadLayout.addStyleName(CssStyles.LAYOUT_MINIMAL);
    PopupButton mainButton = ButtonHelper.createIconPopupButton(Captions.documentUploadDocument, VaadinIcons.PLUS_CIRCLE, uploadLayout, ValoTheme.BUTTON_PRIMARY);
    boolean multipleUpload = FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.DOCUMENTS_MULTI_UPLOAD);
    UploadStateWindow uploadStateWindow = new UploadStateWindow();
    MultiFileUpload multiFileUpload = new DocumentMultiFileUpload(() -> {
        mainButton.setButtonClickTogglesPopupVisibility(false);
        mainButton.setClosePopupOnOutsideClick(false);
    }, new DocumentUploadFinishedHandler(relatedEntityType, entityRef.getUuid(), documentList::reload), uploadStateWindow, multipleUpload);
    multiFileUpload.setUploadButtonCaptions(I18nProperties.getCaption(Captions.importImportData), I18nProperties.getCaption(Captions.importImportData));
    multiFileUpload.setAllUploadFinishedHandler(() -> {
        mainButton.setButtonClickTogglesPopupVisibility(true);
        mainButton.setClosePopupOnOutsideClick(true);
        mainButton.setPopupVisible(false);
    });
    uploadLayout.addComponentsAndExpand(multiFileUpload);
    return mainButton;
}
Also used : DocumentMultiFileUpload(de.symeda.sormas.ui.importer.DocumentMultiFileUpload) PopupButton(org.vaadin.hene.popupbutton.PopupButton) MultiFileUpload(com.wcs.wcslib.vaadin.widget.multifileupload.ui.MultiFileUpload) DocumentMultiFileUpload(de.symeda.sormas.ui.importer.DocumentMultiFileUpload) UploadStateWindow(com.wcs.wcslib.vaadin.widget.multifileupload.ui.UploadStateWindow) DocumentUploadFinishedHandler(de.symeda.sormas.ui.importer.DocumentUploadFinishedHandler) VerticalLayout(com.vaadin.ui.VerticalLayout)

Example 2 with UploadStateWindow

use of com.wcs.wcslib.vaadin.widget.multifileupload.ui.UploadStateWindow in project catma by forTEXT.

the class UploadStep method initComponents.

private void initComponents() {
    HorizontalLayout uploadPanel = new HorizontalLayout();
    uploadPanel.setWidth("100%");
    uploadPanel.setSpacing(true);
    uploadPanel.setMargin(false);
    addComponent(uploadPanel);
    UploadStateWindow uploadStateWindow = new UploadStateWindow();
    uploadStateWindow.setModal(true);
    uploadStateWindow.setWindowPosition(WindowPosition.CENTER);
    upload = new MultiFileUpload(new UploadFinishedHandler() {

        @Override
        public void handleFile(InputStream stream, String fileName, String mimeType, long length, int filesLeftInQueue) {
            try {
                String tempDir = ((CatmaApplication) UI.getCurrent()).accquirePersonalTempFolder();
                final String fileId = idGenerator.generateDocumentId();
                File tempFile = new File(new File(tempDir), fileId);
                if (tempFile.exists()) {
                    tempFile.delete();
                }
                try (FileOutputStream fos = new FileOutputStream(tempFile)) {
                    IOUtils.copy(stream, fos);
                }
                try (FileInputStream fis = new FileInputStream(tempFile)) {
                    String type = tika.detect(fis, fileName);
                    UploadFile uploadFile = new UploadFile(fileId, tempFile.toURI(), fileName, type, length);
                    if (type.toLowerCase().trim().equals(FileType.ZIP.getMimeType())) {
                        handleZipFile(uploadFile);
                    } else {
                        fileList.add(uploadFile);
                        fileDataProvider.refreshAll();
                        stepChangeListener.stepChanged(UploadStep.this);
                    }
                }
            } catch (Exception e) {
                String errorMsg = e.getMessage();
                if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
                    errorMsg = "";
                }
                Notification.show("Error", String.format("Error uploading %1$s, file will be skipped!\n%2$s", fileName, errorMsg), Type.ERROR_MESSAGE);
            }
        }
    }, uploadStateWindow) {

        @Override
        protected UploadStatePanel createStatePanel(UploadStateWindow uploadStateWindow) {
            return new MyUploadStatePanel(uploadStateWindow);
        }
    };
    uploadPanel.addComponent(upload);
    // 100 MB
    int maxFileSize = 104857600;
    upload.setMaxFileSize(maxFileSize);
    String errorMsgPattern = "File is too big (max = {0}): {2} ({1})";
    upload.setSizeErrorMsgPattern(errorMsgPattern);
    upload.setCaption("Upload files from your local computer");
    upload.setPanelCaption("Uploading file");
    upload.setMaxFileCount(300);
    upload.getSmartUpload().setUploadButtonCaptions("", "");
    upload.getSmartUpload().setUploadButtonIcon(VaadinIcons.UPLOAD);
    urlInputField = new TextField("or add a URL");
    urlInputField.setValueChangeMode(ValueChangeMode.BLUR);
    urlInputField.setWidth("100%");
    uploadPanel.addComponent(urlInputField);
    btFetch = new Button(VaadinIcons.CLOUD_DOWNLOAD);
    uploadPanel.addComponent(btFetch);
    uploadPanel.setComponentAlignment(btFetch, Alignment.BOTTOM_LEFT);
    progressBar = new ProgressBar();
    progressBar.setVisible(false);
    uploadPanel.addComponent(progressBar);
    fileGrid = new Grid<UploadFile>("or drag and drop some files to the list", fileDataProvider);
    fileGrid.setSizeFull();
    fileGrid.addColumn(UploadFile::getOriginalFilename).setCaption("File");
    fileGrid.addColumn(UploadFile::getMimetype).setCaption("Type");
    addComponent(fileGrid);
    setExpandRatio(fileGrid, 1.0f);
}
Also used : MultiFileUpload(com.wcs.wcslib.vaadin.widget.multifileupload.ui.MultiFileUpload) UploadStateWindow(com.wcs.wcslib.vaadin.widget.multifileupload.ui.UploadStateWindow) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) UploadFinishedHandler(com.wcs.wcslib.vaadin.widget.multifileupload.ui.UploadFinishedHandler) UploadStatePanel(com.wcs.wcslib.vaadin.widget.multifileupload.ui.UploadStatePanel) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) HorizontalLayout(com.vaadin.ui.HorizontalLayout) CatmaApplication(de.catma.ui.CatmaApplication) Button(com.vaadin.ui.Button) FileOutputStream(java.io.FileOutputStream) TextField(com.vaadin.ui.TextField) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) Html5File(com.vaadin.ui.Html5File) File(java.io.File) ProgressBar(com.vaadin.ui.ProgressBar)

Aggregations

MultiFileUpload (com.wcs.wcslib.vaadin.widget.multifileupload.ui.MultiFileUpload)2 UploadStateWindow (com.wcs.wcslib.vaadin.widget.multifileupload.ui.UploadStateWindow)2 Button (com.vaadin.ui.Button)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Html5File (com.vaadin.ui.Html5File)1 ProgressBar (com.vaadin.ui.ProgressBar)1 TextField (com.vaadin.ui.TextField)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 UploadFinishedHandler (com.wcs.wcslib.vaadin.widget.multifileupload.ui.UploadFinishedHandler)1 UploadStatePanel (com.wcs.wcslib.vaadin.widget.multifileupload.ui.UploadStatePanel)1 CatmaApplication (de.catma.ui.CatmaApplication)1 DocumentMultiFileUpload (de.symeda.sormas.ui.importer.DocumentMultiFileUpload)1 DocumentUploadFinishedHandler (de.symeda.sormas.ui.importer.DocumentUploadFinishedHandler)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)1