use of org.kie.workbench.common.forms.model.impl.ModelPropertyImpl in project kie-wb-common by kiegroup.
the class JBPMFormModelCreationPresenterTest method initFormModels.
protected void initFormModels() {
List<ModelProperty> processVariables = new ArrayList<>();
processVariables.add(new ModelPropertyImpl("name", new TypeInfoImpl(String.class.getName())));
processVariables.add(new ModelPropertyImpl("age", new TypeInfoImpl(Integer.class.getName())));
processVariables.add(new ModelPropertyImpl("twitter", new TypeInfoImpl(String.class.getName())));
processVariables.add(new ModelPropertyImpl("offering", new TypeInfoImpl(Integer.class.getName())));
processVariables.add(new ModelPropertyImpl("skills", new TypeInfoImpl(String.class.getName())));
processVariables.add(new ModelPropertyImpl("mail", new TypeInfoImpl(String.class.getName())));
processVariables.add(new ModelPropertyImpl("hr_score", new TypeInfoImpl(Integer.class.getName())));
processVariables.add(new ModelPropertyImpl("tech_score", new TypeInfoImpl(Integer.class.getName())));
processVariables.add(new ModelPropertyImpl("signed", new TypeInfoImpl(Boolean.class.getName())));
BusinessProcessFormModel processFormModel = new BusinessProcessFormModel("hiring", "hiring", processVariables);
TaskFormModel taskFormModel;
List<TaskFormModel> processTasks = new ArrayList<>();
List<ModelProperty> taskVariables = new ArrayList<>();
taskVariables.add(new ModelPropertyImpl("name", new TypeInfoImpl(String.class.getName())));
taskVariables.add(new ModelPropertyImpl("age", new TypeInfoImpl(Integer.class.getName())));
taskVariables.add(new ModelPropertyImpl("mail", new TypeInfoImpl(String.class.getName())));
taskVariables.add(new ModelPropertyImpl("hr_score", new TypeInfoImpl(String.class.getName())));
taskFormModel = new TaskFormModel("hiring", "HRInterview", taskVariables);
processTasks.add(taskFormModel);
taskVariables = new ArrayList<>();
taskVariables.add(new ModelPropertyImpl("name", new TypeInfoImpl(String.class.getName())));
taskVariables.add(new ModelPropertyImpl("age", new TypeInfoImpl(Integer.class.getName())));
taskVariables.add(new ModelPropertyImpl("mail", new TypeInfoImpl(String.class.getName())));
taskVariables.add(new ModelPropertyImpl("skills", new TypeInfoImpl(String.class.getName())));
taskVariables.add(new ModelPropertyImpl("tech_score", new TypeInfoImpl(Integer.class.getName())));
taskVariables.add(new ModelPropertyImpl("twitter", new TypeInfoImpl(String.class.getName())));
taskFormModel = new TaskFormModel("hiring", "TechInterview", taskVariables);
processTasks.add(taskFormModel);
JBPMProcessModel model = new JBPMProcessModel(processFormModel, processTasks);
formModels.add(model);
}
use of org.kie.workbench.common.forms.model.impl.ModelPropertyImpl in project kie-wb-common by kiegroup.
the class ModelPropertiesGenerator method createModelProperty.
public static ModelProperty createModelProperty(String name, String className, boolean isMultiple, ClassLoader classLoader) {
if (FormModelPropertiesUtil.isBaseType(className)) {
// Dealing with basic type properties (String, Integer...)
return new ModelPropertyImpl(name, new TypeInfoImpl(className, isMultiple));
} else {
// Dealing with complex types.
if (FormModelPropertiesUtil.isListType(className)) {
// If className is a List let's create a model for Object...
return createModelProperty(name, Object.class.getName(), true);
}
try {
Class clazz = classLoader.loadClass(className);
TypeKind typeKind = clazz.isEnum() ? TypeKind.ENUM : TypeKind.OBJECT;
return new ModelPropertyImpl(name, new TypeInfoImpl(typeKind, className, isMultiple));
} catch (ClassNotFoundException e) {
logger.warn("Unable to create property '" + name + "' for class '" + className + "':", e);
}
}
return null;
}
use of org.kie.workbench.common.forms.model.impl.ModelPropertyImpl 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.model.impl.ModelPropertyImpl in project kie-wb-common by kiegroup.
the class FormDefinitionGenerator method updateNestedFormsModelProperties.
private void updateNestedFormsModelProperties(FormDefinition newFormDefinition, FieldDefinition nestedFormField, Form nestedForm) {
nestedFormField.setStandaloneClassName(nestedForm.getHolders().iterator().next().getClassName());
FormModel model = newFormDefinition.getModel();
ModelProperty modelProperty = model.getProperty(nestedFormField.getBinding());
if (modelProperty != null) {
model.getProperties().remove(modelProperty);
ModelPropertyImpl newProperty = new ModelPropertyImpl(nestedFormField.getBinding(), nestedFormField.getFieldTypeInfo());
newProperty.getMetaData().getEntries().addAll(modelProperty.getMetaData().getEntries());
model.getProperties().add(newProperty);
}
}
use of org.kie.workbench.common.forms.model.impl.ModelPropertyImpl in project kie-wb-common by kiegroup.
the class AbstractFieldAdapter method parseField.
@Override
public void parseField(Field originalField, FormMigrationSummary formSummary, FormDefinition newFormDefinition, Consumer<LayoutComponent> layoutElementConsumer) {
FieldDefinition fieldDefinition = getFieldDefinition(originalField);
fieldDefinition.setId(String.valueOf(originalField.getId()));
fieldDefinition.setName(originalField.getFieldName());
fieldDefinition.setLabel(lookupI18nValue(originalField.getLabel()));
fieldDefinition.setHelpMessage(lookupI18nValue(originalField.getTitle()));
fieldDefinition.setStandaloneClassName(StringUtils.defaultIfBlank(originalField.getBag(), originalField.getFieldType().getFieldClass()));
fieldDefinition.setReadOnly(originalField.getReadonly());
fieldDefinition.setRequired(originalField.getFieldRequired());
String binding = StringUtils.defaultString(StringUtils.defaultIfBlank(originalField.getInputBinding(), originalField.getOutputBinding()));
if (!StringUtils.isEmpty(binding)) {
if (binding.contains("/")) {
binding = binding.substring(binding.indexOf("/") + 1);
}
ModelPropertyImpl property = new ModelPropertyImpl(binding, fieldDefinition.getFieldTypeInfo());
newFormDefinition.getModel().getProperties().add(property);
}
fieldDefinition.setBinding(binding);
newFormDefinition.getFields().add(fieldDefinition);
LayoutComponent component = new LayoutComponent(DRAGGABLE_TYPE);
component.addProperty(FormLayoutComponent.FORM_ID, newFormDefinition.getId());
component.addProperty(FormLayoutComponent.FIELD_ID, fieldDefinition.getId());
layoutElementConsumer.accept(component);
}
Aggregations