Search in sources :

Example 11 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class DynamicAttributesCache method getAttributesForMetaClass.

public Collection<CategoryAttribute> getAttributesForMetaClass(MetaClass metaClass) {
    MetaClass targetMetaClass = resolveTargetMetaClass(metaClass);
    Collection<Category> categories = categoriesCache.get(targetMetaClass.getName());
    List<CategoryAttribute> categoryAttributes = new ArrayList<>();
    for (Category category : categories) {
        categoryAttributes.addAll(Collections2.filter(category.getCategoryAttrs(), new Predicate<CategoryAttribute>() {

            @Override
            public boolean apply(@Nullable CategoryAttribute input) {
                return input != null && StringUtils.isNotBlank(input.getCode());
            }
        }));
    }
    return categoryAttributes;
}
Also used : Category(com.haulmont.cuba.core.entity.Category) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) Nullable(javax.annotation.Nullable) Predicate(com.google.common.base.Predicate)

Example 12 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class DynamicAttributesUtils method getDynamicAttributeValueAsString.

/**
 * For collection dynamic attributes the method returns a list of formatted collection items joined with the comma,
 * for non-collection dynamic attribute a formatted value is returned
 */
public static String getDynamicAttributeValueAsString(MetaProperty metaProperty, Object value) {
    CategoryAttribute categoryAttribute = getCategoryAttribute(metaProperty);
    MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
    if (categoryAttribute.getIsCollection()) {
        if (value instanceof Collection) {
            List<String> valuesList = ((Collection<Object>) value).stream().map(item -> metadataTools.format(item, metaProperty)).collect(Collectors.toList());
            return Joiner.on(", ").join(valuesList);
        }
    }
    return metadataTools.format(value, metaProperty);
}
Also used : Date(java.util.Date) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Collection(java.util.Collection) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) UUID(java.util.UUID) AppBeans(com.haulmont.cuba.core.global.AppBeans) Collectors(java.util.stream.Collectors) MetaClass(com.haulmont.chile.core.model.MetaClass) List(java.util.List) MetadataTools(com.haulmont.cuba.core.global.MetadataTools) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) Nullable(javax.annotation.Nullable) Joiner(com.google.common.base.Joiner) MetadataTools(com.haulmont.cuba.core.global.MetadataTools) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) Collection(java.util.Collection)

Example 13 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class AbstractComponentGenerationStrategy method createStringField.

protected Component createStringField(ComponentGenerationContext context, MetaPropertyPath mpp) {
    TextInputField textField = null;
    Element xmlDescriptor = context.getXmlDescriptor();
    if (xmlDescriptor != null) {
        final String rows = xmlDescriptor.attributeValue("rows");
        if (!StringUtils.isEmpty(rows)) {
            TextArea textArea = componentsFactory.createComponent(TextArea.class);
            textArea.setRows(Integer.parseInt(rows));
            textField = textArea;
        }
    }
    if (DynamicAttributesUtils.isDynamicAttribute(context.getProperty()) && mpp != null) {
        CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(mpp.getMetaProperty());
        if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.STRING && categoryAttribute.getRowsCount() != null && categoryAttribute.getRowsCount() > 1) {
            TextArea textArea = componentsFactory.createComponent(TextArea.class);
            textArea.setRows(categoryAttribute.getRowsCount());
            textField = textArea;
        }
    }
    if (textField == null) {
        textField = componentsFactory.createComponent(TextField.class);
    }
    setDatasource(textField, context);
    String maxLength = xmlDescriptor != null ? xmlDescriptor.attributeValue("maxLength") : null;
    if (StringUtils.isNotEmpty(maxLength)) {
        ((TextInputField.MaxLengthLimited) textField).setMaxLength(Integer.parseInt(maxLength));
    }
    return textField;
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) Element(org.dom4j.Element)

Example 14 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class DataGridEditorComponentGenerationStrategy method createEntityField.

