Search in sources :

Example 6 with ComboboxHolder

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);
    }
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ComboboxHolder(org.motechproject.mds.domain.ComboboxHolder) TypeDto(org.motechproject.mds.dto.TypeDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Example 7 with ComboboxHolder

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);
    }
}
Also used : ComboboxHolder(org.motechproject.mds.domain.ComboboxHolder)

Example 8 with ComboboxHolder

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;
}
Also used : ComboboxHolder(org.motechproject.mds.domain.ComboboxHolder)

Example 9 with ComboboxHolder

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());
}
Also used : Type(org.motechproject.mds.domain.Type) ComboboxHolder(org.motechproject.mds.domain.ComboboxHolder) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 10 with ComboboxHolder

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);
    }
}
Also used : ComboboxHolder(org.motechproject.mds.domain.ComboboxHolder)

Aggregations

ComboboxHolder (org.motechproject.mds.domain.ComboboxHolder)16 TypeDto (org.motechproject.mds.dto.TypeDto)6 FieldDto (org.motechproject.mds.dto.FieldDto)5 ArrayList (java.util.ArrayList)3 EntityDto (org.motechproject.mds.dto.EntityDto)3 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)3 CtClass (javassist.CtClass)2 ClassData (org.motechproject.mds.domain.ClassData)2 RelationshipHolder (org.motechproject.mds.domain.RelationshipHolder)2 Type (org.motechproject.mds.domain.Type)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 CannotCompileException (javassist.CannotCompileException)1 CtField (javassist.CtField)1 FieldMetadata (javax.jdo.metadata.FieldMetadata)1 ForeignKeyMetadata (javax.jdo.metadata.ForeignKeyMetadata)1