Search in sources :

Example 11 with EnumClass

use of io.jmix.core.metamodel.datatype.impl.EnumClass in project jmix by jmix-framework.

the class EnumsControllerManager method getAllEnumInfos.

public List<EnumInfo> getAllEnumInfos() {
    List<EnumInfo> results = new ArrayList<>();
    metadataTools.getAllEnums().stream().filter(enumClass -> EnumClass.class.isAssignableFrom(enumClass) && enumClass.isEnum()).forEach(enumClass -> {
        List<EnumValueInfo> enumValues = new ArrayList<>();
        Object[] enumConstants = enumClass.getEnumConstants();
        for (Object enumConstant : enumConstants) {
            Enum enumValue = (Enum) enumConstant;
            EnumValueInfo enumValueInfo = new EnumValueInfo(enumValue.name(), ((EnumClass) enumValue).getId(), messages.getMessage(enumValue));
            enumValues.add(enumValueInfo);
        }
        results.add(new EnumInfo(enumClass.getName(), enumValues));
    });
    return results;
}
Also used : EnumClass(io.jmix.core.metamodel.datatype.impl.EnumClass) HttpStatus(org.springframework.http.HttpStatus) Component(org.springframework.stereotype.Component) List(java.util.List) EnumValueInfo(io.jmix.rest.impl.service.filter.data.EnumValueInfo) Autowired(org.springframework.beans.factory.annotation.Autowired) EnumInfo(io.jmix.rest.impl.service.filter.data.EnumInfo) MetadataTools(io.jmix.core.MetadataTools) RestAPIException(io.jmix.rest.exception.RestAPIException) Messages(io.jmix.core.Messages) ArrayList(java.util.ArrayList) EnumValueInfo(io.jmix.rest.impl.service.filter.data.EnumValueInfo) EnumInfo(io.jmix.rest.impl.service.filter.data.EnumInfo) ArrayList(java.util.ArrayList) EnumClass(io.jmix.core.metamodel.datatype.impl.EnumClass)

Aggregations

EnumClass (io.jmix.core.metamodel.datatype.impl.EnumClass)11 Method (java.lang.reflect.Method)3 EnumStore (com.haulmont.cuba.core.config.EnumStore)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)2 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)2 Component (org.springframework.stereotype.Component)2 DatatypeRegistry (com.haulmont.chile.core.datatypes.DatatypeRegistry)1 Datatypes (com.haulmont.chile.core.datatypes.Datatypes)1 CubaProperties (com.haulmont.cuba.CubaProperties)1 com.haulmont.cuba.core.config.defaults (com.haulmont.cuba.core.config.defaults)1 Default (com.haulmont.cuba.core.config.defaults.Default)1 com.haulmont.cuba.core.config.type (com.haulmont.cuba.core.config.type)1 TypeStringify (com.haulmont.cuba.core.config.type.TypeStringify)1