Search in sources :

Example 86 with MetaProperty

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

the class EntityLogBrowser method fillAttributes.

protected void fillAttributes(String metaClassName, LoggedEntity item, boolean editable) {
    clearAttributes();
    setSelectAllCheckBox(false);
    if (metaClassName != null) {
        MetaClass metaClass = metadata.getExtendedEntities().getEffectiveMetaClass(metadata.getClassNN(metaClassName));
        List<MetaProperty> metaProperties = new ArrayList<>(metaClass.getProperties());
        selectAllCheckBox.setEditable(editable);
        Set<LoggedAttribute> enabledAttr = null;
        if (item != null)
            enabledAttr = item.getAttributes();
        for (MetaProperty property : metaProperties) {
            if (allowLogProperty(property, null)) {
                if (metadata.getTools().isEmbedded(property)) {
                    MetaClass embeddedMetaClass = property.getRange().asClass();
                    for (MetaProperty embeddedProperty : embeddedMetaClass.getProperties()) {
                        if (allowLogProperty(embeddedProperty, null)) {
                            addAttribute(enabledAttr, String.format("%s.%s", property.getName(), embeddedProperty.getName()), editable);
                        }
                    }
                } else {
                    addAttribute(enabledAttr, property.getName(), editable);
                }
            }
        }
        Collection<CategoryAttribute> attributes = dynamicAttributes.getAttributesForMetaClass(metaClass);
        if (attributes != null) {
            for (CategoryAttribute categoryAttribute : attributes) {
                MetaPropertyPath propertyPath = DynamicAttributesUtils.getMetaPropertyPath(metaClass, categoryAttribute);
                MetaProperty property = propertyPath.getMetaProperty();
                if (allowLogProperty(property, categoryAttribute)) {
                    addAttribute(enabledAttr, property.getName(), editable);
                }
            }
        }
    }
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 87 with MetaProperty

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

the class DesktopAbstractTable method addColumn.

@Override
public void addColumn(Column column) {
    checkNotNullArgument(column, "Column must be non null");
    Object columnId = column.getId();
    columns.put(columnId, column);
    columnsOrder.add(column);
    if (tableModel != null) {
        tableModel.addColumn(column);
    }
    if (datasource != null && column.isEditable() && columnId instanceof MetaPropertyPath) {
        if (!editableColumns.contains(columnId)) {
            editableColumns.add((MetaPropertyPath) columnId);
        }
    }
    setColumnIdentifiers();
    refresh();
    column.setOwner(this);
    if (column.getFormatter() == null && columnId instanceof MetaPropertyPath) {
        MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
        if (Collection.class.isAssignableFrom(metaProperty.getJavaType())) {
            final Formatter collectionFormatter = new CollectionFormatter();
            column.setFormatter(collectionFormatter);
        }
    }
}
Also used : CollectionFormatter(com.haulmont.cuba.gui.components.formatters.CollectionFormatter) Formatter(com.haulmont.cuba.gui.components.Formatter) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty) CollectionFormatter(com.haulmont.cuba.gui.components.formatters.CollectionFormatter)

Example 88 with MetaProperty

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

the class DesktopCurrencyField method setDatasource.

@Override
public void setDatasource(Datasource datasource, String property) {
    super.setDatasource(datasource, property);
    if (datasource != null && !DynamicAttributesUtils.isDynamicAttribute(property)) {
        MetaProperty metaProperty = datasource.getMetaClass().getPropertyNN(property);
        Object annotation = metaProperty.getAnnotations().get(CurrencyValue.class.getName());
        if (annotation == null)
            return;
        // noinspection unchecked
        currency = (String) ((Map<String, Object>) annotation).get("currency");
    }
}
Also used : CurrencyValue(com.haulmont.cuba.core.entity.annotation.CurrencyValue) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Map(java.util.Map)

Example 89 with MetaProperty

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

the class AttributeAccessSupport method calculateComponentState.

protected ComponentState calculateComponentState(Entity entity, MetaPropertyPath propertyPath) {
    MetaProperty[] metaProperties = propertyPath.getMetaProperties();
    ComponentState componentState = new ComponentState();
    for (int i = 0; i < metaProperties.length; i++) {
        MetaProperty metaProperty = metaProperties[i];
        String name = metaProperty.getName();
        SecurityState securityState = getSecurityState(entity);
        if (securityState != null) {
            componentState.hidden = test(componentState.hidden, securityState.getHiddenAttributes(), name);
            componentState.readOnly = test(componentState.readOnly, securityState.getReadonlyAttributes(), name);
            if (i == metaProperties.length - 1) {
                componentState.required = test(componentState.required, securityState.getRequiredAttributes(), name);
            }
        }
        if (i != metaProperties.length - 1) {
            entity = entity.getValue(name);
            if (entity == null) {
                break;
            }
        }
    }
    return componentState;
}
Also used : MetaProperty(com.haulmont.chile.core.model.MetaProperty) SecurityState(com.haulmont.cuba.core.entity.SecurityState)

Example 90 with MetaProperty

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

the class ComponentsHelper method handleFilteredAttributes.

/**
 * Set field's "required" flag to false if the value has been filtered by Row Level Security
 * This is necessary to allow user to submit form with filtered attribute even if attribute is required
 */
public static void handleFilteredAttributes(Field component, Datasource datasource, MetaPropertyPath mpp) {
    if (component.isRequired() && datasource.getState() == Datasource.State.VALID && datasource.getItem() != null && mpp.getMetaProperty().getRange().isClass()) {
        Entity targetItem = datasource.getItem();
        MetaProperty[] propertiesChain = mpp.getMetaProperties();
        if (propertiesChain.length > 1) {
            String basePropertyItem = Arrays.stream(propertiesChain).limit(propertiesChain.length - 1).map(MetadataObject::getName).collect(Collectors.joining("."));
            targetItem = datasource.getItem().getValueEx(basePropertyItem);
        }
        if (targetItem instanceof BaseGenericIdEntity) {
            String metaPropertyName = mpp.getMetaProperty().getName();
            Object value = targetItem.getValue(metaPropertyName);
            BaseGenericIdEntity baseGenericIdEntity = (BaseGenericIdEntity) targetItem;
            String[] filteredAttributes = getFilteredAttributes(baseGenericIdEntity);
            if (value == null && filteredAttributes != null && ArrayUtils.contains(filteredAttributes, metaPropertyName)) {
                component.setRequired(false);
            }
        }
    }
}
Also used : BaseGenericIdEntity(com.haulmont.cuba.core.entity.BaseGenericIdEntity) Entity(com.haulmont.cuba.core.entity.Entity) BaseGenericIdEntity(com.haulmont.cuba.core.entity.BaseGenericIdEntity) MetadataObject(com.haulmont.chile.core.model.MetadataObject) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Aggregations

MetaProperty (com.haulmont.chile.core.model.MetaProperty)157 MetaClass (com.haulmont.chile.core.model.MetaClass)102 Entity (com.haulmont.cuba.core.entity.Entity)44 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)26 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)21 Range (com.haulmont.chile.core.model.Range)13 Nullable (javax.annotation.Nullable)11 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)10 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)9 java.util (java.util)9 Element (org.dom4j.Element)9 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)8 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 Query (com.haulmont.cuba.core.Query)5 SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)5 Collection (java.util.Collection)5 MessageTools (com.haulmont.cuba.core.global.MessageTools)4 PropertyDatasource (com.haulmont.cuba.gui.data.PropertyDatasource)4 Logger (org.slf4j.Logger)4