use of com.wcs.wcslib.vaadin.widget.multifileupload.ui.MultiFileUpload 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;
}
use of com.wcs.wcslib.vaadin.widget.multifileupload.ui.MultiFileUpload 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);
}
Aggregations