use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.
the class AbstractBPMNFormGeneratorService method createModelFormDefinition.
protected FormDefinition createModelFormDefinition(String modelType, GenerationContext<SOURCE> context) {
FormDefinition form = context.getContextForms().get(modelType);
if (form == null) {
String modelName = modelType.substring(modelType.lastIndexOf(".") + 1);
String formModelName = modelName;
formModelName = formModelName.substring(0, 1).toLowerCase() + formModelName.substring(1);
DataObjectFormModel formModel = new DataObjectFormModel(formModelName, modelType);
form = new FormDefinition(formModel);
context.getContextForms().put(modelType, form);
form.setId(UIDGenerator.generateUID());
form.setName(modelName);
// TODO: extract model properties & generate fields
List<FieldDefinition> fields = extractModelFields(formModel, context);
form.getFields().addAll(fields);
createFormLayout(form);
processFormDefinition(form, context);
}
return form;
}
use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.
the class BPMNRuntimeFormGeneratorService method createRootFormDefinition.
@Override
protected FormDefinition createRootFormDefinition(GenerationContext<ClassLoader> context) {
FormDefinition form = new FormDefinition(context.getFormModel());
form.setId(context.getFormModel().getFormName());
form.setName(context.getFormModel().getFormName());
context.getFormModel().getProperties().forEach(property -> {
if (!BPMNVariableUtils.isValidInputName(property.getName())) {
return;
}
FieldDefinition field = generateFieldDefinition(property, context);
if (field != null) {
form.getFields().add(field);
}
});
return form;
}
use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.
the class BPMNRuntimeFormGeneratorService method generateFieldDefinition.
protected FieldDefinition generateFieldDefinition(ModelProperty property, GenerationContext<ClassLoader> context) {
FieldDefinition field = fieldManager.getDefinitionByModelProperty(property);
if (field == null) {
return null;
}
processFieldDefinition(field, context);
return field;
}
use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.
the class AbstractFieldElementProcessor method processFormElement.
@Override
public LayoutComponent processFormElement(FieldElement element, FormGenerationContext context) {
FieldDefinition field;
if (element.getPreferredType().equals(FieldType.class)) {
field = fieldManager.getDefinitionByDataType(element.getTypeInfo());
} else {
field = fieldManager.getDefinitionByFieldType(element.getPreferredType(), element.getTypeInfo());
if (field == null) {
field = fieldManager.getDefinitionByDataType(element.getTypeInfo());
}
}
if (field != null) {
context.getFormDefinition().getFields().add(field);
field.setId(element.getName());
field.setName(element.getName());
field.setBinding(element.getBinding());
String label = context.getI18nHelper().getTranslation(element.getLabelKey());
if (label == null || label.isEmpty()) {
label = element.getName().substring(0, 1).toUpperCase() + element.getName().substring(1);
}
field.setLabel(label);
String helpMessage = context.getI18nHelper().getTranslation(element.getHelpMessageKey());
field.setHelpMessage(helpMessage);
field.setRequired(element.isRequired());
field.setReadOnly(element.isReadOnly());
if (context.getModel() != null) {
String fullFieldName = context.getFormDefinitionSettings().getModelType() + "." + element.getName();
FieldStatusModifier initializer = context.getStatusModifierForFieldName(fullFieldName);
if (initializer != null) {
initializer.modifyFieldStatus(field, propertyValueExtractor.readPropertyValue(context.getModel(), element.getName()));
}
}
for (FieldInitializer fieldInitializer : initializers) {
if (fieldInitializer.supports(field)) {
fieldInitializer.initialize(field, element, context);
}
}
LayoutComponent component = new LayoutComponent("org.kie.workbench.common.forms.dynamic.client.rendering.FieldLayoutComponent");
component.addProperty(FormLayoutComponent.FORM_ID, context.getFormDefinition().getId());
component.addProperty(FormLayoutComponent.FIELD_ID, field.getId());
return component;
}
return null;
}
use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.
the class AbstractFormGenerationTest method testGeneratedForm.
protected void testGeneratedForm(FormDefinition form, String modelName) {
assertNotNull(form);
FormDefinitionSettings settings = resourcesProvider.getDefinitionSettings().get(modelName);
assertEquals(settings.getModelType(), form.getId());
assertEquals(settings.getModelType(), form.getName());
assertEquals(settings.getFormElements().size(), form.getFields().size());
settings.getFormElements().forEach(element -> {
FieldElement fieldElement = (FieldElement) element;
FieldDefinition field = form.getFieldByBinding(fieldElement.getBinding());
assertNotNull(field);
assertEquals(fieldElement.getName(), field.getName());
if (!fieldElement.getPreferredType().equals(FieldType.class)) {
assertEquals(fieldElement.getPreferredType(), field.getFieldType().getClass());
}
assertEquals(fieldElement.getTypeInfo().getClassName(), field.getStandaloneClassName());
assertEquals(fieldElement.isReadOnly(), field.getReadOnly());
assertEquals(fieldElement.isRequired(), field.getRequired());
assertEquals(fieldElement.getBinding(), field.getBinding());
verify(i18nHelper, atLeast(1)).getTranslation(field.getName() + ".label");
});
assertNotNull(form.getLayoutTemplate());
assertEquals(settings.getFormElements().size(), form.getLayoutTemplate().getRows().size());
form.getLayoutTemplate().getRows().forEach(row -> {
assertNotNull(row);
assertEquals(1, row.getLayoutColumns().size());
LayoutColumn column = row.getLayoutColumns().get(0);
assertNotNull(column);
assertEquals("12", column.getSpan());
assertEquals(1, column.getLayoutComponents().size());
LayoutComponent layoutComponent = column.getLayoutComponents().get(0);
String formId = layoutComponent.getProperties().get(FormLayoutComponent.FORM_ID);
assertNotNull(formId);
assertEquals(form.getId(), formId);
String fieldId = layoutComponent.getProperties().get(FormLayoutComponent.FIELD_ID);
assertNotNull(fieldId);
FieldDefinition field = form.getFieldById(fieldId);
assertNotNull(field);
});
}
Aggregations