Search in sources :

Example 61 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.

the class FormEditorServiceImpl method constructContent.

@Override
protected FormModelerContent constructContent(Path path, Overview overview) {
    try {
        org.uberfire.java.nio.file.Path kiePath = Paths.convert(path);
        FormDefinition form = findForm(kiePath);
        FormModelerContent formModelConent = new FormModelerContent();
        formModelConent.setDefinition(form);
        formModelConent.setPath(path);
        formModelConent.setOverview(overview);
        FormEditorRenderingContext context = createRenderingContext(form, path);
        formModelConent.setRenderingContext(context);
        if (Optional.ofNullable(form.getModel()).isPresent()) {
            FormModel formModel = form.getModel();
            Optional<FormModelHandler> modelHandlerOptional = getHandlerForForm(form, path);
            if (modelHandlerOptional.isPresent()) {
                FormModelHandler formModelHandler = modelHandlerOptional.get();
                FormModelSynchronizationResult synchronizationResult = formModelHandler.synchronizeFormModel();
                formModel.getProperties().forEach(property -> {
                    Optional<FieldDefinition> fieldOptional = Optional.ofNullable(form.getFieldByBinding(property.getName()));
                    if (!fieldOptional.isPresent()) {
                        synchronizationResult.resolveConflict(property.getName());
                    }
                });
                formModelConent.setSynchronizationResult(synchronizationResult);
            }
        }
        resourceOpenedEvent.fire(new ResourceOpenedEvent(path, sessionInfo));
        return formModelConent;
    } catch (Exception e) {
        log.warn("Error loading form " + path.toURI(), e);
    }
    return null;
}
Also used : FormEditorRenderingContext(org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext) FormModelerContent(org.kie.workbench.common.forms.editor.model.FormModelerContent) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) ResourceOpenedEvent(org.uberfire.workbench.events.ResourceOpenedEvent) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) FormModel(org.kie.workbench.common.forms.model.FormModel) FormModelSynchronizationResult(org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult) FormModelHandler(org.kie.workbench.common.forms.editor.service.backend.FormModelHandler) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 62 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.

the class FormEditorServiceImpl method createRenderingContext.

protected FormEditorRenderingContext createRenderingContext(FormDefinition form, Path formPath) {
    FormEditorRenderingContext context = new FormEditorRenderingContext(formPath);
    context.setRootForm(form);
    List<FormDefinition> allForms = vfsFormFinderService.findAllForms(formPath);
    for (FormDefinition vfsForm : allForms) {
        if (!vfsForm.getId().equals(form.getId())) {
            context.getAvailableForms().put(vfsForm.getId(), vfsForm);
        }
    }
    return context;
}
Also used : FormEditorRenderingContext(org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 63 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.

the class FormEditorHelper method removeField.

public void removeField(String fieldId, boolean addToAvailables) {
    FormDefinition formDefinition = content.getDefinition();
    FieldDefinition fieldToRemove = formDefinition.getFieldById(fieldId);
    if (fieldToRemove != null) {
        formDefinition.getFields().remove(fieldToRemove);
        if (addToAvailables) {
            FieldDefinition originalField = fieldToRemove;
            if (fieldToRemove.getBinding() == null) {
                return;
            }
            ModelProperty property = formDefinition.getModel().getProperty(fieldToRemove.getBinding());
            fieldToRemove = fieldManager.getDefinitionByModelProperty(property);
            fieldToRemove.setId(originalField.getId());
            availableFields.put(fieldToRemove.getId(), fieldToRemove);
        }
    }
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 64 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.

the class FormEditorHelper method addAvailableFields.

public void addAvailableFields() {
    FormModel model = getFormModel();
    FormDefinition formDefinition = getFormDefinition();
    model.getProperties().forEach(modelProperty -> {
        if (formDefinition.getFieldByBinding(modelProperty.getName()) == null) {
            addAvailableField(fieldManager.getDefinitionByModelProperty(modelProperty));
        }
    });
}
Also used : FormModel(org.kie.workbench.common.forms.model.FormModel) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 65 with FormDefinition

use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.

the class FormModelConflictHandler method checkConflicts.

@Override
public boolean checkConflicts(FormModelerContent content, Consumer<ConflictElement> conflictElementConsumer) {
    init(content, conflictElementConsumer);
    this.removed = false;
    this.conflicts = false;
    FormDefinition formDefinition = content.getDefinition();
    FormModelSynchronizationResult synchronizationResult = content.getSynchronizationResult();
    if (synchronizationResult == null) {
        return false;
    }
    checkRemovedProperties(formDefinition, synchronizationResult);
    checkConflictProperties(formDefinition, synchronizationResult);
    return removed || conflicts;
}
Also used : FormModelSynchronizationResult(org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Aggregations

FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)89 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)30 Test (org.junit.Test)29 ArrayList (java.util.ArrayList)16 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)14 FormGenerationResult (org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult)14 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)13 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)12 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)12 AbstractFormGenerationTest (org.kie.workbench.common.forms.adf.engine.shared.test.AbstractFormGenerationTest)10 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)10 List (java.util.List)9 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)9 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)8 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)8 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)8 Person (org.kie.workbench.common.forms.adf.engine.shared.formGeneration.model.Person)7 FormModel (org.kie.workbench.common.forms.model.FormModel)7 PortableJavaModel (org.kie.workbench.common.forms.model.impl.PortableJavaModel)7 Date (java.util.Date)6