All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dragome.forms.bindings.client.binding.AbstractValueBinding Maven / Gradle / Ivy

There is a newer version: 0.96-beta4
Show newest version
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);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy