use of org.kie.workbench.common.forms.processing.engine.handling.IsNestedModel in project kie-wb-common by kiegroup.
the class FormHandlerImpl method registerInput.
@Override
public void registerInput(FormField formField, Converter valueConverter) {
Assert.notNull("FormHandler isn't correctly initialized, please run any of the setUp methods before use", binder);
Assert.notNull("FormField cannot be null!", formField);
String fieldName = formField.getFieldName();
IsWidget widget = formField.getWidget();
form.addField(formField);
if (formField.isBindable()) {
BindableProxy proxy = (BindableProxy) binder.getModel();
Object modelValue = readPropertyValue(proxy, formField.getFieldBinding());
StateSync stateSync = Optional.ofNullable(modelValue).isPresent() ? StateSync.FROM_MODEL : StateSync.FROM_UI;
binder.bind(widget, formField.getFieldBinding(), valueConverter, stateSync);
}
fieldChangeManager.registerField(formField);
formField.getChangeListeners().forEach(listener -> fieldChangeManager.addFieldChangeHandler(listener.getFieldToListen(), listener.getChangeHandler()));
/**
* if field isn't bindable we cannot listen to field value changes.
*/
if (!formField.isBindable()) {
return;
}
if (widget instanceof IsNestedModel) {
IsNestedModel nestedModelWidget = (IsNestedModel) widget;
nestedModelWidget.addFieldChangeHandler((childFieldName, newValue) -> fieldChangeManager.notifyFieldChange(fieldName + "." + childFieldName, newValue));
} else {
PropertyChangeUnsubscribeHandle unsubscribeHandle = binder.addPropertyChangeHandler(formField.getFieldBinding(), event -> fieldChangeManager.processFieldChange(fieldName, event.getNewValue(), binder.getModel()));
unsubscribeHandlers.add(unsubscribeHandle);
}
}
Aggregations