Search in sources :

Example 1 with FieldType

use of org.activityinfo.model.type.FieldType in project activityinfo by bedatadriven.

the class FormFieldWidgetFactory method createWidget.

public Promise<? extends FormFieldWidget> createWidget(FormClass formClass, FormField field, FieldUpdater valueUpdater) {
    FieldType type = field.getType();
    if (type instanceof QuantityType) {
        return Promise.resolved(new QuantityFieldWidget((QuantityType) type, valueUpdater));
    } else if (type instanceof SerialNumberType) {
        return Promise.resolved(new SerialNumberFieldWidget((SerialNumberType) type));
    } else if (type instanceof NarrativeType) {
        return Promise.resolved(new NarrativeFieldWidget(valueUpdater));
    } else if (type instanceof TextType) {
        return Promise.resolved(new TextFieldWidget((TextType) type, valueUpdater));
    } else if (type instanceof CalculatedFieldType) {
        return Promise.resolved(new CalculatedFieldWidget(valueUpdater));
    } else if (type instanceof LocalDateType) {
        return Promise.resolved(new DateFieldWidget(valueUpdater));
    } else if (type instanceof LocalDateIntervalType) {
        return Promise.resolved(new DateIntervalFieldWidget(valueUpdater));
    } else if (type instanceof GeoPointType) {
        return Promise.resolved(new GeographicPointWidget(valueUpdater));
    } else if (type instanceof EnumType) {
        return Promise.resolved(new EnumFieldWidget((EnumType) field.getType(), valueUpdater, fieldWidgetMode));
    } else if (type instanceof BooleanType) {
        return Promise.resolved(new BooleanFieldWidget(valueUpdater));
    } else if (type instanceof AttachmentType) {
        AttachmentType attachmentType = (AttachmentType) type;
        if (attachmentType.getKind() == AttachmentType.Kind.IMAGE) {
            return Promise.resolved(new ImageUploadFieldWidget(formClass.getId(), valueUpdater, fieldWidgetMode));
        } else {
            return Promise.resolved(new AttachmentUploadFieldWidget(formClass.getId(), valueUpdater, fieldWidgetMode));
        }
    } else if (type instanceof ReferenceType) {
        return createReferenceWidget(field, valueUpdater);
    } else if (type instanceof BarcodeType) {
        return Promise.resolved(new BarcodeFieldWidget(valueUpdater));
    }
    Log.error("Unexpected field type " + type.getTypeClass());
    throw new UnsupportedOperationException();
}
Also used : SerialNumberType(org.activityinfo.model.type.SerialNumberType) ReferenceType(org.activityinfo.model.type.ReferenceType) AttachmentUploadFieldWidget(org.activityinfo.ui.client.component.form.field.attachment.AttachmentUploadFieldWidget) ImageUploadFieldWidget(org.activityinfo.ui.client.component.form.field.attachment.ImageUploadFieldWidget) NarrativeType(org.activityinfo.model.type.NarrativeType) EnumType(org.activityinfo.model.type.enumerated.EnumType) CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) AttachmentType(org.activityinfo.model.type.attachment.AttachmentType) BooleanType(org.activityinfo.model.type.primitive.BooleanType) LocalDateIntervalType(org.activityinfo.model.type.time.LocalDateIntervalType) FieldType(org.activityinfo.model.type.FieldType) CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) TextType(org.activityinfo.model.type.primitive.TextType) GeoPointType(org.activityinfo.model.type.geo.GeoPointType) QuantityType(org.activityinfo.model.type.number.QuantityType) LocalDateType(org.activityinfo.model.type.time.LocalDateType) BarcodeType(org.activityinfo.model.type.barcode.BarcodeType)

Example 2 with FieldType

use of org.activityinfo.model.type.FieldType in project activityinfo by bedatadriven.

the class XFormReader method createField.

private FormElement createField(BodyElement element) {
    if (Strings.isNullOrEmpty(element.getLabel())) {
        throw new RuntimeException("Element " + element.getRef() + " has no label");
    }
    InstanceElement instanceElement = instanceElements.get(element.getRef());
    Bind bind = bindings.get(element.getRef());
    FieldType type = createType(element, bind);
    FormField field = new FormField(ResourceId.generateFieldId(type.getTypeClass()));
    field.setCode(buildCode(null, instanceElement).toString());
    field.setLabel(element.getLabel());
    field.setDescription(element.getHint());
    field.setType(type);
    return field;
}
Also used : FieldType(org.activityinfo.model.type.FieldType)

Example 3 with FieldType

use of org.activityinfo.model.type.FieldType in project activityinfo by bedatadriven.

the class XlsFormBuilder method writeSimpleField.

