use of com.haulmont.cuba.gui.data.impl.DatasourceImplementation in project cuba by cuba-platform.
the class FileBrowser method init.
@Override
public void init(Map<String, Object> params) {
super.init(params);
filesTable.addAction(new ItemTrackingAction("download").withCaption(getMessage("download")).withHandler(event -> {
FileDescriptor fileDescriptor = filesTable.getSingleSelected();
if (fileDescriptor != null) {
exportDisplay.show(fileDescriptor, null);
}
}));
BaseAction multiUploadAction = new BaseAction("multiupload").withCaption(getMessage("multiupload")).withHandler(event -> {
if (!security.isEntityOpPermitted(FileDescriptor.class, EntityOp.READ)) {
throw new AccessDeniedException(PermissionType.ENTITY_OP, FileDescriptor.class.getSimpleName());
}
Window window = openWindow("multiuploadDialog", OpenType.DIALOG);
window.addCloseListener(actionId -> {
if (COMMIT_ACTION_ID.equals(actionId)) {
Collection<FileDescriptor> items = ((MultiUploader) window).getFiles();
for (FileDescriptor fdesc : items) {
boolean modified = filesDs.isModified();
filesDs.addItem(fdesc);
((DatasourceImplementation) filesDs).setModified(modified);
}
filesTable.focus();
}
});
});
multiUploadAction.setEnabled(security.isEntityOpPermitted(FileDescriptor.class, EntityOp.CREATE));
multiUploadBtn.setAction(multiUploadAction);
}
use of com.haulmont.cuba.gui.data.impl.DatasourceImplementation in project cuba by cuba-platform.
the class WebEntityLinkField method afterCommitOpenedEntity.
protected void afterCommitOpenedEntity(Entity item) {
MetaProperty metaProperty = getMetaPropertyForEditedValue();
if (metaProperty != null && metaProperty.getRange().isClass()) {
if (getValueSource() != null) {
boolean ownerDsModified = false;
boolean nonModifiedInTable = false;
DatasourceImplementation ownerDs = null;
CollectionContainer ownerCollectionCont = null;
if (getCollectionDatasourceFromOwner() != null) {
ownerDs = ((DatasourceImplementation) getCollectionDatasourceFromOwner());
nonModifiedInTable = !ownerDs.getItemsToUpdate().contains(((EntityValueSource) getValueSource()).getItem());
ownerDsModified = ownerDs.isModified();
} else if (getCollectionContainerFromOwner() != null) {
ownerCollectionCont = ((ContainerDataUnit) owner.getItems()).getContainer();
ownerCollectionCont.mute();
}
// noinspection unchecked
setValueSilently((V) item);
// remove from items to update if it was not modified before setValue
if (ownerDs != null) {
if (nonModifiedInTable) {
ownerDs.getItemsToUpdate().remove(getDatasource().getItem());
}
ownerDs.setModified(ownerDsModified);
} else if (ownerCollectionCont != null) {
ownerCollectionCont.unmute();
}
} else {
// noinspection unchecked
setValue((V) item);
}
// if we edit property with non Entity type and set ListComponent owner
} else if (owner != null) {
if (getCollectionDatasourceFromOwner() != null) {
// noinspection unchecked
getCollectionDatasourceFromOwner().updateItem(item);
} else if (getCollectionContainerFromOwner() != null) {
// do not listen changes in collection
getCollectionContainerFromOwner().mute();
// noinspection unchecked
getCollectionContainerFromOwner().replaceItem(item);
setValueSilently(item.getValueEx(getMetaPropertyPath()));
// listen changes
getCollectionContainerFromOwner().unmute();
}
if (owner instanceof Focusable) {
// focus owner
((Focusable) owner).focus();
}
// if we edit property with non Entity type
} else {
// noinspection unchecked
setValueSilently((V) item);
}
}
use of com.haulmont.cuba.gui.data.impl.DatasourceImplementation in project cuba by cuba-platform.
the class AttributeEditor method initAttributesFieldGroup.
@SuppressWarnings("unchecked")
protected void initAttributesFieldGroup() {
defaultBoolean.setOptionsMap(getBooleanOptions());
dataType.setOptionsMap(getTypeOptions());
entityClassField.setOptionsMap(getEntityOptions());
defaultEntityId.addValueChangeListener(e -> {
Entity entity = e.getValue();
if (entity != null) {
getItem().setObjectDefaultEntityId(referenceToEntitySupport.getReferenceId(entity));
} else {
getItem().setObjectDefaultEntityId(null);
}
((DatasourceImplementation<CategoryAttribute>) attributeDs).modified(getItem());
});
enumerationListEditor = uiComponents.create(ListEditor.NAME);
enumerationListEditor.setWidth("100%");
enumerationListEditor.setItemType(ListEditor.ItemType.STRING);
enumerationListEditor.setRequired(true);
enumerationListEditor.setRequiredMessage(getMessage("enumRequired"));
enumerationListEditor.addValueChangeListener(e -> {
List<?> list = e.getValue() != null ? e.getValue() : Collections.emptyList();
getItem().setEnumeration(Joiner.on(",").join(list));
});
if (localizedFrame != null) {
enumerationListEditor.setEditorWindowId("localizedEnumerationWindow");
enumerationListEditor.setEditorParamsSupplier(() -> ParamsMap.of("enumerationLocales", getItem().getEnumerationLocales()));
enumerationListEditor.addEditorCloseListener(closeEvent -> {
if (closeEvent.getActionId().equals(COMMIT_ACTION_ID)) {
LocalizedEnumerationWindow enumerationWindow = (LocalizedEnumerationWindow) closeEvent.getWindow();
getItem().setEnumerationLocales(enumerationWindow.getLocalizedValues());
}
});
}
optionalAttributeFieldGroup.getFieldNN("enumeration").setComponent(enumerationListEditor);
validatorGroovyScript.setContextHelpIconClickHandler(e -> showMessageDialog(getMessage("validatorScript"), getMessage("validatorScriptHelp"), MessageType.CONFIRMATION_HTML.modal(false).width(560f)));
validatorGroovyScript.setHeight(themeConstants.get("cuba.gui.AttributeEditor.validatorGroovyScriptField.height"));
}
Aggregations