com.dragome.forms.bindings.client.binding.AbstractValueBinding Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dragome-form-bindings Show documentation
Show all versions of dragome-form-bindings Show documentation
Dragome SDK module: form bindings
package com.dragome.forms.bindings.client.binding;
import com.dragome.forms.bindings.client.value.GuardedValueChangeHandler;
import com.dragome.forms.bindings.client.value.ValueModel;
import com.dragome.model.interfaces.ValueChangeEvent;
/**
* Created by IntelliJ IDEA.
* User: andrew
* Date: May 22, 2010
* Time: 9:20:15 AM
* To change this template use File | Settings | File Templates.
*/
public abstract class AbstractValueBinding extends AbstractBinding
{
private ValueModel model;
private ModelChangeHandler valueMonitor= new ModelChangeHandler();
public AbstractValueBinding(ValueModel model)
{
this.model= model;
registerDisposable(model.addValueChangeHandler(valueMonitor));
}
protected ValueModel getModel()
{
return model;
}
public void updateTarget()
{
updateTarget(model.getValue());
}
protected abstract void updateTarget(T value);
protected void whileIgnoringModelChanges(Runnable r)
{
valueMonitor.whileIgnoringEvents(r);
}
protected Boolean areEqual(T one, T two)
{
return one != null ? one.equals(two) : two == null;
}
private class ModelChangeHandler extends GuardedValueChangeHandler
{
@Override
public void onGuardedValueChanged(ValueChangeEvent event)
{
T value= event.getValue();
updateTarget(value);
}
}
}