use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class FileDownloadHelper method initGeneratedColumn.
/**
* Initializes a column for downloading files in a table displaying {@link FileDescriptor}s.
*
* @param table table that displays instances of the {@link FileDescriptor} entity
*/
public static void initGeneratedColumn(final Table table) {
final ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.NAME);
final ExportDisplay exportDisplay = AppBeans.get(ExportDisplay.NAME);
table.addGeneratedColumn("name", new Table.ColumnGenerator<FileDescriptor>() {
@Override
public Component generateCell(final FileDescriptor fd) {
if (fd == null) {
return componentsFactory.createComponent(Label.NAME);
}
if (PersistenceHelper.isNew(fd)) {
Label label = componentsFactory.createComponent(Label.class);
label.setValue(fd.getName());
return label;
} else {
Button button = componentsFactory.createComponent(Button.class);
button.setStyleName("link");
button.setAction(new AbstractAction("download") {
@Override
public void actionPerform(Component component) {
exportDisplay.show(fd);
}
@Override
public String getCaption() {
return fd.getName();
}
});
return button;
}
}
});
}
use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class WebFileUploadField method saveFile.
protected void saveFile(FileDescriptor fileDescriptor) {
switch(mode) {
case MANUAL:
internalValueChangedOnUpload = true;
setValue(fileDescriptor);
internalValueChangedOnUpload = false;
break;
case IMMEDIATE:
try {
fileUploading.putFileIntoStorage(fileId, fileDescriptor);
FileDescriptor committedDescriptor = commitFileDescriptor(fileDescriptor);
setValue(committedDescriptor);
} catch (FileStorageException e) {
log.error("Error has occurred during file saving", e);
}
break;
}
}
Aggregations