Search in sources :

Example 26 with CategoryAttribute

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;
}
Also used : Element(org.dom4j.Element) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) Range(com.haulmont.chile.core.model.Range) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaClass(com.haulmont.chile.core.model.MetaClass) DynamicAttributesMetaProperty(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty) MetaProperty(com.haulmont.chile.core.model.MetaProperty) UUID(java.util.UUID)

Example 27 with CategoryAttribute

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);
    }
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute)

Example 28 with CategoryAttribute

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;
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 29 with CategoryAttribute

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;
    }
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) Nullable(javax.annotation.Nullable)

Example 30 with CategoryAttribute

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;
    }
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) Nullable(javax.annotation.Nullable)

Aggregations

CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)34 MetaClass (com.haulmont.chile.core.model.MetaClass)15 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)12 MetaProperty (com.haulmont.chile.core.model.MetaProperty)10 Nullable (javax.annotation.Nullable)6 Element (org.dom4j.Element)5 DynamicAttributesMetaProperty (com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty)4 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)4 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)4 DynamicAttributesGuiTools (com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools)4 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)3 Joiner (com.google.common.base.Joiner)2 Strings (com.google.common.base.Strings)2 Dom4j (com.haulmont.bali.util.Dom4j)2 Enumeration (com.haulmont.chile.core.datatypes.Enumeration)2 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)2 Category (com.haulmont.cuba.core.entity.Category)2 Entity (com.haulmont.cuba.core.entity.Entity)2 AppBeans (com.haulmont.cuba.core.global.AppBeans)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2