Search in sources :

Example 1 with EnumerationImpl

use of com.haulmont.chile.core.datatypes.impl.EnumerationImpl in project cuba by cuba-platform.

the class EnumerationImplTest method testParseIntegerId.

@Test
public void testParseIntegerId() throws ParseException {
    EnumerationImpl enumeration = new EnumerationImpl(PermissionType.class);
    Enum enumValue = enumeration.parse("10");
    Assert.assertEquals(PermissionType.SCREEN, enumValue);
}
Also used : EnumerationImpl(com.haulmont.chile.core.datatypes.impl.EnumerationImpl) Test(org.junit.Test)

Example 2 with EnumerationImpl

use of com.haulmont.chile.core.datatypes.impl.EnumerationImpl in project cuba by cuba-platform.

the class EnumerationImplTest method testParseStringId.

@Test
public void testParseStringId() throws ParseException {
    EnumerationImpl enumeration = new EnumerationImpl(FtsChangeType.class);
    Enum enumValue = enumeration.parse("I");
    Assert.assertEquals(FtsChangeType.INSERT, enumValue);
}
Also used : EnumerationImpl(com.haulmont.chile.core.datatypes.impl.EnumerationImpl) Test(org.junit.Test)

Example 3 with EnumerationImpl

use of com.haulmont.chile.core.datatypes.impl.EnumerationImpl in project cuba by cuba-platform.

the class MetaModelLoader method loadRange.

protected MetadataObjectInfo<Range> loadRange(MetaProperty metaProperty, Class<?> type, Map<String, Object> map) {
    Datatype datatype = (Datatype) map.get("datatype");
    if (datatype != null) {
        // A datatype is assigned explicitly
        return new MetadataObjectInfo<>(new DatatypeRange(datatype));
    }
    datatype = getAdaptiveDatatype(metaProperty, type);
    if (datatype == null) {
        datatype = datatypes.get(type);
    }
    if (datatype != null) {
        MetaClass metaClass = metaProperty.getDomain();
        Class javaClass = metaClass.getJavaClass();
        try {
            String name = "get" + StringUtils.capitalize(metaProperty.getName());
            Method method = javaClass.getMethod(name);
            Class<Enum> returnType = (Class<Enum>) method.getReturnType();
            if (returnType.isEnum()) {
                return new MetadataObjectInfo<>(new EnumerationRange(new EnumerationImpl<>(returnType)));
            }
        } catch (NoSuchMethodException e) {
        // ignore
        }
        return new MetadataObjectInfo<>(new DatatypeRange(datatype));
    } else if (type.isEnum()) {
        return new MetadataObjectInfo<>(new EnumerationRange(new EnumerationImpl(type)));
    } else {
        return new MetadataObjectInfo<>(null, Collections.singletonList(new RangeInitTask(metaProperty, type, map)));
    }
}
Also used : EnumerationImpl(com.haulmont.chile.core.datatypes.impl.EnumerationImpl) AdaptiveNumberDatatype(com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype) Datatype(com.haulmont.chile.core.datatypes.Datatype)

Example 4 with EnumerationImpl

use of com.haulmont.chile.core.datatypes.impl.EnumerationImpl in project cuba by cuba-platform.

the class EnumerationImplTest method testParseNonExistingId.

@Test
public void testParseNonExistingId() throws ParseException {
    EnumerationImpl enumeration = new EnumerationImpl(FtsChangeType.class);
    Enum enumValue = enumeration.parse("ZZZ");
    Assert.assertNull(enumValue);
}
Also used : EnumerationImpl(com.haulmont.chile.core.datatypes.impl.EnumerationImpl) Test(org.junit.Test)

Aggregations

EnumerationImpl (com.haulmont.chile.core.datatypes.impl.EnumerationImpl)4 Test (org.junit.Test)3 Datatype (com.haulmont.chile.core.datatypes.Datatype)1 AdaptiveNumberDatatype (com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype)1