Search in sources :

Example 1 with MetaClass

use of io.jmix.core.metamodel.model.MetaClass in project jmix-docs by Haulmont.

the class CustomerService method printOrderProperties.

public void printOrderProperties() {
    // <1>
    MetaClass metaClass = metadata.getClass(Order.class);
    for (MetaProperty metaProperty : metaClass.getProperties()) {
        // <2>
        // <3>
        String propertyName = metaProperty.getName();
        // <4>
        MetaProperty.Type propertyType = metaProperty.getType();
        // <5>
        Class<?> javaType = metaProperty.getJavaType();
        // <6>
        Range propertyRange = metaProperty.getRange();
        String info = "name: " + propertyName + "\n type: " + propertyType + "\n Java type: " + javaType + "\n range: " + propertyRange;
        if (propertyRange.isClass()) {
            // <7>
            // <8>
            MetaClass refMetaClass = propertyRange.asClass();
            // <9>
            Range.Cardinality cardinality = propertyRange.getCardinality();
            info += "\n reference to: " + refMetaClass;
            info += "\n cardinality: " + cardinality;
        } else if (propertyRange.isEnum()) {
            // <10>
            // <11>
            Enumeration<?> enumeration = propertyRange.asEnumeration();
            info += "\n enum: " + enumeration;
        } else if (propertyRange.isDatatype()) {
            // <12>
            // <13>
            Datatype<Object> propertyDatatype = propertyRange.asDatatype();
            info += "\n data type: " + propertyDatatype;
        }
        System.out.println(info);
    }
}
Also used : Enumeration(io.jmix.core.metamodel.datatype.Enumeration) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Range(io.jmix.core.metamodel.model.Range)

Example 2 with MetaClass

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

the class EntityLoadInfoBuilder method contains.

/**
 * Check whether an info about the given entity instance is contained in the collection.
 *
 * @param collection collection of EntityLoadInfo objects
 * @param entity     entity instance
 * @return true if the collection contains an info about the given entity instance. View part of the info is ignored.
 */
public boolean contains(Collection<EntityLoadInfo> collection, Entity entity) {
    Preconditions.checkNotNullArgument(collection, "collection is null");
    Preconditions.checkNotNullArgument(entity, "entity is null");
    MetaClass metaClass = metadata.getClass(entity.getClass());
    for (EntityLoadInfo info : collection) {
        if (metaClass.equals(info.getMetaClass()) && EntityValues.getId(entity).equals(info.getId()))
            return true;
    }
    return false;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass)

Example 3 with MetaClass

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

the class EntityLoadInfoBuilder method create.

/**
 * Create a new info instance.
 *
 * @param entity   entity instance
 * @param viewName view name, can be null
 * @return info instance
 */
public EntityLoadInfo create(Entity entity, @Nullable String viewName) {
    Objects.requireNonNull(entity, "entity is null");
    MetaClass metaClass = metadata.getSession().getClass(entity.getClass());
    MetaProperty primaryKeyProperty = metadataTools.getPrimaryKeyProperty(metaClass);
    boolean stringKey = primaryKeyProperty != null && primaryKeyProperty.getJavaType().equals(String.class);
    return new EntityLoadInfo(EntityValues.getId(entity), metaClass, viewName, stringKey);
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 4 with MetaClass

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

the class OriginalEntityLoadInfo method create.

/**
 * Create a new info instance.
 * @param entity    entity instance
 * @return          info instance
 */
public static OriginalEntityLoadInfo create(Entity entity) {
    Objects.requireNonNull(entity, "entity is null");
    Metadata metadata = AppBeans.get(Metadata.class);
    MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
    ExtendedEntities extendedEntities = AppBeans.get(ExtendedEntities.class);
    MetaClass metaClass = metadata.getSession().getClass(entity.getClass());
    MetaClass originalMetaClass = extendedEntities.getOriginalMetaClass(metaClass);
    if (originalMetaClass != null) {
        metaClass = originalMetaClass;
    }
    MetaProperty primaryKeyProperty = metadataTools.getPrimaryKeyProperty(metaClass);
    boolean stringKey = primaryKeyProperty != null && primaryKeyProperty.getJavaType().equals(String.class);
    return new OriginalEntityLoadInfo((UUID) EntityValues.getId(entity), metaClass, stringKey);
}
Also used : ExtendedEntities(io.jmix.core.ExtendedEntities) MetadataTools(io.jmix.core.MetadataTools) MetaClass(io.jmix.core.metamodel.model.MetaClass) Metadata(io.jmix.core.Metadata) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 5 with MetaClass

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

the class View method addSystemProperties.

public View addSystemProperties() {
    io.jmix.core.Metadata metadata = AppBeans.get(Metadata.class);
    MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
    MetaClass metaClass = metadata.getClass(getEntityClass());
    for (String propertyName : metadataTools.getSystemProperties(metaClass)) {
        addProperty(propertyName);
    }
    return this;
}
Also used : io.jmix.core(io.jmix.core) MetaClass(io.jmix.core.metamodel.model.MetaClass) Metadata(io.jmix.core.Metadata)

Aggregations

MetaClass (io.jmix.core.metamodel.model.MetaClass)502 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)162 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)71 Nullable (javax.annotation.Nullable)59 Autowired (org.springframework.beans.factory.annotation.Autowired)34 Collectors (java.util.stream.Collectors)30 java.util (java.util)26 Component (org.springframework.stereotype.Component)26 io.jmix.core (io.jmix.core)25 Logger (org.slf4j.Logger)23 LoggerFactory (org.slf4j.LoggerFactory)23 EntityDataUnit (io.jmix.ui.component.data.meta.EntityDataUnit)21 Range (io.jmix.core.metamodel.model.Range)20 UiEntityContext (io.jmix.ui.accesscontext.UiEntityContext)20 Entity (io.jmix.core.Entity)19 EntityValues (io.jmix.core.entity.EntityValues)19 MetadataTools (io.jmix.core.MetadataTools)16 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)16 ArrayList (java.util.ArrayList)16 EntityManager (javax.persistence.EntityManager)15