use of org.uberfire.ext.layout.editor.api.editor.LayoutRow in project kie-wb-common by kiegroup.
the class AbstractFormDefinitionGeneratorTest method verifyUserForm.
protected void verifyUserForm(FormMigrationSummary summary) {
Form originalForm = summary.getOriginalForm().get();
Assertions.assertThat(originalForm.getFormFields()).isNotEmpty().hasSize(2);
FormDefinition newForm = summary.getNewForm().get();
Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(2);
Assertions.assertThat(newForm.getModel()).isNotNull().hasFieldOrPropertyWithValue("className", USER_MODEL).isInstanceOf(DataObjectFormModel.class);
IntStream indexStream = IntStream.range(0, newForm.getFields().size());
LayoutTemplate formLayout = newForm.getLayoutTemplate();
assertNotNull(formLayout);
Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(2);
indexStream.forEach(index -> {
FieldDefinition fieldDefinition = newForm.getFields().get(index);
switch(index) {
case 0:
checkFieldDefinition(fieldDefinition, USER_LOGIN, "login", "login", TextBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 1:
checkFieldDefinition(fieldDefinition, USER_PASSWORD, "password", "password", TextBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
}
LayoutRow fieldRow = formLayout.getRows().get(index);
assertNotNull(fieldRow);
Assertions.assertThat(fieldRow.getLayoutColumns()).isNotEmpty().hasSize(1);
LayoutColumn fieldColumn = fieldRow.getLayoutColumns().get(0);
assertNotNull(fieldColumn);
assertEquals("12", fieldColumn.getSpan());
Assertions.assertThat(fieldColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
checkLayoutFormField(fieldColumn.getLayoutComponents().get(0), fieldDefinition, newForm);
});
}
use of org.uberfire.ext.layout.editor.api.editor.LayoutRow 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.LayoutRow in project kie-wb-common by kiegroup.
the class AbstractFormLayoutTemplateGenerator method addFieldsToTemplate.
protected void addFieldsToTemplate(LayoutTemplate template, List<FieldDefinition> fields, String formId) {
fields.forEach(field -> {
LayoutComponent layoutComponent = new LayoutComponent(getDraggableType());
layoutComponent.addProperty(FormLayoutComponent.FORM_ID, formId);
layoutComponent.addProperty(FormLayoutComponent.FIELD_ID, field.getId());
LayoutColumn column = new LayoutColumn("12");
column.add(layoutComponent);
LayoutRow row = new LayoutRow();
row.add(column);
template.addRow(row);
});
}
use of org.uberfire.ext.layout.editor.api.editor.LayoutRow in project kie-wb-common by kiegroup.
the class LayoutGenerator method build.
public LayoutTemplate build() {
LayoutTemplate template = new LayoutTemplate();
rows.stream().filter(row -> !row.cells.isEmpty()).forEach(row -> {
LayoutRow layoutRow = new LayoutRow();
template.addRow(layoutRow);
row.cells.forEach(cell -> {
LayoutColumn layoutColumn = new LayoutColumn(String.valueOf(cell.horizontalSpan));
layoutRow.add(layoutColumn);
if (cell.getComponentsCount() == 0) {
return;
} else if (cell.getComponentsCount() == 1) {
layoutColumn.add(cell.components.get(0));
} else {
cell.components.forEach(component -> {
LayoutRow nestedRow = new LayoutRow();
layoutColumn.addRow(nestedRow);
LayoutColumn nestedColumn = new LayoutColumn(String.valueOf(MAX_SPAN));
nestedRow.add(nestedColumn);
nestedColumn.add(component);
});
}
});
});
return template;
}
use of org.uberfire.ext.layout.editor.api.editor.LayoutRow in project kie-wb-common by kiegroup.
the class AbstractFormDefinitionGeneratorTest method verifyLineForm.
protected void verifyLineForm(FormMigrationSummary summary) {
Form originalForm = summary.getOriginalForm().get();
Assertions.assertThat(originalForm.getFormFields()).isNotEmpty().hasSize(4);
FormDefinition newForm = summary.getNewForm().get();
Assertions.assertThat(newForm.getFields()).isNotEmpty().hasSize(4);
Assertions.assertThat(newForm.getModel()).isNotNull().hasFieldOrPropertyWithValue("className", LINE_MODEL).isInstanceOf(DataObjectFormModel.class);
IntStream indexStream = IntStream.range(0, newForm.getFields().size());
LayoutTemplate formLayout = newForm.getLayoutTemplate();
assertNotNull(formLayout);
Assertions.assertThat(formLayout.getRows()).isNotEmpty().hasSize(1);
LayoutRow fieldRow = formLayout.getRows().get(0);
indexStream.forEach(index -> {
FieldDefinition fieldDefinition = newForm.getFields().get(index);
switch(index) {
case 0:
checkFieldDefinition(fieldDefinition, LINE_PRODUCT, "product", "product", TextBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 1:
checkFieldDefinition(fieldDefinition, LINE_PRICE, "price", "price", DecimalBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 2:
checkFieldDefinition(fieldDefinition, LINE_QUANTITY, "quantity", "quantity", IntegerBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
case 3:
checkFieldDefinition(fieldDefinition, LINE_TOTAL, "total", "total", DecimalBoxFieldDefinition.class, newForm, originalForm.getField(fieldDefinition.getName()));
break;
}
assertNotNull(fieldRow);
Assertions.assertThat(fieldRow.getLayoutColumns()).isNotEmpty().hasSize(4);
LayoutColumn fieldColumn = fieldRow.getLayoutColumns().get(index);
assertNotNull(fieldColumn);
assertEquals("3", fieldColumn.getSpan());
Assertions.assertThat(fieldColumn.getLayoutComponents()).isNotEmpty().hasSize(1);
checkLayoutFormField(fieldColumn.getLayoutComponents().get(0), fieldDefinition, newForm);
});
}
Aggregations