use of com.wcs.wcslib.vaadin.widget.multifileupload.ui.UploadFinishedHandler 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