Search in sources :

Example 1 with EditorFieldLayoutComponent

use of org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent in project kie-wb-common by kiegroup.

the class FormEditorHelperTest method loadContent.

private void loadContent() {
    testFieldManager = spy(new TestFieldManager());
    when(editorFieldLayoutComponents.get()).thenAnswer(invocationOnMock -> {
        final EditorFieldLayoutComponent mocked = mock(EditorFieldLayoutComponent.class);
        return mocked;
    });
    when(formEditorService.loadContent(any())).then(invocation -> {
        FormDefinition form = new FormDefinition();
        form.setName("EmployeeTestForm");
        form.setId("_random_id");
        content = new FormModelerContent();
        PortableJavaModel model = new PortableJavaModel("com.test.Employee");
        model.getProperties().addAll(modelProperties);
        form.setModel(model);
        content.setDefinition(form);
        content.setOverview(new Overview());
        return content;
    });
    when(testFieldManager.getBaseFieldTypes()).thenAnswer(invocationOnMock -> {
        List<String> baseFields = new ArrayList<>();
        baseFields.add("TextBox");
        baseFields.add("CheckBox");
        return baseFields;
    });
    editorServiceCallerMock = new CallerMock<>(formEditorService);
    formEditorHelper = new TestFormEditorHelper(testFieldManager, editorFieldLayoutComponents);
    formEditorService.loadContent(null);
    formEditorHelper.initHelper(content);
    assertEquals(formEditorHelper.getEditorFieldTypes().size(), formEditorHelper.getBaseFieldsDraggables().size());
}
Also used : FormModelerContent(org.kie.workbench.common.forms.editor.model.FormModelerContent) ArrayList(java.util.ArrayList) PortableJavaModel(org.kie.workbench.common.forms.model.impl.PortableJavaModel) TestFormEditorHelper(org.kie.workbench.common.forms.editor.client.editor.test.TestFormEditorHelper) EditorFieldLayoutComponent(org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent) Overview(org.guvnor.common.services.shared.metadata.model.Overview) TestFieldManager(org.kie.workbench.common.forms.fields.test.TestFieldManager) Mockito.anyString(org.mockito.Mockito.anyString) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 2 with EditorFieldLayoutComponent

use of org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent in project kie-wb-common by kiegroup.

the class FormEditorHelper method initHelper.

public void initHelper(FormModelerContent content) {
    this.content = content;
    if (unbindedFields != null && !unbindedFields.isEmpty()) {
        return;
    }
    for (FieldType baseType : enabledPaletteFieldTypes) {
        EditorFieldLayoutComponent layoutComponent = editorFieldLayoutComponents.get();
        if (layoutComponent != null) {
            FieldDefinition field = fieldManager.getDefinitionByFieldType(baseType);
            field.setName(generateUnboundFieldName(field));
            layoutComponent.init(content.getRenderingContext(), field);
            unbindedFields.put(field.getId(), new Pair<>(layoutComponent, field));
        }
    }
    addAvailableFields();
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) EditorFieldLayoutComponent(org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent) FieldType(org.kie.workbench.common.forms.model.FieldType)

Example 3 with EditorFieldLayoutComponent

use of org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent in project kie-wb-common by kiegroup.

the class FormEditorPresenter method loadAvailableFields.

protected void loadAvailableFields() {
    LayoutDragComponentGroup group = new LayoutDragComponentGroup(translationService.getTranslation(FormEditorConstants.FormEditorPresenterModelFields));
    editorHelper.getAvailableFields().values().forEach(fieldDefinition -> {
        EditorFieldLayoutComponent layoutFieldComponent = editorFieldLayoutComponents.get();
        if (layoutFieldComponent != null) {
            layoutFieldComponent.init(editorHelper.getRenderingContext(), fieldDefinition);
            group.addLayoutDragComponent(fieldDefinition.getId(), layoutFieldComponent);
        }
    });
    layoutDragComponentPalette.addDraggableGroup(group);
}
Also used : LayoutDragComponentGroup(org.uberfire.ext.layout.editor.client.api.LayoutDragComponentGroup) EditorFieldLayoutComponent(org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent)

Example 4 with EditorFieldLayoutComponent

use of org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent in project kie-wb-common by kiegroup.

the class FormEditorHelper method getFormField.

public FieldDefinition getFormField(String fieldId) {
    FieldDefinition result = content.getDefinition().getFieldById(fieldId);
    if (result == null) {
        result = availableFields.get(fieldId);
        if (result == null) {
            if (unbindedFields.containsKey(fieldId)) {
                Pair<EditorFieldLayoutComponent, FieldDefinition> pair = unbindedFields.get(fieldId);
                result = pair.getK2();
                result.setLabel(result.getFieldType().getTypeName());
                if (result instanceof HasPlaceHolder) {
                    ((HasPlaceHolder) result).setPlaceHolder(result.getFieldType().getTypeName());
                }
                unbindedFields.remove(result.getId());
                FieldDefinition newField = fieldManager.getDefinitionByFieldType(result.getFieldType());
                newField.setName(generateUnboundFieldName(newField));
                EditorFieldLayoutComponent component = pair.getK1();
                component.init(content.getRenderingContext(), newField);
                unbindedFields.put(newField.getId(), new Pair<>(component, newField));
            }
        }
    }
    return result;
}
Also used : HasPlaceHolder(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasPlaceHolder) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) EditorFieldLayoutComponent(org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent)

Example 5 with EditorFieldLayoutComponent

use of org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent in project kie-wb-common by kiegroup.

the class FormEditorPresenter method addAllDraggableGroupComponent.

protected void addAllDraggableGroupComponent(Collection<FieldDefinition> fields) {
    String groupId = translationService.getTranslation(FormEditorConstants.FormEditorPresenterModelFields);
    Iterator<FieldDefinition> it = fields.iterator();
    while (it.hasNext()) {
        FieldDefinition field = it.next();
        EditorFieldLayoutComponent layoutFieldComponent = editorFieldLayoutComponents.get();
        if (layoutFieldComponent != null) {
            layoutFieldComponent.init(editorHelper.getRenderingContext(), field);
            layoutDragComponentPalette.addDraggableComponent(groupId, field.getId(), layoutFieldComponent);
        }
    }
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) EditorFieldLayoutComponent(org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent)

Aggregations

EditorFieldLayoutComponent (org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent)5 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)3 ArrayList (java.util.ArrayList)1 Overview (org.guvnor.common.services.shared.metadata.model.Overview)1 TestFormEditorHelper (org.kie.workbench.common.forms.editor.client.editor.test.TestFormEditorHelper)1 FormModelerContent (org.kie.workbench.common.forms.editor.model.FormModelerContent)1 HasPlaceHolder (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasPlaceHolder)1 TestFieldManager (org.kie.workbench.common.forms.fields.test.TestFieldManager)1 FieldType (org.kie.workbench.common.forms.model.FieldType)1 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)1 PortableJavaModel (org.kie.workbench.common.forms.model.impl.PortableJavaModel)1 Mockito.anyString (org.mockito.Mockito.anyString)1 LayoutDragComponentGroup (org.uberfire.ext.layout.editor.client.api.LayoutDragComponentGroup)1