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