Search in sources :

Example 91 with MetaProperty

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

the class BulkEditorWindow method createNestedEmbeddedDatasources.

protected void createNestedEmbeddedDatasources(Datasource masterDs, MetaClass metaClass, String fqnPrefix) {
    for (MetaProperty metaProperty : metaClass.getProperties()) {
        if (MetaProperty.Type.ASSOCIATION == metaProperty.getType() || MetaProperty.Type.COMPOSITION == metaProperty.getType()) {
            String fqn = metaProperty.getName();
            if (StringUtils.isNotEmpty(fqnPrefix)) {
                fqn = fqnPrefix + "." + fqn;
            }
            if (managedEmbeddedProperties.contains(fqn) && metadataTools.isEmbedded(metaProperty)) {
                MetaClass propertyMetaClass = metaProperty.getRange().asClass();
                @SuppressWarnings("unchecked") NestedDatasource<Entity> propertyDs = new EmbeddedDatasourceImpl();
                propertyDs.setup(fqn + "Ds", masterDs, metaProperty.getName());
                propertyDs.setAllowCommit(false);
                createNestedEmbeddedDatasources(propertyDs, propertyMetaClass, fqn);
                datasources.put(fqn, propertyDs);
                dsContext.register(propertyDs);
            }
        }
    }
}
Also used : BaseGenericIdEntity(com.haulmont.cuba.core.entity.BaseGenericIdEntity) Entity(com.haulmont.cuba.core.entity.Entity) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty) EmbeddedDatasourceImpl(com.haulmont.cuba.gui.data.impl.EmbeddedDatasourceImpl)

Example 92 with MetaProperty

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

the class BulkEditorWindow method getManagedFields.

protected List<ManagedField> getManagedFields(MetaProperty embeddedProperty, String fqnPrefix, String localePrefix) {
    List<ManagedField> managedFields = new ArrayList<>();
    MetaClass metaClass = embeddedProperty.getRange().asClass();
    for (MetaProperty metaProperty : metaClass.getProperties()) {
        if (isManagedAttribute(metaClass, metaProperty)) {
            String fqn = fqnPrefix + "." + metaProperty.getName();
            String localeName = localePrefix + " " + messageTools.getPropertyCaption(metaClass, metaProperty.getName());
            if (!metadataTools.isEmbedded(metaProperty)) {
                managedFields.add(new ManagedField(fqn, metaProperty, localeName, fqnPrefix));
            } else {
                List<ManagedField> nestedFields = getManagedFields(metaProperty, fqn, localeName);
                if (nestedFields.size() > 0) {
                    managedEmbeddedProperties.add(fqn);
                }
                managedFields.addAll(nestedFields);
            }
        }
    }
    return managedFields;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 93 with MetaProperty

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

the class BulkEditorWindow method createEmbeddedFields.

/**
 * Recursively instantiates the embedded properties.
 * E.g. embedded properties of the embedded property will also be instantiated.
 *
 * @param metaClass meta class of the entity
 * @param item      entity instance
 */
protected void createEmbeddedFields(MetaClass metaClass, Entity item, String fqnPrefix) {
    for (MetaProperty metaProperty : metaClass.getProperties()) {
        String fqn = metaProperty.getName();
        if (StringUtils.isNotEmpty(fqnPrefix)) {
            fqn = fqnPrefix + "." + fqn;
        }
        if (managedEmbeddedProperties.contains(fqn) && metadataTools.isEmbedded(metaProperty)) {
            MetaClass embeddedMetaClass = metaProperty.getRange().asClass();
            Entity embedded = item.getValue(metaProperty.getName());
            if (embedded == null) {
                embedded = metadata.create(embeddedMetaClass);
                item.setValue(metaProperty.getName(), embedded);
            }
            createEmbeddedFields(embeddedMetaClass, embedded, fqn);
        }
    }
}
Also used : BaseGenericIdEntity(com.haulmont.cuba.core.entity.BaseGenericIdEntity) Entity(com.haulmont.cuba.core.entity.Entity) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 94 with MetaProperty

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

the class BulkEditorWindow method ensureEmbeddedPropertyCreated.

protected void ensureEmbeddedPropertyCreated(Entity item, String propertyPath) {
    if (!StringUtils.contains(propertyPath, ".")) {
        return;
    }
    MetaPropertyPath path = metaClass.getPropertyPath(propertyPath);
    if (path != null) {
        Entity currentItem = item;
        for (MetaProperty property : path.getMetaProperties()) {
            if (metadataTools.isEmbedded(property)) {
                Object currentItemValue = currentItem.getValue(property.getName());
                if (currentItemValue == null) {
                    Entity newItem = metadata.create(property.getRange().asClass());
                    currentItem.setValue(property.getName(), newItem);
                    currentItem = newItem;
                } else {
                    currentItem = (Entity) currentItemValue;
                }
            } else {
                break;
            }
        }
    }
}
Also used : BaseGenericIdEntity(com.haulmont.cuba.core.entity.BaseGenericIdEntity) Entity(com.haulmont.cuba.core.entity.Entity) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 95 with MetaProperty

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

the class BulkEditorWindow method getManagedFields.

protected List<ManagedField> getManagedFields(MetaClass metaClass) {
    List<ManagedField> managedFields = new ArrayList<>();
    // sort Fields
    for (MetaProperty metaProperty : metaClass.getProperties()) {
        if (isManagedAttribute(metaClass, metaProperty)) {
            String propertyCaption = messageTools.getPropertyCaption(metaClass, metaProperty.getName());
            if (!metadataTools.isEmbedded(metaProperty)) {
                managedFields.add(new ManagedField(metaProperty.getName(), metaProperty, propertyCaption, null));
            } else {
                List<ManagedField> nestedFields = getManagedFields(metaProperty, metaProperty.getName(), propertyCaption);
                if (nestedFields.size() > 0) {
                    managedEmbeddedProperties.add(metaProperty.getName());
                }
                managedFields.addAll(nestedFields);
            }
        }
    }
    if (loadDynamicAttributes) {
        List<CategoryAttribute> categoryAttributes = (List<CategoryAttribute>) dynamicAttributes.getAttributesForMetaClass(metaClass);
        if (!categoryAttributes.isEmpty()) {
            for (CategoryAttribute attribute : categoryAttributes) {
                MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(metaClass, attribute);
                String propertyCaption = attribute.getLocaleName();
                if (isManagedDynamicAttribute(metaClass, metaPropertyPath.getMetaProperty())) {
                    managedFields.add(new ManagedField(metaPropertyPath.getMetaProperty().getName(), metaPropertyPath.getMetaProperty(), propertyCaption, null));
                }
            }
        }
    }
    return managedFields;
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) 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