private void writeSimpleField(FormField field) {
    HSSFRow fieldRow = surveySheet.createRow(nextFieldRow++);
    String name = field.getCode();
    if (Strings.isNullOrEmpty(name)) {
        name = field.getId().asString();
    }
    fieldRow.createCell(NAME_COLUMN).setCellValue(name);
    fieldRow.createCell(LABEL_COLUMN).setCellValue(field.getLabel());
    fieldRow.createCell(REQUIRED_COLUMN).setCellValue(field.isRequired() ? "yes" : "no");
    FieldType type = field.getType();
    if (type instanceof QuantityType) {
        QuantityType quantityType = (QuantityType) field.getType();
        fieldRow.createCell(TYPE_COLUMN).setCellValue(XlsFormTypes.DECIMAL);
        fieldRow.createCell(UNITS_COLUMN).setCellValue(quantityType.getUnits());
    } else if (type instanceof TextType) {
        fieldRow.createCell(TYPE_COLUMN).setCellValue(XlsFormTypes.TEXT);
    } else if (type instanceof NarrativeType) {
        fieldRow.createCell(TYPE_COLUMN).setCellValue("text");
    } else if (type instanceof CalculatedFieldType) {
        CalculatedFieldType calculatedType = (CalculatedFieldType) field.getType();
        fieldRow.createCell(TYPE_COLUMN).setCellValue(XlsFormTypes.CALCULATE);
        fieldRow.createCell(CALCULATION_FIELD).setCellValue(calculatedType.getExpression());
    } else if (type instanceof LocalDateType) {
        fieldRow.createCell(TYPE_COLUMN).setCellValue(XlsFormTypes.DATE);
    } else if (type instanceof EnumType) {
        EnumType enumType = (EnumType) type;
        String typeName;
        if (enumType.getCardinality() == Cardinality.SINGLE) {
            typeName = XlsFormTypes.SELECT_ONE;
        } else {
            typeName = XlsFormTypes.SELECT_MULTIPLE;
        }
        String listName = name;
        fieldRow.createCell(TYPE_COLUMN).setCellValue(typeName + " " + listName);
        addChoices(listName, enumType);
    }
    if (field.getRelevanceConditionExpression() != null) {
        String xpathRelevanceCondition = xPathBuilder.build(field.getRelevanceConditionExpression());
        fieldRow.createCell(RELEVANT_COLUMN).setCellValue(xpathRelevanceCondition);
    }
}
Also used : CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) NarrativeType(org.activityinfo.model.type.NarrativeType) QuantityType(org.activityinfo.model.type.number.QuantityType) LocalDateType(org.activityinfo.model.type.time.LocalDateType) EnumType(org.activityinfo.model.type.enumerated.EnumType) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) FieldType(org.activityinfo.model.type.FieldType) TextType(org.activityinfo.model.type.primitive.TextType)

Example 4 with FieldType

use of org.activityinfo.model.type.FieldType in project activityinfo by bedatadriven.

the class StatFunction method computeUnits.

protected final String computeUnits(List<FieldType> argumentTypes) {
    Set<String> units = Sets.newHashSet();
    for (FieldType argumentType : argumentTypes) {
        if (argumentType instanceof QuantityType) {
            QuantityType quantityType = (QuantityType) argumentType;
            units.add(quantityType.getUnits());
        }
    }
    if (units.size() == 1) {
        return units.iterator().next();
    } else {
        return QuantityType.UNKNOWN_UNITS;
    }
}
Also used : QuantityType(org.activityinfo.model.type.number.QuantityType) FieldType(org.activityinfo.model.type.FieldType)

Example 5 with FieldType

use of org.activityinfo.model.type.FieldType in project activityinfo by bedatadriven.

the class IfFunction method resolveResultType.

@Override
public FieldType resolveResultType(List<FieldType> argumentTypes) {
    checkArity(argumentTypes, 3);
    FieldType conditionType = argumentTypes.get(0);
    if (!(conditionType instanceof BooleanType)) {
        throw new ArgumentException(0, "Expected TRUE/FALSE value");
    }
    FieldType trueType = argumentTypes.get(1);
    FieldType falseType = argumentTypes.get(2);
    if (trueType.getTypeClass() != falseType.getTypeClass()) {
        throw new ArgumentException(2, "Must have the same type as the TRUE argument.");
    }
    return trueType;
}
Also used : BooleanType(org.activityinfo.model.type.primitive.BooleanType) ArgumentException(org.activityinfo.model.formula.diagnostic.ArgumentException) FieldType(org.activityinfo.model.type.FieldType)

Aggregations

FieldType (org.activityinfo.model.type.FieldType)6 QuantityType (org.activityinfo.model.type.number.QuantityType)4 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)3 NarrativeType (org.activityinfo.model.type.NarrativeType)2 EnumType (org.activityinfo.model.type.enumerated.EnumType)2 BooleanType (org.activityinfo.model.type.primitive.BooleanType)2 TextType (org.activityinfo.model.type.primitive.TextType)2 LocalDateType (org.activityinfo.model.type.time.LocalDateType)2 ArgumentException (org.activityinfo.model.formula.diagnostic.ArgumentException)1 ReferenceType (org.activityinfo.model.type.ReferenceType)1 SerialNumberType (org.activityinfo.model.type.SerialNumberType)1 AttachmentType (org.activityinfo.model.type.attachment.AttachmentType)1 BarcodeType (org.activityinfo.model.type.barcode.BarcodeType)1 GeoPointType (org.activityinfo.model.type.geo.GeoPointType)1 LocalDateIntervalType (org.activityinfo.model.type.time.LocalDateIntervalType)1 ActivityField (org.activityinfo.store.mysql.metadata.ActivityField)1 AttachmentUploadFieldWidget (org.activityinfo.ui.client.component.form.field.attachment.AttachmentUploadFieldWidget)1 ImageUploadFieldWidget (org.activityinfo.ui.client.component.form.field.attachment.ImageUploadFieldWidget)1 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)1