Search in sources :

Example 1 with FieldTypeEntry

use of org.kie.workbench.common.forms.model.impl.meta.entries.FieldTypeEntry in project kie-wb-common by kiegroup.

the class BPMNFormModelGeneratorImpl method createModelProperty.

protected ModelProperty createModelProperty(Variable variable, ClassLoader classLoader) {
    ModelProperty property = ModelPropertiesGenerator.createModelProperty(variable.getName(), variable.getType(), FormModelPropertiesUtil.isListType(variable.getType()), classLoader);
    property.getMetaData().addEntry(new FieldReadOnlyEntry(variable.isInput() && !variable.isOutput()));
    if (!property.getTypeInfo().isMultiple() && property.getTypeInfo().getClassName().equals(Object.class.getName())) {
        property.getMetaData().addEntry(new FieldTypeEntry(TextAreaFieldDefinition.FIELD_TYPE.getTypeName()));
    }
    return property;
}
Also used : FieldTypeEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldTypeEntry) FieldReadOnlyEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldReadOnlyEntry) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty)

Example 2 with FieldTypeEntry

use of org.kie.workbench.common.forms.model.impl.meta.entries.FieldTypeEntry 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 3 with FieldTypeEntry

use of org.kie.workbench.common.forms.model.impl.meta.entries.FieldTypeEntry 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)

Aggregations

FieldTypeEntry (org.kie.workbench.common.forms.model.impl.meta.entries.FieldTypeEntry)3 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)2 FieldReadOnlyEntry (org.kie.workbench.common.forms.model.impl.meta.entries.FieldReadOnlyEntry)2 Test (org.junit.Test)1 HasPlaceHolder (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasPlaceHolder)1 TextAreaFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition)1 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)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 FieldPlaceHolderEntry (org.kie.workbench.common.forms.fields.shared.model.meta.entries.FieldPlaceHolderEntry)1 MetaDataEntry (org.kie.workbench.common.forms.model.MetaDataEntry)1 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)1 FieldLabelEntry (org.kie.workbench.common.forms.model.impl.meta.entries.FieldLabelEntry)1 FieldRequiredEntry (org.kie.workbench.common.forms.model.impl.meta.entries.FieldRequiredEntry)1 MetaDataEntryProcessor (org.kie.workbench.common.forms.service.shared.meta.processing.MetaDataEntryProcessor)1