Search in sources :

Example 1 with StateSync

use of org.jboss.errai.databinding.client.api.StateSync 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);
    }
}
Also used : IsWidget(com.google.gwt.user.client.ui.IsWidget) PropertyChangeUnsubscribeHandle(org.jboss.errai.databinding.client.PropertyChangeUnsubscribeHandle) StateSync(org.jboss.errai.databinding.client.api.StateSync) BindableProxy(org.jboss.errai.databinding.client.BindableProxy) IsNestedModel(org.kie.workbench.common.forms.processing.engine.handling.IsNestedModel)

Aggregations

IsWidget (com.google.gwt.user.client.ui.IsWidget)1 BindableProxy (org.jboss.errai.databinding.client.BindableProxy)1 PropertyChangeUnsubscribeHandle (org.jboss.errai.databinding.client.PropertyChangeUnsubscribeHandle)1 StateSync (org.jboss.errai.databinding.client.api.StateSync)1 IsNestedModel (org.kie.workbench.common.forms.processing.engine.handling.IsNestedModel)1