Search in sources :

Example 1 with Editable

use of com.haulmont.cuba.gui.components.Component.Editable 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)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 EmbeddedDatasource (com.haulmont.cuba.gui.data.EmbeddedDatasource)1