Search in sources :

Example 6 with FormEditorRenderingContext

use of org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext in project kie-wb-common by kiegroup.

the class VFSSelectorFormProvider method getSelectorData.

@Override
public SelectorData getSelectorData(FormRenderingContext context) {
    Map<String, String> values = new TreeMap<>();
    if (context.getModel() instanceof EntityRelationField) {
        FormEditorRenderingContext editorContext = (FormEditorRenderingContext) context;
        FieldDefinition field = (FieldDefinition) context.getModel();
        List<FormDefinition> forms;
        if (field != null) {
            forms = vfsFormFinderService.findFormsForType(field.getStandaloneClassName(), editorContext.getFormPath());
        } else {
            forms = vfsFormFinderService.findAllForms(editorContext.getFormPath());
        }
        for (FormDefinition form : forms) {
            values.put(form.getId(), form.getName());
        }
    }
    return new SelectorData(values, null);
}
Also used : EntityRelationField(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EntityRelationField) FormEditorRenderingContext(org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TreeMap(java.util.TreeMap) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData)

Example 7 with FormEditorRenderingContext

use of org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext 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 8 with FormEditorRenderingContext

use of org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext 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)

Aggregations

FormEditorRenderingContext (org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext)8 SelectorData (org.kie.workbench.common.forms.dynamic.model.config.SelectorData)3 TableColumnMeta (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta)3 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)3 FormRenderingContext (org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext)2 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)2 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 Collectors (java.util.stream.Collectors)1 Dependent (javax.enterprise.context.Dependent)1 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Before (org.junit.Before)1 Test (org.junit.Test)1 DataObjectFinderService (org.kie.workbench.common.forms.data.modeller.service.DataObjectFinderService)1 SystemSelectorDataProvider (org.kie.workbench.common.forms.dynamic.model.config.SystemSelectorDataProvider)1 FormModelSynchronizationResult (org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult)1