Search in sources :

Example 6 with FormModel

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

the class FormDefinitionIndexer method fillIndexBuilder.

@Override
protected DefaultIndexBuilder fillIndexBuilder(Path path) throws Exception {
    final DefaultIndexBuilder builder = getIndexBuilder(path);
    if (builder == null) {
        return null;
    }
    String formContent = ioService.readAllString(path);
    FormDefinition formDefinition = formDefinitionSerializer.deserialize(formContent);
    if (formDefinition != null) {
        Resource resParts = new Resource(formDefinition.getName(), ResourceType.FORM);
        FormDefinitionVisitor visitor = new FormDefinitionVisitor(resParts);
        visitor.visit(formDefinition);
        addReferencedResourcesToIndexBuilder(builder, visitor);
        FormModel model = formDefinition.getModel();
        if (model != null) {
            FormModelVisitorProvider provider = getProviderForModel(model.getClass());
            if (provider != null) {
                FormModelVisitor modelVisitor = provider.getVisitor();
                modelVisitor.index(formDefinition, model);
                addReferencedResourcesToIndexBuilder(builder, modelVisitor);
            }
        }
    } else {
        logger.error("Unable to read FormDefinition on " + path.toUri().toString() + ".");
        return null;
    }
    return builder;
}
Also used : FormModel(org.kie.workbench.common.forms.model.FormModel) Resource(org.kie.workbench.common.services.refactoring.Resource) DefaultIndexBuilder(org.kie.workbench.common.services.refactoring.backend.server.indexing.DefaultIndexBuilder) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 7 with FormModel

use of org.kie.workbench.common.forms.model.FormModel 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 FormModel

use of org.kie.workbench.common.forms.model.FormModel 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 9 with FormModel

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

the class FieldPropertiesRenderer method doRender.

protected void doRender(FieldPropertiesRendererHelper helper, FormEditorRenderingContext context) {
    FormModel roodFormModel = helper.getCurrentRenderingContext().getRootForm().getModel();
    final DataBindingEditor editor = roodFormModel instanceof DynamicModel ? dynamicDataBindingEditor : staticDataBindingEditor;
    editor.init(fieldCopy, this::getAvailableBindings, this::onFieldBindingChange);
    view.render(helper, context, editor);
}
Also used : DataBindingEditor(org.kie.workbench.common.forms.editor.client.editor.properties.binding.DataBindingEditor) StaticFormModel(org.kie.workbench.common.forms.editor.client.editor.properties.binding.StaticFormModel) DynamicFormModel(org.kie.workbench.common.forms.editor.client.editor.properties.binding.DynamicFormModel) FormModel(org.kie.workbench.common.forms.model.FormModel) DynamicModel(org.kie.workbench.common.forms.model.DynamicModel)

Example 10 with FormModel

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

the class FormDefinitionGenerator method updateNestedFormsModelProperties.

private void updateNestedFormsModelProperties(FormDefinition newFormDefinition, FieldDefinition nestedFormField, Form nestedForm) {
    nestedFormField.setStandaloneClassName(nestedForm.getHolders().iterator().next().getClassName());
    FormModel model = newFormDefinition.getModel();
    ModelProperty modelProperty = model.getProperty(nestedFormField.getBinding());
    if (modelProperty != null) {
        model.getProperties().remove(modelProperty);
        ModelPropertyImpl newProperty = new ModelPropertyImpl(nestedFormField.getBinding(), nestedFormField.getFieldTypeInfo());
        newProperty.getMetaData().getEntries().addAll(modelProperty.getMetaData().getEntries());
        model.getProperties().add(newProperty);
    }
}
Also used : FormModel(org.kie.workbench.common.forms.model.FormModel) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)

Aggregations

FormModel (org.kie.workbench.common.forms.model.FormModel)11 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)5 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 DataObjectFormModel (org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel)2 FormModelSynchronizationResult (org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult)2 FormModelHandler (org.kie.workbench.common.forms.editor.service.backend.FormModelHandler)2 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)2 Path (org.uberfire.backend.vfs.Path)2 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 DataBindingEditor (org.kie.workbench.common.forms.editor.client.editor.properties.binding.DataBindingEditor)1 DynamicFormModel (org.kie.workbench.common.forms.editor.client.editor.properties.binding.DynamicFormModel)1 StaticFormModel (org.kie.workbench.common.forms.editor.client.editor.properties.binding.StaticFormModel)1