Search in sources :

Example 1 with PropertyType

use of org.jboss.errai.databinding.client.PropertyType in project kie-wb-common by kiegroup.

the class MapModelBindingHelper method initContext.

public void initContext(MapModelRenderingContext context) {
    FormDefinition form = context.getRootForm();
    Map<String, PropertyType> modelProperties = generateModelDefinition(form, context);
    Map<String, Object> content = DataBinder.forMap(modelProperties).getModel();
    Map<String, Object> contextModel = context.getModel() != null ? context.getModel() : new HashMap<>();
    prepareMapContent(content, form, contextModel, context);
    context.setModel(content);
}
Also used : MapPropertyType(org.jboss.errai.databinding.client.MapPropertyType) PropertyType(org.jboss.errai.databinding.client.PropertyType) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 2 with PropertyType

use of org.jboss.errai.databinding.client.PropertyType in project kie-wb-common by kiegroup.

the class MapModelBindingHelper method generateModelDefinition.

protected Map<String, PropertyType> generateModelDefinition(FormDefinition form, MapModelRenderingContext context, Map<String, Map<String, PropertyType>> availableModels) {
    if (availableModels.containsKey(form.getId())) {
        return availableModels.get(form.getId());
    }
    Map<String, PropertyType> formTypes = new HashMap<>();
    availableModels.put(form.getId(), formTypes);
    form.getFields().forEach(field -> {
        PropertyType propertyType = null;
        if (basicProperties.containsKey(field.getStandaloneClassName())) {
            propertyType = new PropertyType(basicProperties.get(field.getStandaloneClassName()));
        } else if (propertiesGenerator.containsKey(field.getClass())) {
            PropertyGenerator generator = propertiesGenerator.get(field.getClass());
            propertyType = generator.generatePropertyType(field);
        } else if (field instanceof SubFormFieldDefinition) {
            propertyType = getModeldefinitionFor((SubFormFieldDefinition) field, context, availableModels);
        } else if (field instanceof MultipleSubFormFieldDefinition) {
            propertyType = new PropertyType(List.class);
        }
        if (propertyType != null) {
            formTypes.put(field.getBinding(), propertyType);
        }
    });
    return formTypes;
}
Also used : MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) HashMap(java.util.HashMap) MapPropertyType(org.jboss.errai.databinding.client.MapPropertyType) PropertyType(org.jboss.errai.databinding.client.PropertyType) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)

Example 3 with PropertyType

use of org.jboss.errai.databinding.client.PropertyType in project kie-wb-common by kiegroup.

the class MapModelBindingHelperTest method checkBindableProxy.

protected void checkBindableProxy(MapBindableProxy model) {
    assertFalse(model.getBeanProperties().isEmpty());
    checkSimpleTypeProperty(model.getBeanProperties().get(EMPLOYEE_NAME), String.class);
    checkSimpleTypeProperty(model.getBeanProperties().get(EMPLOYEE_SURNAME), String.class);
    checkSimpleTypeProperty(model.getBeanProperties().get(EMPLOYEE_AGE_BINDING), Integer.class);
    checkSimpleTypeProperty(model.getBeanProperties().get(EMPLOYEE_BIRTHDAY), Date.class);
    checkSimpleTypeProperty(model.getBeanProperties().get(EMPLOYEE_MARRIED), Boolean.class);
    PropertyType addressPropertyType = model.getBeanProperties().get(EMPLOYEE_ADDRESS);
    assertNotNull(addressPropertyType);
    assertTrue(addressPropertyType instanceof MapPropertyType);
    MapPropertyType address = (MapPropertyType) addressPropertyType;
    checkSimpleTypeProperty(address.getPropertyTypes().get(ADDRESS_STREET), String.class);
    checkSimpleTypeProperty(address.getPropertyTypes().get(ADDRESS_NUM), Integer.class);
}
Also used : MapPropertyType(org.jboss.errai.databinding.client.MapPropertyType) MapPropertyType(org.jboss.errai.databinding.client.MapPropertyType) PropertyType(org.jboss.errai.databinding.client.PropertyType)

Example 4 with PropertyType

use of org.jboss.errai.databinding.client.PropertyType in project kie-wb-common by kiegroup.

the class MapModelBindingHelper method getModeldefinitionFor.

public MapPropertyType getModeldefinitionFor(MultipleSubFormFieldDefinition subFormField, MapModelRenderingContext context, Map<String, Map<String, PropertyType>> availableModels) {
    FormDefinition creationForms = context.getAvailableForms().get(subFormField.getCreationForm());
    Map<String, PropertyType> modelDefinition = generateModelDefinition(creationForms, context, availableModels);
    FormDefinition editionForm = context.getAvailableForms().get(subFormField.getCreationForm());
    modelDefinition.putAll(generateModelDefinition(editionForm, context, availableModels));
    modelDefinition.put(MapModelRenderingContext.FORM_ENGINE_OBJECT_IDX, new PropertyType(Integer.class));
    modelDefinition.put(MapModelRenderingContext.FORM_ENGINE_EDITED_OBJECT, new PropertyType(Boolean.class));
    return new MapPropertyType(modelDefinition);
}
Also used : BigInteger(java.math.BigInteger) MapPropertyType(org.jboss.errai.databinding.client.MapPropertyType) MapPropertyType(org.jboss.errai.databinding.client.MapPropertyType) PropertyType(org.jboss.errai.databinding.client.PropertyType) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Aggregations

MapPropertyType (org.jboss.errai.databinding.client.MapPropertyType)4 PropertyType (org.jboss.errai.databinding.client.PropertyType)4 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)2 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)1 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)1