Search in sources :

Example 61 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class AbstractFieldManager method getDefinitionByModelProperty.

@Override
public FieldDefinition getDefinitionByModelProperty(ModelProperty modelProperty) {
    FieldTypeEntry fieldTypeEntry = (FieldTypeEntry) modelProperty.getMetaData().getEntry(FieldTypeEntry.NAME);
    FieldDefinition fieldDefinition = null;
    if (fieldTypeEntry != null) {
        fieldDefinition = getFieldFromProvider(fieldTypeEntry.getValue(), modelProperty.getTypeInfo());
    }
    if (fieldDefinition == null) {
        Optional<FieldDefinition> optional = Optional.ofNullable(getDefinitionByDataType(modelProperty.getTypeInfo()));
        if (optional.isPresent()) {
            fieldDefinition = optional.get();
        }
    }
    if (fieldDefinition != null) {
        fieldDefinition.setName(modelProperty.getName());
        fieldDefinition.setBinding(modelProperty.getName());
        String label = modelProperty.getName();
        label = label.substring(0, 1).toUpperCase() + label.substring(1);
        fieldDefinition.setLabel(label);
        fieldDefinition.setStandaloneClassName(modelProperty.getTypeInfo().getClassName());
        if (fieldDefinition instanceof HasPlaceHolder) {
            ((HasPlaceHolder) fieldDefinition).setPlaceHolder(label);
        }
        for (MetaDataEntry entry : modelProperty.getMetaData().getEntries()) {
            MetaDataEntryProcessor processor = metaDataEntryManager.getProcessorForEntry(entry);
            if (processor != null && processor.supports(fieldDefinition)) {
                processor.process(entry, fieldDefinition);
            }
        }
        return fieldDefinition;
    }
    return null;
}
Also used : HasPlaceHolder(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasPlaceHolder) FieldTypeEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldTypeEntry) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) MetaDataEntryProcessor(org.kie.workbench.common.forms.service.shared.meta.processing.MetaDataEntryProcessor) MetaDataEntry(org.kie.workbench.common.forms.model.MetaDataEntry)

Example 62 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FieldManagerTest method testGetDefinitionByModelPropertyWithMetaData.

@Test
public void testGetDefinitionByModelPropertyWithMetaData() {
    property.getMetaData().addEntry(new FieldTypeEntry(TextAreaFieldType.NAME));
    property.getMetaData().addEntry(new FieldLabelEntry(METADATA_LABEL));
    property.getMetaData().addEntry(new FieldPlaceHolderEntry(METADATA_PLACEHOLDER));
    property.getMetaData().addEntry(new FieldReadOnlyEntry(METADATA_READONLY));
    property.getMetaData().addEntry(new FieldRequiredEntry(METADATA_REQUIRED));
    FieldDefinition fieldDefinition = fieldManager.getDefinitionByModelProperty(property);
    Assertions.assertThat(fieldDefinition).isNotNull().isInstanceOf(TextAreaFieldDefinition.class).hasFieldOrPropertyWithValue("name", PROPERTY_NAME).hasFieldOrPropertyWithValue("label", METADATA_LABEL).hasFieldOrPropertyWithValue("placeHolder", METADATA_PLACEHOLDER).hasFieldOrPropertyWithValue("required", METADATA_REQUIRED).hasFieldOrPropertyWithValue("readOnly", METADATA_READONLY).hasFieldOrPropertyWithValue("binding", PROPERTY_NAME);
}
Also used : FieldTypeEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldTypeEntry) FieldLabelEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldLabelEntry) FieldReadOnlyEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldReadOnlyEntry) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) FieldPlaceHolderEntry(org.kie.workbench.common.forms.fields.shared.model.meta.entries.FieldPlaceHolderEntry) FieldRequiredEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldRequiredEntry) Test(org.junit.Test)

Example 63 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FieldManagerTest method checkFieldExists.

protected void checkFieldExists(TypeInfo typeInfo) {
    FieldDefinition fieldDefinition = fieldManager.getDefinitionByDataType(typeInfo);
    Assertions.assertThat(fieldDefinition).isNotNull();
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition)

Example 64 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FieldManagerTest method testCompatiblefields.

protected void testCompatiblefields(boolean addFieldType) {
    for (Class clazz : basicTypesSupported) {
        TypeInfo typeInfo = new TypeInfoImpl(clazz.isEnum() ? TypeKind.ENUM : TypeKind.BASE, clazz.getName(), false);
        FieldDefinition fieldDefinition = fieldManager.getDefinitionByDataType(typeInfo);
        Assertions.assertThat(fieldDefinition).isNotNull();
        if (addFieldType) {
            fieldDefinition.setStandaloneClassName(typeInfo.getClassName());
        }
        Collection<String> compatibles = fieldManager.getCompatibleFields(fieldDefinition);
        Assertions.assertThat(compatibles).isNotNull().isNotEmpty();
    }
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) TypeInfo(org.kie.workbench.common.forms.model.TypeInfo)

Example 65 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FormModelSynchronizationUtilImpl method resolveConflict.

protected void resolveConflict(TypeConflictImpl typeConflict) {
    /*
        If there are type conflicts (a property that has changed the type) we are going to solve it by trying to
        update the binded field to the right FieldDefinition.
        */
    Optional<FieldDefinition> originalformFieldOptional = Optional.ofNullable(form.getFieldByBinding(typeConflict.getPropertyName()));
    if (originalformFieldOptional.isPresent()) {
        FieldDefinition originalFormField = originalformFieldOptional.get();
        logger.warning("Conflict found on variable '" + typeConflict.getPropertyName() + "', previous type was '" + typeConflict.getBefore().getClassName() + "' and new one is '" + typeConflict.getNow().getClassName() + "'. Trying to fix.");
        // Determining if the current FieldType is suitable for the new property type.
        Optional<FieldDefinition> newFieldOptional = Optional.ofNullable(fieldManager.getFieldFromProvider(originalFormField.getFieldType().getTypeName(), typeConflict.getNow()));
        FieldDefinition newField;
        if (newFieldOptional.isPresent()) {
            // There's a suitable FieldDefinition with the same FieldType than the old field for the new property type.
            newField = newFieldOptional.get();
        } else {
            // It seems that the new property type isn't compatible with the actual FieldDefinition. Getting a compatible FieldDefintion..
            newField = fieldManager.getDefinitionByDataType(typeConflict.getNow());
        }
        newField.setId(originalFormField.getId());
        newField.setName(originalFormField.getName());
        newField.copyFrom(originalFormField);
        newField.setStandaloneClassName(typeConflict.getNow().getClassName());
        form.getFields().remove(originalFormField);
        form.getFields().add(newField);
    }
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition)

Aggregations

FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)85 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)42 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)29 Test (org.junit.Test)27 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)24 TextAreaFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition)22 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)21 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)20 CheckBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition)18 DecimalBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)17 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)14 DatePickerFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition)13 ArrayList (java.util.ArrayList)11 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)9 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)8 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)7 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)7 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)7 LayoutColumn (org.uberfire.ext.layout.editor.api.editor.LayoutColumn)7 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)7