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);
}
}
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);
}
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);
}
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);
}
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));
}
Aggregations