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;
}
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);
}
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();
}
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();
}
}
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);
}
}
Aggregations