Search in sources :

Example 1 with EnumDisplayName

use of org.motechproject.mds.annotations.EnumDisplayName in project motech by motech.

the class FieldProcessor method createComboboxSettings.

private List<SettingDto> createComboboxSettings(AccessibleObject ac, Class<?> classType) {
    boolean allowMultipleSelections = Collection.class.isAssignableFrom(classType);
    boolean allowUserSupplied = false;
    Map<String, String> values = new HashMap<>();
    final EnumDisplayName annotation = ac.getAnnotation(EnumDisplayName.class);
    String nameDisplayField = "";
    if (annotation != null) {
        nameDisplayField = annotation.enumField();
    }
    if (Collection.class.isAssignableFrom(classType)) {
        Class<?> genericType = MemberUtil.getGenericType(ac);
        if (genericType.isEnum()) {
            Object[] enumConstants = genericType.getEnumConstants();
            populateEnumDisplayValues(enumConstants, values, nameDisplayField, annotation);
        } else {
            allowUserSupplied = true;
        }
    } else {
        Object[] enumConstants = classType.getEnumConstants();
        populateEnumDisplayValues(enumConstants, values, nameDisplayField, annotation);
    }
    List<SettingDto> list = new ArrayList<>();
    list.add(new SettingDto(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS, allowMultipleSelections));
    list.add(new SettingDto(Constants.Settings.ALLOW_USER_SUPPLIED, allowUserSupplied));
    list.add(new SettingDto(Constants.Settings.COMBOBOX_VALUES, values));
    return list;
}
Also used : HashMap(java.util.HashMap) EnumDisplayName(org.motechproject.mds.annotations.EnumDisplayName) ArrayList(java.util.ArrayList) AccessibleObject(java.lang.reflect.AccessibleObject) SettingDto(org.motechproject.mds.dto.SettingDto)

Aggregations

AccessibleObject (java.lang.reflect.AccessibleObject)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 EnumDisplayName (org.motechproject.mds.annotations.EnumDisplayName)1 SettingDto (org.motechproject.mds.dto.SettingDto)1