use of org.motechproject.mds.domain.ComboboxHolder in project motech by motech.
the class LookupProcessor method setUseGenericParam.
private void setUseGenericParam(EntityDto entity, Class<?> methodParameterType, LookupFieldDto lookupField) {
FieldDto field = findEntityFieldByName(entity.getClassName(), lookupField.getName());
TypeDto fieldType = field.getType();
EntityDto relatedEntity = null;
if (fieldType.isRelationship()) {
relatedEntity = findEntityByClassName(field.getMetadata(Constants.MetadataKeys.RELATED_CLASS).getValue());
field = findEntityFieldByName(field.getMetadata(Constants.MetadataKeys.RELATED_CLASS).getValue(), lookupField.getRelatedName());
}
if (fieldType.isCombobox()) {
ComboboxHolder holder = new ComboboxHolder(relatedEntity == null ? entity : relatedEntity, field);
boolean isCollection = holder.isCollection();
boolean isCollectionParam = Collection.class.isAssignableFrom(methodParameterType);
lookupField.setUseGenericParam(isCollection && !isCollectionParam);
}
}
use of org.motechproject.mds.domain.ComboboxHolder in project motech by motech.
the class ActionHandlerServiceImpl method setComboboxInstanceProperty.
private void setComboboxInstanceProperty(Object instance, Field field, Object value) {
ComboboxHolder comboboxHolder = new ComboboxHolder(field);
String underlyingType = comboboxHolder.getUnderlyingType();
if (comboboxHolder.isAllowMultipleSelections()) {
setMultiValueComboboxInstanceProperty(instance, field, value, underlyingType);
} else {
setSingleValueComboboxInstanceProperty(instance, field, value, underlyingType);
}
}
use of org.motechproject.mds.domain.ComboboxHolder in project motech by motech.
the class LookupExecutor method getTypeClass.
private String getTypeClass(FieldDto field) {
String typeClass;
if (field.getType().isCombobox()) {
ComboboxHolder holder = new ComboboxHolder(entityClass, field);
typeClass = holder.getTypeClassName();
} else {
typeClass = (field.getType().isTextArea()) ? "java.lang.String" : field.getType().getTypeClass();
}
return typeClass;
}
use of org.motechproject.mds.domain.ComboboxHolder in project motech by motech.
the class PropertyBuilder method create.
public static Property create(Field field, Object value) {
String name = field.getName();
Type type = field.getType();
if (type.isCombobox()) {
ComboboxHolder holder = new ComboboxHolder(field);
if (holder.isCollection()) {
if (holder.getTypeClassName().equals(List.class.getName())) {
return new CollectionProperty(name, value, new ArrayList(), holder.getUnderlyingType());
} else if (holder.getTypeClassName().equals(Set.class.getName())) {
return new CollectionProperty(name, value, new HashSet(), holder.getUnderlyingType());
}
}
}
return create(name, value, field.getType().getTypeClassName());
}
use of org.motechproject.mds.domain.ComboboxHolder in project motech by motech.
the class InstancesReader method readComboboxProperty.
private void readComboboxProperty(Field field, Object instance) throws IOException {
ComboboxHolder comboboxHolder = new ComboboxHolder(field);
Class<?> underlyingClass = getClassRelativeToObject(instance, comboboxHolder.getUnderlyingType());
if (comboboxHolder.isAllowMultipleSelections()) {
List<?> values = objectReader.readList(underlyingClass);
PropertyUtil.safeSetCollectionProperty(instance, field.getName(), values);
} else {
Object value = objectReader.readObject(underlyingClass);
PropertyUtil.safeSetProperty(instance, field.getName(), value);
}
}
Aggregations