Search in sources :

Example 1 with EmbeddedDatasource

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);
        }
    }
}
Also used : EmbeddedDatasource(com.haulmont.cuba.gui.data.EmbeddedDatasource) MetaClass(com.haulmont.chile.core.model.MetaClass) Element(org.dom4j.Element) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 2 with EmbeddedDatasource

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);
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) EmbeddedDatasource(com.haulmont.cuba.gui.data.EmbeddedDatasource) EmbeddedDatasource(com.haulmont.cuba.gui.data.EmbeddedDatasource) Field(com.haulmont.cuba.gui.components.Field) Entity(com.haulmont.cuba.core.entity.Entity) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) DatasourceValueSource(com.haulmont.cuba.gui.components.data.value.DatasourceValueSource) DatasourceValueSource(com.haulmont.cuba.gui.components.data.value.DatasourceValueSource) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) Editable(com.haulmont.cuba.gui.components.Component.Editable) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource)

Aggregations

MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)2 EmbeddedDatasource (com.haulmont.cuba.gui.data.EmbeddedDatasource)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 Entity (com.haulmont.cuba.core.entity.Entity)1 Editable (com.haulmont.cuba.gui.components.Component.Editable)1 Field (com.haulmont.cuba.gui.components.Field)1 HasValueSource (com.haulmont.cuba.gui.components.data.HasValueSource)1 ValueSource (com.haulmont.cuba.gui.components.data.ValueSource)1 EntityValueSource (com.haulmont.cuba.gui.components.data.meta.EntityValueSource)1 DatasourceValueSource (com.haulmont.cuba.gui.components.data.value.DatasourceValueSource)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1 Element (org.dom4j.Element)1