use of org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition in project kie-wb-common by kiegroup.
the class AbstractBPMNFormGeneratorService method createFormLayout.
protected void createFormLayout(FormDefinition form) {
LayoutGenerator layoutGenerator = new LayoutGenerator();
layoutGenerator.init(new LayoutColumnDefinition[] { new LayoutColumnDefinition(ColSpan.SPAN_12) });
if (form.getFields().size() > 0) {
boolean separeateInputsAndOutputs = form.getModel() instanceof TaskFormModel;
boolean mightAddOtuputsLabel = form.getFields().get(0).getReadOnly();
if (separeateInputsAndOutputs) {
if (mightAddOtuputsLabel) {
layoutGenerator.addComponent(generateHTMLElement(INPUTS), new LayoutSettings());
} else {
layoutGenerator.addComponent(generateHTMLElement(OUTPUTS), new LayoutSettings());
}
}
for (FieldDefinition fieldDefinition : form.getFields()) {
if (separeateInputsAndOutputs && mightAddOtuputsLabel && !fieldDefinition.getReadOnly()) {
mightAddOtuputsLabel = false;
layoutGenerator.addComponent(generateHTMLElement(OUTPUTS), new LayoutSettings());
}
LayoutComponent fieldComponent = new LayoutComponent(StaticFormLayoutTemplateGenerator.DRAGGABLE_TYPE);
fieldComponent.addProperty(FormLayoutComponent.FORM_ID, form.getId());
fieldComponent.addProperty(FormLayoutComponent.FIELD_ID, fieldDefinition.getId());
layoutGenerator.addComponent(fieldComponent, new LayoutSettings());
}
}
form.setLayoutTemplate(layoutGenerator.build());
}
use of org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition in project kie-wb-common by kiegroup.
the class AbstractFormGenerator method generateFormDefinition.
protected FormDefinition generateFormDefinition(FormDefinitionSettings settings, Object model, FormElementFilter... filters) {
FormGenerationContext context = new FormGenerationContext(model, settings, getI18nHelper(settings.getI18nSettings()), filters);
context.setFieldStatusModifierReferences(fieldModifierReferences);
context.setFieldStatusModifiers(fieldModifiers);
if (settings.getLayout() == null || settings.getLayout().getColumns() == null || settings.getLayout().getColumns().length == 0) {
settings.setLayout(new LayoutDefinition(new LayoutColumnDefinition()));
}
layoutGenerator.init(settings.getLayout().getColumns());
processElements(context);
FormDefinition form = context.getFormDefinition();
form.setLayoutTemplate(layoutGenerator.build());
return form;
}
use of org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition 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.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition in project kie-wb-common by kiegroup.
the class LayoutGeneratorTest method testSimpleVerticalLayout.
@Test
public void testSimpleVerticalLayout() {
LayoutColumnDefinition[] structure = 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(), result.getRows().size());
result.getRows().forEach(row -> {
checkSingleColumnRow(row);
});
}
use of org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition 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);
}
});
}
Aggregations