use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class AbstractComponentGenerationStrategy method createComponentInternal.
protected Component createComponentInternal(ComponentGenerationContext context) {
MetaClass metaClass = context.getMetaClass();
MetaPropertyPath mpp = resolveMetaPropertyPath(metaClass, context.getProperty());
Element xmlDescriptor = context.getXmlDescriptor();
if (mpp != null) {
Range mppRange = mpp.getRange();
if (mppRange.isDatatype()) {
Class type = mppRange.asDatatype().getJavaClass();
MetaProperty metaProperty = mpp.getMetaProperty();
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) {
return createEnumField(context);
}
}
if (xmlDescriptor != null && "true".equalsIgnoreCase(xmlDescriptor.attributeValue("link"))) {
return createDatatypeLinkField(context);
} else {
boolean hasMaskAttribute = xmlDescriptor != null && xmlDescriptor.attribute("mask") != null;
if (type.equals(String.class)) {
if (hasMaskAttribute) {
return createMaskedField(context);
} else {
return createStringField(context, mpp);
}
} else if (type.equals(UUID.class)) {
return createUuidField(context);
} else if (type.equals(Boolean.class)) {
return createBooleanField(context);
} else if (type.equals(java.sql.Date.class) || type.equals(Date.class)) {
return createDateField(context);
} else if (type.equals(Time.class)) {
return createTimeField(context);
} else if (Number.class.isAssignableFrom(type)) {
if (hasMaskAttribute) {
return createMaskedField(context);
} else {
Field currencyField = createCurrencyField(context, mpp);
if (currencyField != null) {
return currencyField;
}
return createNumberField(context);
}
}
}
} else if (mppRange.isClass()) {
MetaProperty metaProperty = mpp.getMetaProperty();
Class<?> javaType = metaProperty.getJavaType();
if (FileDescriptor.class.isAssignableFrom(javaType)) {
return createFileUploadField(context);
}
if (!Collection.class.isAssignableFrom(javaType)) {
return createEntityField(context, mpp);
}
} else if (mppRange.isEnum()) {
return createEnumField(context);
}
}
return null;
}
use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class RuntimePropertiesFrame method loadRequired.
protected void loadRequired(FieldGroup fieldGroup, FieldGroup.FieldConfig field) {
CategoryAttribute attribute = dynamicAttributes.getAttributeForMetaClass(rds.resolveCategorizedEntityClass(), field.getId());
if (attribute != null) {
String requiredMessage = messages.formatMessage(AppConfig.getMessagesPack(), "validation.required.defaultMsg", attribute.getName());
field.setRequired(Boolean.TRUE.equals(attribute.getRequired()) && requiredControlEnabled);
field.setRequiredMessage(requiredMessage);
}
}
use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class EntityDiffManager method getPropertyDiffs.
/**
* Get diffs for entity properties
*
* @param diffView View
* @param firstEntity First entity
* @param secondEntity Second entity
* @param diffBranch Diff branch
* @return Diff list
*/
protected List<EntityPropertyDiff> getPropertyDiffs(View diffView, Entity firstEntity, Entity secondEntity, Stack<Object> diffBranch) {
List<EntityPropertyDiff> propertyDiffs = new LinkedList<>();
MetaClass viewMetaClass = metadata.getSession().getClass(diffView.getEntityClass());
MetaClass metaClass = extendedEntities.getEffectiveMetaClass(viewMetaClass);
Collection<MetaPropertyPath> metaProperties = metadataTools.getViewPropertyPaths(diffView, metaClass);
for (MetaPropertyPath metaPropertyPath : metaProperties) {
MetaProperty metaProperty = metaPropertyPath.getMetaProperty();
if (!metadataTools.isNotPersistent(metaProperty) && !metadataTools.isSystem(metaProperty)) {
ViewProperty viewProperty = diffView.getProperty(metaProperty.getName());
Object firstValue = firstEntity != null ? getPropertyValue(firstEntity, metaPropertyPath) : null;
Object secondValue = secondEntity != null ? getPropertyValue(secondEntity, metaPropertyPath) : null;
EntityPropertyDiff diff = getPropertyDifference(firstValue, secondValue, metaProperty, viewProperty, diffBranch);
if (diff != null)
propertyDiffs.add(diff);
}
}
Collection<CategoryAttribute> categoryAttributes = dynamicAttributesManagerAPI.getAttributesForMetaClass(metaClass);
if (categoryAttributes != null) {
for (CategoryAttribute categoryAttribute : categoryAttributes) {
MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(metaClass, categoryAttribute);
MetaProperty metaProperty = metaPropertyPath.getMetaProperty();
Object firstValue = firstEntity != null ? getPropertyValue(firstEntity, metaPropertyPath) : null;
Object secondValue = secondEntity != null ? getPropertyValue(secondEntity, metaPropertyPath) : null;
EntityPropertyDiff diff = getDynamicAttributeDifference(firstValue, secondValue, metaProperty, categoryAttribute);
if (diff != null)
propertyDiffs.add(diff);
}
}
Comparator<EntityPropertyDiff> comparator = Comparator.comparing(EntityPropertyDiff::getName);
Collections.sort(propertyDiffs, comparator);
return propertyDiffs;
}
use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class DynamicAttributesUtils method getMetaPropertyPath.
/**
* Get special meta property path object for dynamic attribute by code
*/
@Nullable
public static MetaPropertyPath getMetaPropertyPath(MetaClass metaClass, String attributeCode) {
attributeCode = decodeAttributeCode(attributeCode);
CategoryAttribute attribute = AppBeans.get(DynamicAttributes.NAME, DynamicAttributes.class).getAttributeForMetaClass(metaClass, attributeCode);
if (attribute != null) {
return getMetaPropertyPath(metaClass, attribute);
} else {
return null;
}
}
use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class DynamicAttributesUtils method getMetaPropertyPath.
/**
* Get special meta property path object for dynamic attribute id
*/
@Nullable
public static MetaPropertyPath getMetaPropertyPath(MetaClass metaClass, UUID attributeId) {
Collection<CategoryAttribute> attributes = AppBeans.get(DynamicAttributes.NAME, DynamicAttributes.class).getAttributesForMetaClass(metaClass);
CategoryAttribute attribute = null;
for (CategoryAttribute theAttribute : attributes) {
if (theAttribute.getId().equals(attributeId)) {
attribute = theAttribute;
break;
}
}
if (attribute != null) {
return getMetaPropertyPath(metaClass, attribute);
} else {
return null;
}
}
Aggregations