Search in sources :

Example 1 with MessageTools

use of io.jmix.core.MessageTools in project jmix by jmix-framework.

the class DynamicAttributesCondition method getLocCaption.

@Override
public String getLocCaption() {
    if (isBlank(caption) && !isBlank(propertyPath)) {
        MessageTools messageTools = AppBeans.get(MessageTools.class);
        String propertyCaption = messageTools.getPropertyCaption(metaClass, propertyPath);
        if (!isBlank(propertyCaption)) {
            return propertyCaption + "." + locCaption;
        }
    } else if (isNotBlank(caption)) {
        MessageTools messageTools = AppBeans.get(MessageTools.class);
        return messageTools.loadString(messagesPack, caption);
    }
    DynAttrMetadata dynamicModelMetadata = AppBeans.get(DynAttrMetadata.class);
    AttributeDefinition attribute = dynamicModelMetadata.getAttributes(metaClass).stream().filter(attr -> Objects.equals(EntityValues.getId(attr.getSource()), getCategoryAttributeId())).findFirst().orElse(null);
    if (attribute != null) {
        MsgBundleTools msgBundleTools = AppBeans.get(MsgBundleTools.class);
        return msgBundleTools.getLocalizedValue(attribute.getNameMsgBundle(), attribute.getName());
    }
    return super.getLocCaption();
}
Also used : MessageTools(io.jmix.core.MessageTools) DynAttrMetadata(io.jmix.dynattr.DynAttrMetadata) MsgBundleTools(io.jmix.dynattr.MsgBundleTools) AttributeDefinition(io.jmix.dynattr.AttributeDefinition)

Example 2 with MessageTools

use of io.jmix.core.MessageTools in project jmix by jmix-framework.

the class FilterConditionUtils method getPropertyLocCaption.

public static String getPropertyLocCaption(MetaClass metaClass, String propertyPath) {
    MessageTools messageTools = AppBeans.get(MessageTools.class);
    MetaPropertyPath mpp = metaClass.getPropertyPath(propertyPath);
    if (mpp == null) {
        return propertyPath;
    } else {
        MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
        MetaProperty[] metaProperties = mpp.getMetaProperties();
        StringBuilder sb = new StringBuilder();
        MetaPropertyPath parentMpp = null;
        MetaClass tempMetaClass;
        for (int i = 0; i < metaProperties.length; i++) {
            if (i == 0) {
                parentMpp = new MetaPropertyPath(metaClass, metaProperties[i]);
                tempMetaClass = metaClass;
            } else {
                parentMpp = new MetaPropertyPath(parentMpp, metaProperties[i]);
                tempMetaClass = metadataTools.getPropertyEnclosingMetaClass(parentMpp);
            }
            sb.append(messageTools.getPropertyCaption(tempMetaClass, metaProperties[i].getName()));
            if (i < metaProperties.length - 1) {
                sb.append(".");
            }
        }
        return sb.toString();
    }
}
Also used : MessageTools(io.jmix.core.MessageTools) MetadataTools(io.jmix.core.MetadataTools) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 3 with MessageTools

use of io.jmix.core.MessageTools in project jmix by jmix-framework.

the class PropertyConditionDescriptor method getTreeCaption.

@Override
public String getTreeCaption() {
    if (!Strings.isNullOrEmpty(this.caption)) {
        return locCaption;
    } else {
        MessageTools messageTools = AppBeans.get(MessageTools.class);
        MetaPropertyPath mpp = datasourceMetaClass.getPropertyPath(name);
        return mpp != null ? messageTools.getPropertyCaption(datasourceMetaClass, name) : name;
    }
}
Also used : MessageTools(io.jmix.core.MessageTools) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath)

Example 4 with MessageTools

use of io.jmix.core.MessageTools in project jmix by jmix-framework.

the class CustomConditionFrame method fillEntitySelect.

protected void fillEntitySelect(Param param) {
    if (!entitySelect.isEnabled()) {
        entitySelect.setValue(null);
        return;
    }
    MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
    MessageTools messageTools = AppBeans.get(MessageTools.class);
    Map<String, Object> items = new TreeMap<>();
    Object selectedItem = null;
    if (ParamType.ENTITY.equals(typeSelect.getValue())) {
        for (MetaClass metaClass : metadataTools.getAllJpaEntityMetaClasses()) {
            if (!metadataTools.isSystemLevel(metaClass)) {
                items.put(messageTools.getEntityCaption(metaClass) + " (" + metaClass.getName() + ")", metaClass);
            }
        }
        if (param != null && Param.Type.ENTITY.equals(param.getType())) {
            Class javaClass = param.getJavaClass();
            Metadata metadata = AppBeans.get(Metadata.class);
            selectedItem = metadata.getClass(javaClass);
        }
        entitySelect.setOptionsMap(items);
        entitySelect.setValue(selectedItem);
    } else if (ParamType.ENUM.equals(typeSelect.getValue())) {
        if (param != null && Param.Type.ENUM.equals(param.getType())) {
            selectedItem = param.getJavaClass();
        }
        boolean selectedItemFound = false;
        for (Class enumClass : metadataTools.getAllEnums()) {
            items.put(getEnumClassName(enumClass), enumClass);
            if (selectedItem == null || selectedItem.equals(enumClass))
                selectedItemFound = true;
        }
        // the meta model, hence not in MetadataHelper.getAllEnums(). So we just add it here.
        if (selectedItem != null && !selectedItemFound) {
            items.put(getEnumClassName((Class) selectedItem), selectedItem);
        }
        entitySelect.setOptionsMap(items);
        entitySelect.setValue(selectedItem);
    }
}
Also used : MetadataTools(io.jmix.core.MetadataTools) MessageTools(io.jmix.core.MessageTools) MetaClass(io.jmix.core.metamodel.model.MetaClass) Metadata(com.haulmont.cuba.core.global.Metadata) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Aggregations

MessageTools (io.jmix.core.MessageTools)4 MetadataTools (io.jmix.core.MetadataTools)2 MetaClass (io.jmix.core.metamodel.model.MetaClass)2 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)2 Metadata (com.haulmont.cuba.core.global.Metadata)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1 AttributeDefinition (io.jmix.dynattr.AttributeDefinition)1 DynAttrMetadata (io.jmix.dynattr.DynAttrMetadata)1 MsgBundleTools (io.jmix.dynattr.MsgBundleTools)1