use of org.uberfire.ext.layout.editor.api.editor.LayoutComponent in project kie-wb-common by kiegroup.
the class FormLayoutTemplateGeneratorTest method testGeneratedLayout.
protected void testGeneratedLayout() {
LayoutTemplate layout = form.getLayoutTemplate();
assertNotNull(layout);
assertNotNull(layout.getRows());
assertEquals(form.getFields().size(), layout.getRows().size());
for (LayoutRow row : layout.getRows()) {
assertEquals(1, row.getLayoutColumns().size());
for (LayoutColumn col : row.getLayoutColumns()) {
assertEquals("12", col.getSpan());
assertEquals(0, col.getRows().size());
assertEquals(1, col.getLayoutComponents().size());
for (LayoutComponent component : col.getLayoutComponents()) {
assertEquals(templateGenerator.getDraggableType(), component.getDragTypeName());
assertEquals(form.getId(), component.getProperties().get(FormLayoutComponent.FORM_ID));
String fieldId = component.getProperties().get(FormLayoutComponent.FIELD_ID);
assertNotNull(fieldId);
assertNotNull(form.getFieldById(fieldId));
}
}
}
}
use of org.uberfire.ext.layout.editor.api.editor.LayoutComponent 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.uberfire.ext.layout.editor.api.editor.LayoutComponent in project kie-wb-common by kiegroup.
the class LayoutGeneratorTest method testTwoColumnsWithWraps.
@Test
public void testTwoColumnsWithWraps() {
LayoutComponent component = mock(LayoutComponent.class);
when(component.getDragTypeName()).thenReturn("wrap");
LayoutSettings settings = new LayoutSettings();
settings.setWrap(true);
settingsMap.put(component, settings);
component = mock(LayoutComponent.class);
when(component.getDragTypeName()).thenReturn("wrap");
settingsMap.put(component, settings);
LayoutColumnDefinition[] structure = new LayoutColumnDefinition[] { new LayoutColumnDefinition(), new LayoutColumnDefinition() };
generator.init(structure);
settingsMap.entrySet().forEach(entry -> generator.addComponent(entry.getKey(), entry.getValue()));
LayoutTemplate result = generator.build();
assertNotNull(result);
assertNotNull(result.getRows());
assertEquals(settingsMap.size() / 2 + 1, result.getRows().size());
result.getRows().forEach(row -> {
assertNotNull(row);
assertNotNull(row.getLayoutColumns());
LayoutComponent layoutComponent = row.getLayoutColumns().get(0).getLayoutComponents().get(0);
if ("wrap".equals(layoutComponent.getDragTypeName())) {
checkTwoColumnsRowWraps(row);
} else {
checkTwoColumnsRow(row);
}
});
}
use of org.uberfire.ext.layout.editor.api.editor.LayoutComponent in project kie-wb-common by kiegroup.
the class LayoutGeneratorTest method testTwoColumnsLayoutWithSpans.
@Test
public void testTwoColumnsLayoutWithSpans() {
LayoutComponent component = mock(LayoutComponent.class);
when(component.getDragTypeName()).thenReturn("span");
LayoutSettings settings = new LayoutSettings();
settings.setHorizontalSpan(2);
settingsMap.put(component, settings);
component = mock(LayoutComponent.class);
when(component.getDragTypeName()).thenReturn("span");
settingsMap.put(component, settings);
LayoutColumnDefinition[] structure = new LayoutColumnDefinition[] { new LayoutColumnDefinition(), new LayoutColumnDefinition() };
generator.init(structure);
settingsMap.entrySet().forEach(entry -> generator.addComponent(entry.getKey(), entry.getValue()));
LayoutTemplate result = generator.build();
assertNotNull(result);
assertNotNull(result.getRows());
assertEquals(settingsMap.size() / 2 + 1, result.getRows().size());
result.getRows().forEach(row -> {
assertNotNull(row);
assertNotNull(row.getLayoutColumns());
LayoutComponent layoutComponent = row.getLayoutColumns().get(0).getLayoutComponents().get(0);
if ("span".equals(layoutComponent.getDragTypeName())) {
checkSingleColumnRow(row);
} else {
checkTwoColumnsRow(row);
}
});
}
use of org.uberfire.ext.layout.editor.api.editor.LayoutComponent 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