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;
}
Aggregations