Search in sources :

Example 1 with BasicTypeFieldProvider

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider in project kie-wb-common by kiegroup.

the class AbstractFieldManager method getCompatibleFields.

@Override
public Collection<String> getCompatibleFields(FieldDefinition fieldDefinition) {
    if (fieldDefinition.getStandaloneClassName() != null) {
        if (fieldDefinition instanceof EntityRelationField) {
            if (fieldDefinition.getFieldTypeInfo().isMultiple()) {
                return new TreeSet<>(multipleEntityTypeFieldProvider.keySet());
            }
            return new TreeSet<>(entityTypeFieldProvider.keySet());
        }
        Set result = new TreeSet();
        if (fieldDefinition.getFieldTypeInfo().isMultiple()) {
            for (BasicTypeFieldProvider provider : basicMultipleProviders) {
                if (provider.isCompatible(fieldDefinition)) {
                    result.add(provider.getFieldTypeName());
                }
            }
        } else {
            for (BasicTypeFieldProvider provider : basicProviders) {
                if (provider.isCompatible(fieldDefinition)) {
                    result.add(provider.getFieldTypeName());
                }
            }
        }
        return result;
    } else {
        if (fieldDefinition instanceof EntityRelationField) {
            if (fieldDefinition.getFieldTypeInfo().isMultiple()) {
                return new TreeSet<>(multipleEntityTypeFieldProvider.keySet());
            }
            return new TreeSet<>(entityTypeFieldProvider.keySet());
        }
        BasicTypeFieldProvider provider = (BasicTypeFieldProvider) providersByFieldCode.get(fieldDefinition.getFieldType().getTypeName());
        Set result = new TreeSet();
        for (String className : provider.getSupportedTypes()) {
            result.addAll(getCompatibleTypes(className));
        }
        return result;
    }
}
Also used : EntityRelationField(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EntityRelationField) TreeSet(java.util.TreeSet) Set(java.util.Set) TreeSet(java.util.TreeSet) BasicTypeFieldProvider(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider)

Example 2 with BasicTypeFieldProvider

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider in project kie-wb-common by kiegroup.

the class FieldManagerTest method testGettingAllProvidersDefinitions.

@Test
public void testGettingAllProvidersDefinitions() {
    for (BasicTypeFieldProvider provider : fieldManager.getAllBasicTypeProviders()) {
        for (String className : provider.getSupportedTypes()) {
            try {
                Class clazz = Class.forName(className);
                TypeInfo typeInfo = new TypeInfoImpl(clazz.isEnum() ? TypeKind.ENUM : TypeKind.BASE, clazz.getName(), false);
                FieldDefinition fieldDefinition = fieldManager.getFieldFromProvider(provider.getFieldTypeName(), typeInfo);
                Assertions.assertThat(fieldDefinition).isNotNull();
            } catch (ClassNotFoundException e) {
            // swallow error caused by looking up simple types
            }
        }
    }
}
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) BasicTypeFieldProvider(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider) Test(org.junit.Test)

Example 3 with BasicTypeFieldProvider

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider in project kie-wb-common by kiegroup.

the class FieldManagerTest method testGettingAllMultipleProvidersDefinitions.

