Search in sources :

Example 76 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class DataGridLoader method addDynamicAttributes.

protected void addDynamicAttributes(DataGrid component, Datasource ds, List<Column> availableColumns) {
    if (metadataTools.isPersistent(ds.getMetaClass())) {
        Set<CategoryAttribute> attributesToShow = dynamicAttributesGuiTools.getAttributesToShowOnTheScreen(ds.getMetaClass(), context.getFullFrameId(), component.getId());
        if (CollectionUtils.isNotEmpty(attributesToShow)) {
            ds.setLoadDynamicAttributes(true);
            for (CategoryAttribute attribute : attributesToShow) {
                final MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(ds.getMetaClass(), attribute);
                Object columnWithSameId = IterableUtils.find(availableColumns, column -> {
                    MetaPropertyPath propertyPath = column.getPropertyPath();
                    return propertyPath != null && propertyPath.equals(metaPropertyPath);
                });
                if (columnWithSameId != null) {
                    continue;
                }
                final Column column = component.addColumn(metaPropertyPath.getMetaProperty().getName(), metaPropertyPath);
                column.setCaption(LocaleHelper.isLocalizedValueDefined(attribute.getLocaleNames()) ? attribute.getLocaleName() : StringUtils.capitalize(attribute.getName()));
            }
        }
        dynamicAttributesGuiTools.listenDynamicAttributesChanges(ds);
    }
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) Column(com.haulmont.cuba.gui.components.DataGrid.Column) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 77 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class FieldGroupLoader method loadValidators.

protected void loadValidators(FieldGroup resultComponent, FieldGroup.FieldConfig field) {
    Element descriptor = field.getXmlDescriptor();
    @SuppressWarnings("unchecked") List<Element> validatorElements = (descriptor == null) ? null : descriptor.elements("validator");
    if (validatorElements != null) {
        if (!validatorElements.isEmpty()) {
            for (Element validatorElement : validatorElements) {
                Field.Validator validator = loadValidator(validatorElement);
                if (validator != null) {
                    field.addValidator(validator);
                }
            }
        }
    } else {
        Datasource ds;
        if (field.getDatasource() == null) {
            ds = resultComponent.getDatasource();
        } else {
            ds = field.getDatasource();
        }
        if (ds != null) {
            MetaClass metaClass = ds.getMetaClass();
            MetaPropertyPath metaPropertyPath = metaClass.getPropertyPath(field.getProperty());
            if (metaPropertyPath != null) {
                MetaProperty metaProperty = metaPropertyPath.getMetaProperty();
                Field.Validator validator = null;
                if (descriptor == null) {
                    validator = getDefaultValidator(metaProperty);
                } else if (!"timeField".equals(descriptor.attributeValue("field"))) {
                    // In this case we no need to use validator
                    validator = getDefaultValidator(metaProperty);
                }
                if (validator != null) {
                    field.addValidator(validator);
                }
            }
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) 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 78 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class FieldGroupLoader method applyPermissions.

protected void applyPermissions(Component fieldComponent) {
    if (fieldComponent instanceof DatasourceComponent) {
        DatasourceComponent dsComponent = (DatasourceComponent) fieldComponent;
        MetaPropertyPath propertyPath = dsComponent.getMetaPropertyPath();
        Datasource datasource = dsComponent.getDatasource();
        if (datasource != null && propertyPath != null) {
            MetaClass metaClass = datasource.getMetaClass();
            if (!security.isEntityAttrUpdatePermitted(metaClass, propertyPath.toString())) {
                dsComponent.setEditable(false);
            }
            if (!security.isEntityAttrReadPermitted(metaClass, propertyPath.toString())) {
                dsComponent.setVisible(false);
            }
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 79 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class WebAbstractTable method getInitialVisibleColumns.

protected List<Object> getInitialVisibleColumns() {
    List<Object> result = new ArrayList<>();
    MetaClass metaClass = datasource.getMetaClass();
    for (Column column : columnsOrder) {
        if (column.getId() instanceof MetaPropertyPath) {
            MetaPropertyPath propertyPath = (MetaPropertyPath) column.getId();
            if (security.isEntityAttrReadPermitted(metaClass, propertyPath.toString())) {
                result.add(column.getId());
            }
        } else {
            result.add(column.getId());
        }
    }
    return result;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 80 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class WebAbstractTable method getColumnCaption.

protected String getColumnCaption(Object columnId, Column column) {
    String caption = column.getCaption();
    if (caption != null) {
        return caption;
    }
    if (!(columnId instanceof MetaPropertyPath)) {
        return StringUtils.capitalize(getColumnCaption(columnId));
    }
    MetaPropertyPath mpp = (MetaPropertyPath) columnId;
    MetaProperty metaProperty = mpp.getMetaProperty();
    if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
        CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
        if (LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames())) {
            return categoryAttribute.getLocaleName();
        }
        caption = StringUtils.capitalize(categoryAttribute.getName());
    } else {
        caption = StringUtils.capitalize(getColumnCaption(columnId));
    }
    return caption;
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Aggregations

MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)84 MetaClass (com.haulmont.chile.core.model.MetaClass)34 MetaProperty (com.haulmont.chile.core.model.MetaProperty)27 Element (org.dom4j.Element)16 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)11 Entity (com.haulmont.cuba.core.entity.Entity)9 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)9 Datasource (com.haulmont.cuba.gui.data.Datasource)6 Table (com.haulmont.cuba.gui.components.Table)5 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)5 MessageTools (com.haulmont.cuba.core.global.MessageTools)4 Instance (com.haulmont.chile.core.model.Instance)3 Op (com.haulmont.cuba.core.global.filter.Op)3 FocusableTable (com.haulmont.cuba.desktop.sys.vcl.FocusableTable)3 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)3 Formatter (com.haulmont.cuba.gui.components.Formatter)3 Window (com.haulmont.cuba.gui.components.Window)3 CollectionFormatter (com.haulmont.cuba.gui.components.formatters.CollectionFormatter)3 GroupInfo (com.haulmont.cuba.gui.data.GroupInfo)3 java.util (java.util)3