use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class CubaFileUploadWrapper method setInternalValue.
@Override
protected void setInternalValue(Object newValue) {
// noinspection unchecked
super.setInternalValue(newValue);
if (newValue != null) {
FileDescriptor fileDescriptor = (FileDescriptor) newValue;
setFileNameButtonCaption(fileDescriptor.getName());
} else {
setFileNameButtonCaption(null);
}
onSetInternalValue(newValue);
}
use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class WebImage method createImageResource.
protected Resource createImageResource(final Object resourceObject) {
if (resourceObject == null) {
return null;
}
if (resourceObject instanceof FileDescriptor) {
FileDescriptorResource imageResource = createResource(FileDescriptorResource.class);
imageResource.setFileDescriptor((FileDescriptor) resourceObject);
return imageResource;
}
if (resourceObject instanceof byte[]) {
StreamResource imageResource = createResource(StreamResource.class);
Supplier<InputStream> streamSupplier = () -> new ByteArrayDataProvider((byte[]) resourceObject).provide();
imageResource.setStreamSupplier(streamSupplier);
return imageResource;
}
throw new GuiDevelopmentException("The Image component supports only FileDescriptor and byte[] datasource property value binding", getFrame().getId());
}
use of com.haulmont.cuba.core.entity.FileDescriptor in project documentation by cuba-platform.
the class EmployeeEdit method init.
@Override
public void init(Map<String, Object> params) {
uploadField.addFileUploadSucceedListener(event -> {
FileDescriptor fd = uploadField.getFileDescriptor();
try {
fileUploadingAPI.putFileIntoStorage(uploadField.getFileId(), fd);
} catch (FileStorageException e) {
throw new RuntimeException("Error saving file to FileStorage", e);
}
getItem().setImageFile(dataSupplier.commit(fd));
displayImage();
});
uploadField.addFileUploadErrorListener(event -> showNotification("File upload error", NotificationType.HUMANIZED));
employeeDs.addItemPropertyChangeListener(event -> {
if ("imageFile".equals(event.getProperty()))
updateImageButtons(event.getValue() != null);
});
}
use of com.haulmont.cuba.core.entity.FileDescriptor in project documentation by cuba-platform.
the class EmployeeBrowse method init.
@Override
public void init(Map<String, Object> params) {
employeesTable.addGeneratedColumn("name", entity -> {
Image image = componentsFactory.createComponent(Image.class);
image.setScaleMode(ScaleMode.CONTAIN);
image.setHeight("40");
image.setWidth("40");
FileDescriptor userImageFile = entity.getImageFile();
image.setSource(FileDescriptorResource.class).setFileDescriptor(userImageFile);
Label userLogin = componentsFactory.createComponent(Label.class);
userLogin.setValue(entity.getName());
userLogin.setAlignment(Alignment.MIDDLE_LEFT);
HBoxLayout hBox = componentsFactory.createComponent(HBoxLayout.class);
hBox.setSpacing(true);
hBox.add(image);
hBox.add(userLogin);
return hBox;
});
}
use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class DesktopFileUploadField method getFileContent.
@Override
public InputStream getFileContent() {
if (contentProvider != null) {
return contentProvider.provide();
}
FileDescriptor fileDescriptor = getValue();
switch(mode) {
case MANUAL:
if (fileId == null) {
return new FileDataProvider(fileDescriptor).provide();
}
File file = fileUploading.getFile(fileId);
if (file != null) {
try {
return new FileInputStream(file);
} catch (FileNotFoundException e) {
log.error("Unable to get content of {}", file, e);
}
return null;
}
FileStorageService fileStorageService = AppBeans.get(FileStorageService.NAME);
try {
if (fileStorageService.fileExists(fileDescriptor)) {
return new FileDataProvider(fileDescriptor).provide();
}
} catch (FileStorageException e) {
log.error("Unable to get content of {}", fileDescriptor, e);
return null;
}
break;
case IMMEDIATE:
if (fileDescriptor != null) {
return new FileDataProvider(fileDescriptor).provide();
}
}
return null;
}
Aggregations