@Test
public void testGettingAllMultipleProvidersDefinitions() {
    for (BasicTypeFieldProvider provider : fieldManager.getAllBasicMultipleTypeProviders()) {
        for (String className : provider.getSupportedTypes()) {
            TypeInfo typeInfo = new TypeInfoImpl(Object.class.getName().equals(className) ? TypeKind.OBJECT : TypeKind.BASE, className, true);
            FieldDefinition fieldDefinition = fieldManager.getFieldFromProvider(provider.getFieldTypeName(), 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) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) TypeInfo(org.kie.workbench.common.forms.model.TypeInfo) BasicTypeFieldProvider(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider) Test(org.junit.Test)

Example 4 with BasicTypeFieldProvider

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider in project kie-wb-common by kiegroup.

the class FormDefinitionSerializerImplTest method initTest.

@Before
public void initTest() {
    fieldManager = new TestFieldManager();
    definitionSerializer = new FormDefinitionSerializerImpl(new FieldSerializer(), new FormModelSerializer(), new TestMetaDataEntryManager());
    JavaFormModel model = new PortableJavaModel("org.test.MyParentModel");
    formDefinition = new FormDefinition(model);
    formDefinition.setId("testForm");
    formDefinition.setName("testForm");
    formDefinition.setLayoutTemplate(new LayoutTemplate());
    for (BasicTypeFieldProvider provider : fieldManager.getAllBasicTypeProviders()) {
        for (String type : provider.getSupportedTypes()) {
            FieldDefinition field = provider.getFieldByType(new TypeInfoImpl(type));
            assertNotNull(field);
            String fieldDescription = provider.getFieldTypeName() + "_" + type;
            field.setName(fieldDescription);
            field.setLabel(fieldDescription);
            field.setStandaloneClassName(type);
            field.setBinding(fieldDescription);
            model.getProperties().add(new ModelPropertyImpl(fieldDescription, new TypeInfoImpl(type)));
            formDefinition.getFields().add(field);
        }
    }
    SubFormFieldDefinition subForm = new SubFormFieldDefinition();
    subForm.setLabel("SubForm");
    subForm.setNestedForm("");
    subForm.setBinding("model");
    subForm.setStandaloneClassName("org.test.MyTestModel");
    subForm.setBinding("SubForm");
    formDefinition.getFields().add(subForm);
    model.getProperties().add(new ModelPropertyImpl(subForm.getBinding(), new TypeInfoImpl(TypeKind.OBJECT, subForm.getStandaloneClassName(), false)));
    MultipleSubFormFieldDefinition multipleSubForm = new MultipleSubFormFieldDefinition();
    multipleSubForm.setLabel("MultipleSubForm");
    multipleSubForm.setCreationForm("");
    multipleSubForm.setEditionForm("");
    multipleSubForm.setStandaloneClassName("org.test.MyTestModel");
    multipleSubForm.setBinding("MultipleSubForm");
    formDefinition.getFields().add(multipleSubForm);
    model.getProperties().add(new ModelPropertyImpl(multipleSubForm.getBinding(), new TypeInfoImpl(TypeKind.OBJECT, multipleSubForm.getStandaloneClassName(), true)));
    EnumListBoxFieldDefinition enumListBox = new EnumListBoxFieldDefinition();
    enumListBox.setLabel("EnumListBox");
    enumListBox.setBinding("EnumListBox");
    enumListBox.setStandaloneClassName("org.test.MyTestModel");
    formDefinition.getFields().add(enumListBox);
    model.getProperties().add(new ModelPropertyImpl(enumListBox.getBinding(), new TypeInfoImpl(TypeKind.ENUM, enumListBox.getStandaloneClassName(), false)));
}
Also used : LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) EnumListBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.listBox.definition.EnumListBoxFieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl) TestMetaDataEntryManager(org.kie.workbench.common.forms.fields.test.TestMetaDataEntryManager) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) EnumListBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.listBox.definition.EnumListBoxFieldDefinition) 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) PortableJavaModel(org.kie.workbench.common.forms.model.impl.PortableJavaModel) TestFieldManager(org.kie.workbench.common.forms.fields.test.TestFieldManager) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) TypeInfoImpl(org.kie.workbench.common.forms.model.impl.TypeInfoImpl) JavaFormModel(org.kie.workbench.common.forms.model.JavaFormModel) BasicTypeFieldProvider(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider) Before(org.junit.Before)

Example 5 with BasicTypeFieldProvider

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider in project kie-wb-common by kiegroup.

the class AbstractFieldManager method registerFieldProvider.

protected void registerFieldProvider(FieldProvider provider) {
    boolean isMultiple = provider instanceof MultipleValueFieldProvider;
    if (provider instanceof BasicTypeFieldProvider) {
        BasicTypeFieldProvider basicTypeProvider = (BasicTypeFieldProvider) provider;
        if (isMultiple) {
            basicMultipleProviders.add(basicTypeProvider);
        } else {
            basicProviders.add(basicTypeProvider);
        }
    } else {
        if (isMultiple) {
            multipleEntityTypeFieldProvider.put(provider.getFieldTypeName(), provider);
        } else {
            entityTypeFieldProvider.put(provider.getFieldTypeName(), provider);
        }
    }
    providersByFieldCode.put(provider.getFieldTypeName(), provider);
    providerByFieldType.put(provider.getFieldType(), provider);
}
Also used : BasicTypeFieldProvider(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider)

Aggregations

BasicTypeFieldProvider (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.BasicTypeFieldProvider)7 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)3 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)3 Test (org.junit.Test)2 TextAreaFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition)2 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)2 TypeInfo (org.kie.workbench.common.forms.model.TypeInfo)2 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Before (org.junit.Before)1 EnumListBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.listBox.definition.EnumListBoxFieldDefinition)1 EntityRelationField (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EntityRelationField)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 TestFieldManager (org.kie.workbench.common.forms.fields.test.TestFieldManager)1 TestMetaDataEntryManager (org.kie.workbench.common.forms.fields.test.TestMetaDataEntryManager)1 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)1 JavaFormModel (org.kie.workbench.common.forms.model.JavaFormModel)1 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)1