Search in sources :

Example 1 with LayoutSettings

use of org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings 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 LayoutSettings

use of org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings 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 3 with LayoutSettings

use of org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings 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)

Example 4 with LayoutSettings

use of org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings in project kie-wb-common by kiegroup.

the class LayoutGeneratorTest method initTest.

@Before
public void initTest() {
    settingsMap.put(mock(LayoutComponent.class), new LayoutSettings());
    settingsMap.put(mock(LayoutComponent.class), new LayoutSettings());
    settingsMap.put(mock(LayoutComponent.class), new LayoutSettings());
    settingsMap.put(mock(LayoutComponent.class), new LayoutSettings());
    settingsMap.put(mock(LayoutComponent.class), new LayoutSettings());
    settingsMap.put(mock(LayoutComponent.class), new LayoutSettings());
}
Also used : LayoutSettings(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) Before(org.junit.Before)

Aggregations

LayoutSettings (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings)4 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)4 LayoutColumnDefinition (org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition)3 Test (org.junit.Test)2 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)2 Before (org.junit.Before)1 LayoutGenerator (org.kie.workbench.common.forms.adf.engine.shared.formGeneration.layout.LayoutGenerator)1 TaskFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel)1 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)1 FormLayoutComponent (org.kie.workbench.common.forms.model.FormLayoutComponent)1