use of com.haulmont.cuba.web.toolkit.ui.CubaFileUpload in project cuba by cuba-platform.
the class WebFileMultiUploadField method setPasteZone.
@Override
public void setPasteZone(Container pasteZone) {
super.setPasteZone(pasteZone);
if (component instanceof CubaFileUpload) {
if (pasteZone == null) {
((CubaFileUpload) component).setPasteZone(null);
} else {
Component vComponent = pasteZone.unwrapComposition(Component.class);
((CubaFileUpload) component).setPasteZone(vComponent);
}
}
}
use of com.haulmont.cuba.web.toolkit.ui.CubaFileUpload in project cuba by cuba-platform.
the class WebFileMultiUploadField method initComponent.
protected void initComponent() {
CubaFileUpload impl = createComponent();
impl.setMultiSelect(true);
Messages messages = AppBeans.get(Messages.NAME);
impl.setProgressWindowCaption(messages.getMainMessage("upload.uploadingProgressTitle"));
impl.setUnableToUploadFileMessage(messages.getMainMessage("upload.unableToUploadFile"));
impl.setCancelButtonCaption(messages.getMainMessage("upload.cancel"));
impl.setCaption(messages.getMainMessage("upload.submit"));
impl.setDropZonePrompt(messages.getMainMessage("upload.dropZonePrompt"));
impl.setDescription(null);
Configuration configuration = AppBeans.get(Configuration.NAME);
final int maxUploadSizeMb = configuration.getConfig(ClientConfig.class).getMaxUploadSizeMb();
final int maxSizeBytes = maxUploadSizeMb * BYTES_IN_MEGABYTE;
impl.setFileSizeLimit(maxSizeBytes);
impl.setReceiver((fileName, MIMEType) -> {
FileOutputStream outputStream;
try {
FileUploadingAPI.FileInfo fileInfo = fileUploading.createFile();
tempFileId = fileInfo.getId();
File tmpFile = fileInfo.getFile();
outputStream = new FileOutputStream(tmpFile);
} catch (Exception e) {
throw new RuntimeException("Unable to receive file", e);
}
return outputStream;
});
impl.addStartedListener(event -> fireFileUploadStart(event.getFileName(), event.getContentLength()));
impl.addQueueUploadFinishedListener(event -> fireQueueUploadComplete());
impl.addSucceededListener(event -> {
files.put(tempFileId, event.getFileName());
fireFileUploadFinish(event.getFileName(), event.getContentLength());
});
impl.addFailedListener(event -> {
try {
// close and remove temp file
fileUploading.deleteFile(tempFileId);
tempFileId = null;
} catch (Exception e) {
if (e instanceof FileStorageException) {
FileStorageException fse = (FileStorageException) e;
if (fse.getType() != FileStorageException.Type.FILE_NOT_FOUND) {
LoggerFactory.getLogger(WebFileMultiUploadField.class).warn("Could not remove temp file {} after broken uploading", tempFileId);
}
}
LoggerFactory.getLogger(WebFileMultiUploadField.class).warn("Error while delete temp file {}", tempFileId);
}
fireFileUploadError(event.getFileName(), event.getContentLength(), event.getReason());
});
impl.addFileSizeLimitExceededListener(e -> {
String warningMsg = messages.formatMessage(WebFileMultiUploadField.class, "multiupload.filesizeLimitExceed", e.getFileName(), getFileSizeLimitString());
getFrame().showNotification(warningMsg, Frame.NotificationType.WARNING);
});
impl.addFileExtensionNotAllowedListener(e -> {
String warningMsg = messages.formatMainMessage("upload.fileIncorrectExtension.message", e.getFileName());
getFrame().showNotification(warningMsg, Frame.NotificationType.WARNING);
});
component = impl;
}
use of com.haulmont.cuba.web.toolkit.ui.CubaFileUpload in project cuba by cuba-platform.
the class WebFileMultiUploadField method setDropZone.
@Override
public void setDropZone(DropZone dropZone) {
super.setDropZone(dropZone);
if (component instanceof CubaFileUpload) {
if (dropZone == null) {
((CubaFileUpload) component).setDropZone(null);
} else {
com.haulmont.cuba.gui.components.Component target = dropZone.getTarget();
if (target instanceof Window.Wrapper) {
target = ((Window.Wrapper) target).getWrappedWindow();
}
Component vComponent = target.unwrapComposition(Component.class);
((CubaFileUpload) this.component).setDropZone(vComponent);
}
}
}
use of com.haulmont.cuba.web.toolkit.ui.CubaFileUpload in project cuba by cuba-platform.
the class WebFileUploadField method setPasteZone.
@Override
public void setPasteZone(Container pasteZone) {
super.setPasteZone(pasteZone);
if (uploadButton instanceof CubaFileUpload) {
if (pasteZone == null) {
((CubaFileUpload) uploadButton).setPasteZone(null);
} else {
Component vComponent = pasteZone.unwrapComposition(Component.class);
((CubaFileUpload) uploadButton).setPasteZone(vComponent);
}
}
}
use of com.haulmont.cuba.web.toolkit.ui.CubaFileUpload in project cuba by cuba-platform.
the class WebFileUploadField method initUploadButton.
protected void initUploadButton() {
uploadButton = createComponent();
CubaFileUpload impl = (CubaFileUpload) uploadButton;
impl.setProgressWindowCaption(messages.getMainMessage("upload.uploadingProgressTitle"));
impl.setUnableToUploadFileMessage(messages.getMainMessage("upload.unableToUploadFile"));
impl.setCancelButtonCaption(messages.getMainMessage("upload.cancel"));
impl.setCaption(messages.getMainMessage("upload.submit"));
impl.setDropZonePrompt(messages.getMainMessage("upload.singleDropZonePrompt"));
impl.setDescription(null);
impl.setFileSizeLimit(getActualFileSizeLimit());
impl.setReceiver((fileName1, MIMEType) -> {
FileOutputStream outputStream;
try {
FileUploadingAPI.FileInfo fileInfo = fileUploading.createFile();
tempFileId = fileInfo.getId();
File tmpFile = fileInfo.getFile();
outputStream = new FileOutputStream(tmpFile);
} catch (Exception e) {
throw new RuntimeException("Unable to receive file", e);
}
return outputStream;
});
impl.addStartedListener(event -> fireFileUploadStart(event.getFileName(), event.getContentLength()));
impl.addFinishedListener(event -> fireFileUploadFinish(event.getFileName(), event.getContentLength()));
impl.addSucceededListener(event -> {
fileName = event.getFileName();
fileId = tempFileId;
saveFile(getFileDescriptor());
component.setFileNameButtonCaption(fileName);
fireFileUploadSucceed(event.getFileName(), event.getContentLength());
});
impl.addFailedListener(event -> {
try {
fileUploading.deleteFile(tempFileId);
tempFileId = null;
} catch (Exception e) {
if (e instanceof FileStorageException) {
FileStorageException fse = (FileStorageException) e;
if (fse.getType() != FileStorageException.Type.FILE_NOT_FOUND) {
log.warn(String.format("Could not remove temp file %s after broken uploading", tempFileId));
}
}
log.warn(String.format("Error while delete temp file %s", tempFileId));
}
fireFileUploadError(event.getFileName(), event.getContentLength(), event.getReason());
});
impl.addFileSizeLimitExceededListener(e -> {
String warningMsg = messages.formatMainMessage("upload.fileTooBig.message", e.getFileName(), getFileSizeLimitString());
getFrame().showNotification(warningMsg, NotificationType.WARNING);
});
impl.addFileExtensionNotAllowedListener(e -> {
String warningMsg = messages.formatMainMessage("upload.fileIncorrectExtension.message", e.getFileName());
getFrame().showNotification(warningMsg, NotificationType.WARNING);
});
}
Aggregations