Search in sources :

Example 1 with LayoutColumnDefinition

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());
}
Also used : LayoutColumnDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition) LayoutGenerator(org.kie.workbench.common.forms.adf.engine.shared.formGeneration.layout.LayoutGenerator) LayoutSettings(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TaskFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel) FormLayoutComponent(org.kie.workbench.common.forms.model.FormLayoutComponent) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent)

Example 2 with LayoutColumnDefinition

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;
}
Also used : LayoutColumnDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition) LayoutDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutDefinition) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 3 with LayoutColumnDefinition

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);
        }
    });
}
Also used : LayoutColumnDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition) LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) LayoutSettings(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) Test(org.junit.Test)

Example 4 with LayoutColumnDefinition

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);
    });
}
Also used : LayoutColumnDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition) LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) Test(org.junit.Test)

Example 5 with LayoutColumnDefinition

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);
        }
    });
}
Also used : LayoutColumnDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition) LayoutTemplate(org.uberfire.ext.layout.editor.api.editor.LayoutTemplate) LayoutSettings(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) Test(org.junit.Test)

Aggregations

LayoutColumnDefinition (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition)8 Test (org.junit.Test)5 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)5 LayoutSettings (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings)3 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)3 ArrayList (java.util.ArrayList)1 ColSpan (org.kie.workbench.common.forms.adf.definitions.settings.ColSpan)1 LayoutGenerator (org.kie.workbench.common.forms.adf.engine.shared.formGeneration.layout.LayoutGenerator)1 LayoutDefinition (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutDefinition)1 TaskFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel)1 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)1 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)1 FormLayoutComponent (org.kie.workbench.common.forms.model.FormLayoutComponent)1