use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.
the class FormModelSynchronizationUtilImplTest method checkField.
private void checkField(ModelProperty property, Class<? extends FieldDefinition> expectedFieldClass) {
FieldDefinition field = form.getFieldByBinding(property.getName());
assertNotNull(field);
assertEquals(expectedFieldClass, field.getClass());
assertEquals(property.getTypeInfo(), field.getFieldTypeInfo());
}
use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.
the class FormModelSynchronizationUtilImplTest method checkConflictedFieldDefinition.
public void checkConflictedFieldDefinition(TypeConflict conflict, Class<? extends FieldDefinition> expectedFieldClass) {
FieldDefinition field = form.getFieldByBinding(conflict.getPropertyName());
assertNotNull(field);
assertEquals(conflict.getPropertyName(), field.getBinding());
assertEquals(conflict.getNow().getClassName(), field.getStandaloneClassName());
assertEquals(field.getClass(), expectedFieldClass);
}
use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.
the class FormModelSynchronizationUtilImplTest method testRemoveModelProperties.
@Test
public void testRemoveModelProperties() {
ModelProperty name = formModel.getProperty("name");
assertNotNull(name);
formModelSynchronizationResult.getRemovedProperties().add(name);
ModelProperty surname = formModel.getProperty("surname");
assertNotNull(surname);
formModelSynchronizationResult.getRemovedProperties().add(surname);
ModelProperty birthday = formModel.getProperty("birthday");
assertNotNull(birthday);
formModelSynchronizationResult.getRemovedProperties().add(birthday);
synchronizationUtil.init(form, formModelSynchronizationResult);
int originalFormFields = form.getFields().size();
synchronizationUtil.fixRemovedFields();
assertEquals(originalFormFields, form.getFields().size());
assertNull(form.getFieldByBinding(name.getName()));
assertNull(form.getFieldByBinding(surname.getName()));
assertNull(form.getFieldByBinding(birthday.getName()));
FieldDefinition field = form.getFieldByName(name.getName());
assertNotNull(field);
assertNull(field.getBinding());
field = form.getFieldByName(surname.getName());
assertNotNull(field);
assertNull(field.getBinding());
field = form.getFieldByName(birthday.getName());
assertNotNull(field);
assertNull(field.getBinding());
}
use of org.kie.workbench.common.forms.model.FieldDefinition 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);
}
use of org.kie.workbench.common.forms.model.FieldDefinition 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;
}
Aggregations