Search in sources :

Example 71 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class BulkEditorWindow method createFetchPlan.

protected FetchPlan createFetchPlan(MetaClass metaClass) {
    FetchPlanBuilder builder = fetchPlans.builder(metaClass.getJavaClass());
    for (MetaProperty metaProperty : metaClass.getProperties()) {
        String fqn = generateFqn(metaProperty, null);
        if (!managedFields.containsKey(fqn) && !managedEmbeddedProperties.contains(fqn)) {
            continue;
        }
        addFetchPlanProperties(builder, metaProperty, fqn);
    }
    return builder.build();
}
Also used : MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 72 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class BulkEditorWindow method createEmbeddedFetchPlan.

protected FetchPlan createEmbeddedFetchPlan(MetaClass metaClass, String fqnPrefix) {
    FetchPlanBuilder builder = fetchPlans.builder(metaClass.getJavaClass());
    for (MetaProperty metaProperty : metaClass.getProperties()) {
        String fqn = generateFqn(metaProperty, fqnPrefix);
        if (!managedFields.containsKey(fqn)) {
            continue;
        }
        addFetchPlanProperties(builder, metaProperty, fqn);
    }
    return builder.build();
}
Also used : MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 73 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class BulkEditorWindow method getManagedFields.

protected List<ManagedField> getManagedFields(MetaClass metaClass, @Nullable String fqnPrefix, @Nullable String localePrefix) {
    List<ManagedField> managedFields = new ArrayList<>();
    for (MetaProperty metaProperty : metaClass.getProperties()) {
        if (isManagedAttribute(metaClass, metaProperty)) {
            String fqn = generateFqn(metaProperty, fqnPrefix);
            String propertyCaption = generatePropertyCaption(metaClass, metaProperty, localePrefix);
            if (!metadataTools.isEmbedded(metaProperty)) {
                managedFields.add(new ManagedField(fqn, metaProperty, propertyCaption, fqnPrefix));
            } else {
                List<ManagedField> nestedFields = getManagedFields(metaProperty, fqn, propertyCaption);
                if (nestedFields.size() > 0) {
                    managedEmbeddedProperties.add(fqn);
                }
                managedFields.addAll(nestedFields);
            }
        }
    }
    return managedFields;
}
Also used : MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 74 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class BulkEditorWindow method ensureEmbeddedPropertyCreated.

protected void ensureEmbeddedPropertyCreated(E item, String propertyPath) {
    if (!StringUtils.contains(propertyPath, ".")) {
        return;
    }
    MetaPropertyPath path = context.getMetaClass().getPropertyPath(propertyPath);
    if (path != null) {
        Object currentItem = item;
        for (MetaProperty property : path.getMetaProperties()) {
            if (metadataTools.isEmbedded(property)) {
                Object currentItemValue = EntityValues.getValue(currentItem, property.getName());
                if (currentItemValue == null) {
                    Object newItem = metadata.create(property.getRange().asClass());
                    EntityValues.setValue(currentItem, property.getName(), newItem);
                    currentItem = newItem;
                } else {
                    currentItem = currentItemValue;
                }
            } else {
                break;
            }
        }
    }
}
Also used : MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 75 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class StandardEditor method isEntityModifiedRecursive.

protected boolean isEntityModifiedRecursive(Object entity, DataContext dataContext, HashSet<Object> visited) {
    if (visited.contains(entity)) {
        return false;
    }
    visited.add(entity);
    if (dataContext.isModified(entity) || dataContext.isRemoved(entity))
        return true;
    Metadata metadata = getApplicationContext().getBean(Metadata.class);
    for (MetaProperty property : metadata.getClass(entity).getProperties()) {
        if (property.getRange().isClass()) {
            if (getEntityStates().isLoaded(entity, property.getName())) {
                Object value = EntityValues.getValue(entity, property.getName());
                if (value != null) {
                    if (value instanceof Collection) {
                        for (Object item : ((Collection) value)) {
                            if (isEntityModifiedRecursive(item, dataContext, visited)) {
                                return true;
                            }
                        }
                    } else {
                        if (isEntityModifiedRecursive(value, dataContext, visited)) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Aggregations

MetaProperty (io.jmix.core.metamodel.model.MetaProperty)267 MetaClass (io.jmix.core.metamodel.model.MetaClass)162 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)53 Nullable (javax.annotation.Nullable)36 Range (io.jmix.core.metamodel.model.Range)23 Autowired (org.springframework.beans.factory.annotation.Autowired)23 Collectors (java.util.stream.Collectors)22 java.util (java.util)20 Component (org.springframework.stereotype.Component)18 Entity (io.jmix.core.Entity)17 EntityValues (io.jmix.core.entity.EntityValues)17 io.jmix.core (io.jmix.core)16 Logger (org.slf4j.Logger)15 LoggerFactory (org.slf4j.LoggerFactory)15 ArrayList (java.util.ArrayList)12 Collection (java.util.Collection)12 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)10 Metadata (io.jmix.core.Metadata)9 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8