Search in sources :

Example 1 with Field

use of com.haulmont.cuba.gui.components.Field in project cuba by cuba-platform.

the class BulkEditorLoader method loadValidators.

protected void loadValidators(BulkEditor component, Element element) {
    List<Element> validatorElements = Dom4j.elements(element, "validator");
    if (!validatorElements.isEmpty()) {
        List<Field.Validator> modelValidators = new ArrayList<>();
        Map<String, Field.Validator> fieldValidators = new LinkedHashMap<>();
        for (Element validatorElement : validatorElements) {
            Field.Validator validator = loadValidator(validatorElement);
            String field = validatorElement.attributeValue("field");
            if (StringUtils.isNotBlank(field)) {
                fieldValidators.put(field, validator);
            } else {
                modelValidators.add(validator);
            }
        }
        if (!fieldValidators.isEmpty()) {
            component.setFieldValidators(fieldValidators);
        }
        if (!modelValidators.isEmpty()) {
            component.setModelValidators(modelValidators);
        }
    }
}
Also used : Field(com.haulmont.cuba.gui.components.Field) Element(org.dom4j.Element)

Example 2 with Field

use of com.haulmont.cuba.gui.components.Field in project cuba by cuba-platform.

the class AttributeAccessSupport method visitComponent.

protected void visitComponent(DatasourceComponent component, boolean reset) {
    Datasource datasource = component.getDatasource();
    MetaPropertyPath propertyPath = component.getMetaPropertyPath();
    if (datasource == null || datasource.getState() != Datasource.State.VALID || propertyPath == null || datasource.getItem() == null) {
        return;
    }
    if (reset) {
        component.setVisible(security.isEntityAttrReadPermitted(datasource.getMetaClass(), propertyPath.toString()));
        component.setEditable(security.isEntityAttrUpdatePermitted(datasource.getMetaClass(), propertyPath.toString()));
        if (component instanceof Field) {
            ((Field) component).setRequired(propertyPath.getMetaProperty().isMandatory());
        }
    }
    ComponentState componentState = calculateComponentState(datasource.getItem(), propertyPath);
    if (componentState.hidden) {
        component.setVisible(false);
    }
    if (componentState.readOnly) {
        component.setEditable(false);
    }
    if (component instanceof Field) {
        if (componentState.required && component.isEditable() && component.isVisible()) {
            ((Field) component).setRequired(true);
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Field(com.haulmont.cuba.gui.components.Field) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Aggregations

Field (com.haulmont.cuba.gui.components.Field)2 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1 Element (org.dom4j.Element)1