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;
}
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;
}
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));
}
});
}
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);
}
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);
}
}
Aggregations