Search in sources :

Example 1 with EnumType

use of org.activityinfo.model.type.enumerated.EnumType 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 EnumType

use of org.activityinfo.model.type.enumerated.EnumType in project activityinfo by bedatadriven.

the class CheckboxTemplate method create.

@Override
public FormField create() {
    List<EnumItem> values = Lists.newArrayList();
    values.add(new EnumItem(EnumItem.generateId(), I18N.MESSAGES.defaultEnumItem(1)));
    values.add(new EnumItem(EnumItem.generateId(), I18N.MESSAGES.defaultEnumItem(2)));
    FormField field = new FormField(ResourceId.generateFieldId(EnumType.TYPE_CLASS));
    field.setLabel(I18N.CONSTANTS.defaultCheckboxFieldLabel());
    field.setType(new EnumType(Cardinality.MULTIPLE, values));
    return field;
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormField(org.activityinfo.model.form.FormField)

Example 3 with EnumType

use of org.activityinfo.model.type.enumerated.EnumType in project activityinfo by bedatadriven.

the class ColumnMappingGuesser method getDistanceMap.

public TreeMap<Integer, ImportTarget> getDistanceMap(String sourceLabel) {
    final TreeMap<Integer, ImportTarget> distanceMap = Maps.newTreeMap();
    for (ImportTarget target : importTargets) {
        String targetLabel = target.getLabel();
        if (target.getFormField().getType() instanceof EnumType) {
            EnumType enumType = (EnumType) target.getFormField().getType();
            if (enumType.getCardinality() == Cardinality.MULTIPLE) {
                int index = targetLabel.indexOf("-");
                if (index != -1) {
                    targetLabel = targetLabel.substring(0, index - 1);
                }
            }
        }
        final int distance = Levenshtein.getLevenshteinDistance(sourceLabel, targetLabel);
        distanceMap.put(distance, target);
    }
    return distanceMap;
}
Also used : ImportTarget(org.activityinfo.ui.client.component.importDialog.model.strategy.ImportTarget) EnumType(org.activityinfo.model.type.enumerated.EnumType)

Example 4 with EnumType

use of org.activityinfo.model.type.enumerated.EnumType in project activityinfo by bedatadriven.

the class RadioButtonTemplate method create.

@Override
public FormField create() {
    List<EnumItem> values = Lists.newArrayList();
    values.add(new EnumItem(EnumItem.generateId(), I18N.MESSAGES.defaultEnumItem(1)));
    values.add(new EnumItem(EnumItem.generateId(), I18N.MESSAGES.defaultEnumItem(2)));
    FormField field = new FormField(ResourceId.generateFieldId(EnumType.TYPE_CLASS));
    field.setLabel(I18N.CONSTANTS.defaultRadioFieldLabel());
    field.setType(new EnumType(Cardinality.SINGLE, values));
    return field;
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormField(org.activityinfo.model.form.FormField)

Example 5 with EnumType

use of org.activityinfo.model.type.enumerated.EnumType in project activityinfo by bedatadriven.

the class EnumImportStrategy method getImportSites.

@Override
public List<ImportTarget> getImportSites(FormTree.Node node) {
    EnumType type = (EnumType) node.getType();
    List<ImportTarget> result = Lists.newArrayList();
    if (type.getCardinality() == Cardinality.SINGLE) {
        result.add(new ImportTarget(node.getField(), VALUE, node.getField().getLabel(), node.getDefiningFormClass().getId()));
    } else {
        for (EnumItem item : type.getValues()) {
            result.add(new ImportTarget(node.getField(), new TargetSiteId(item.getId().asString()), label(item.getLabel(), node.getField().getLabel()), node.getDefiningFormClass().getId()));
        }
    }
    return result;
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

Aggregations

EnumType (org.activityinfo.model.type.enumerated.EnumType)39 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)30 FormField (org.activityinfo.model.form.FormField)14 FormClass (org.activityinfo.model.form.FormClass)11 ResourceId (org.activityinfo.model.resource.ResourceId)7 QuantityType (org.activityinfo.model.type.number.QuantityType)7 Test (org.junit.Test)7 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)5 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)5 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)4 CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)3 JsonValue (org.activityinfo.json.JsonValue)2 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)2 ColumnView (org.activityinfo.model.query.ColumnView)2 Cardinality (org.activityinfo.model.type.Cardinality)2 FieldType (org.activityinfo.model.type.FieldType)2 FieldValue (org.activityinfo.model.type.FieldValue)2 NarrativeType (org.activityinfo.model.type.NarrativeType)2 ReferenceType (org.activityinfo.model.type.ReferenceType)2 TextType (org.activityinfo.model.type.primitive.TextType)2