@Override
protected Field createEntityField(ComponentGenerationContext context, MetaPropertyPath mpp) {
    CollectionDatasource optionsDatasource = null;
    if (DynamicAttributesUtils.isDynamicAttribute(mpp.getMetaProperty())) {
        DynamicAttributesMetaProperty metaProperty = (DynamicAttributesMetaProperty) mpp.getMetaProperty();
        CategoryAttribute attribute = metaProperty.getAttribute();
        if (Boolean.TRUE.equals(attribute.getLookup())) {
            DynamicAttributesGuiTools dynamicAttributesGuiTools = AppBeans.get(DynamicAttributesGuiTools.class);
            optionsDatasource = dynamicAttributesGuiTools.createOptionsDatasourceForLookup(metaProperty.getRange().asClass(), attribute.getJoinClause(), attribute.getWhereClause());
        }
    }
    PickerField pickerField;
    if (optionsDatasource == null) {
        pickerField = componentsFactory.createComponent(PickerField.class);
        setDatasource(pickerField, context);
        pickerField.addLookupAction();
        if (DynamicAttributesUtils.isDynamicAttribute(mpp.getMetaProperty())) {
            DynamicAttributesGuiTools dynamicAttributesGuiTools = AppBeans.get(DynamicAttributesGuiTools.class);
            DynamicAttributesMetaProperty dynamicAttributesMetaProperty = (DynamicAttributesMetaProperty) mpp.getMetaProperty();
            dynamicAttributesGuiTools.initEntityPickerField(pickerField, dynamicAttributesMetaProperty.getAttribute());
        }
        PickerField.LookupAction lookupAction = (PickerField.LookupAction) pickerField.getActionNN(PickerField.LookupAction.NAME);
        // Opening lookup screen in another mode will close editor
        lookupAction.setLookupScreenOpenType(WindowManager.OpenType.DIALOG);
        // In case of adding special logic for lookup screen opened from DataGrid editor
        lookupAction.setLookupScreenParams(ParamsMap.of("dataGridEditor", true));
        boolean actionsByMetaAnnotations = ComponentsHelper.createActionsByMetaAnnotations(pickerField);
        if (!actionsByMetaAnnotations) {
            pickerField.addClearAction();
        }
    } else {
        LookupPickerField lookupPickerField = componentsFactory.createComponent(LookupPickerField.class);
        setDatasource(lookupPickerField, context);
        lookupPickerField.setOptionsDatasource(optionsDatasource);
        pickerField = lookupPickerField;
        ComponentsHelper.createActionsByMetaAnnotations(pickerField);
    }
    return pickerField;
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) DynamicAttributesMetaProperty(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) DynamicAttributesGuiTools(com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools)

Example 15 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class RuntimePropertiesFrame method createFieldsForAttributes.

protected java.util.List<FieldGroup.FieldConfig> createFieldsForAttributes(FieldGroup newRuntimeFieldGroup) {
    @SuppressWarnings("unchecked") Collection<DynamicAttributesMetaProperty> metaProperties = rds.getPropertiesFilteredByCategory();
    java.util.List<FieldGroup.FieldConfig> fields = new ArrayList<>();
    for (DynamicAttributesMetaProperty property : metaProperties) {
        FieldGroup.FieldConfig field = newRuntimeFieldGroup.createField(property.getName());
        field.setProperty(property.getName());
        CategoryAttribute attribute = property.getAttribute();
        if (attribute != null) {
            field.setCaption(attribute.getName());
            if (StringUtils.isNotBlank(attribute.getWidth())) {
                field.setWidth(attribute.getWidth());
            } else {
                field.setWidth(fieldWidth);
            }
        } else {
            field.setCaption(property.getName());
            field.setWidth(fieldWidth);
        }
        fields.add(field);
    }
    return fields;
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) DynamicAttributesMetaProperty(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty) ArrayList(java.util.ArrayList)

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