use of com.haulmont.cuba.gui.data.EmbeddedDatasource in project cuba by cuba-platform.
the class FieldGroupLoader method loadEditable.
protected void loadEditable(FieldGroup resultComponent, FieldGroup.FieldConfig field) {
Element element = field.getXmlDescriptor();
if (element != null) {
String editable = element.attributeValue("editable");
if (StringUtils.isNotEmpty(editable)) {
field.setEditable(Boolean.parseBoolean(editable));
}
}
if (!field.isCustom() && BooleanUtils.isNotFalse(field.isEditable())) {
MetaClass metaClass = getMetaClass(resultComponent, field);
MetaPropertyPath propertyPath = getMetadataTools().resolveMetaPropertyPath(metaClass, field.getProperty());
checkNotNullArgument(propertyPath, "Could not resolve property path '%s' in '%s'", field.getId(), metaClass);
boolean permittedIfEmbedded = true;
if (getMetadataTools().isEmbeddable(metaClass)) {
MetaClass parentMetaClass = getParentEntityMetaClass(resultComponent);
MetaProperty embeddedProperty = ((EmbeddedDatasource) field.getTargetDatasource()).getProperty();
permittedIfEmbedded = getSecurity().isEntityOpPermitted(parentMetaClass, EntityOp.UPDATE) && getSecurity().isEntityAttrPermitted(parentMetaClass, embeddedProperty.getName(), EntityAttrAccess.MODIFY);
if (permittedIfEmbedded && propertyPath.length() > 1) {
for (MetaProperty property : propertyPath.getMetaProperties()) {
if (!getSecurity().isEntityAttrUpdatePermitted(property.getDomain(), property.getName())) {
permittedIfEmbedded = false;
break;
}
}
}
}
if (!getSecurity().isEntityAttrUpdatePermitted(metaClass, propertyPath.toString()) || !permittedIfEmbedded) {
field.setEditable(false);
}
}
}
use of com.haulmont.cuba.gui.data.EmbeddedDatasource in project cuba by cuba-platform.
the class AttributeAccessSupport method visitComponent.
protected void visitComponent(com.haulmont.cuba.gui.components.Component component, boolean reset) {
if (!(component instanceof HasValueSource)) {
return;
}
ValueSource valueSource = ((HasValueSource) component).getValueSource();
if (!(valueSource instanceof EntityValueSource)) {
return;
}
EntityValueSource entityValueSource = (EntityValueSource) valueSource;
MetaPropertyPath propertyPath = entityValueSource.getMetaPropertyPath();
if (valueSource.getState() != BindingState.ACTIVE || propertyPath == null) {
return;
}
if (reset) {
component.setVisible(security.isEntityAttrReadPermitted(entityValueSource.getEntityMetaClass(), propertyPath.toString()));
if (component instanceof Editable) {
((Editable) component).setEditable(security.isEntityAttrUpdatePermitted(entityValueSource.getEntityMetaClass(), propertyPath.toString()));
}
if (component instanceof Field) {
((Field) component).setRequired(propertyPath.getMetaProperty().isMandatory());
}
}
Entity item = entityValueSource.getItem();
ComponentState componentState = calculateComponentState(item, propertyPath);
if (metadataTools.isEmbeddable(item.getMetaClass()) && entityValueSource instanceof DatasourceValueSource) {
Datasource ds = ((DatasourceValueSource) entityValueSource).getDatasource();
if (ds instanceof EmbeddedDatasource) {
Datasource masterDs = ((EmbeddedDatasource) ds).getMaster();
item = masterDs.getItem();
componentState = calculateComponentState(item, metadataTools.resolveMetaPropertyPath(masterDs.getMetaClass(), ((EmbeddedDatasource) ds).getProperty().getName() + "." + propertyPath));
}
}
if (componentState.hidden) {
component.setVisible(false);
}
if (componentState.readOnly) {
if (component instanceof Editable) {
((Editable) component).setEditable(false);
}
}
if (component instanceof Field) {
if (componentState.required && ((Field) component).isEditable() && component.isVisibleRecursive()) {
((Field) component).setRequired(true);
}
}
}
Aggregations