Search in sources :

Example 1 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty 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 MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty 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 3 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty 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 4 with MetaProperty

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

the class RelatedEntitiesBean method openRelatedScreen.

@Override
public <T extends Entity> void openRelatedScreen(Collection<T> selectedEntities, Class<T> clazz, String property, RelatedScreenDescriptor descriptor) {
    checkNotNullArgument(clazz, "Class can't be null");
    if (StringUtils.isEmpty(property)) {
        throw new IllegalArgumentException("Property can't be null");
    }
    MetaClass metaClass = metadata.getClassNN(clazz);
    MetaProperty metaProperty = metaClass.getProperty(property);
    openRelatedScreen(selectedEntities, metaClass, metaProperty, descriptor);
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 5 with MetaProperty

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

the class RelatedEntitiesBean method applyFilter.

protected void applyFilter(Filter component, Collection<? extends Entity> selectedParents, RelatedScreenDescriptor descriptor, MetaDataDescriptor metaDataDescriptor) {
    FilterEntity filterEntity = metadata.create(FilterEntity.class);
    filterEntity.setComponentId(CubaComponentsHelper.getFilterComponentPath(component));
    if (StringUtils.isNotEmpty(descriptor.getFilterCaption())) {
        filterEntity.setName(descriptor.getFilterCaption());
    } else {
        MetaProperty metaProperty = metaDataDescriptor.getMetaProperty();
        filterEntity.setName(messages.getMainMessage("actions.Related.Filter") + " " + messageTools.getPropertyCaption(metaProperty.getDomain(), metaProperty.getName()));
    }
    MetaClass effectiveMetaClass = extendedEntities.getEffectiveMetaClass(metaDataDescriptor.getRelatedMetaClass());
    filterEntity.setXml(getRelatedEntitiesFilterXml(effectiveMetaClass, selectedParents, component, metaDataDescriptor));
    filterEntity.setUsername(userSessionSource.getUserSession().getUser().getUsername());
    component.setFilterEntity(filterEntity);
    component.apply(Filter.FilterOptions.create().setNotifyInvalidConditions(true).setLoadData(false));
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) 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