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