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

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

The newest version!
package com.dragome.forms.bindings.client.binding;

import com.dragome.forms.bindings.client.channel.Destination;
import com.dragome.forms.bindings.client.command.ParameterisedCommand;
import com.dragome.forms.bindings.client.value.ValueModel;
import com.dragome.forms.bindings.client.value.ValueTarget;
import com.dragome.forms.bindings.extra.user.client.ui.HasHTML;
import com.dragome.forms.bindings.extra.user.client.ui.HasText;

/**
 * Created by IntelliJ IDEA.
 * User: andrew
 * Date: May 22, 2010
 * Time: 11:25:33 AM
 * To change this template use File | Settings | File Templates.
 */
public class ValueBindingBuilder
{
	private BindingBuilderCallback callback;
	private ValueModel model;

	public ValueBindingBuilder(ValueModel model, BindingBuilderCallback callback)
	{
		this.callback= callback;
		this.model= model;
	}

	protected ValueModel getModel()
	{
		return model;
	}

	public void to(ValueTarget widget)
	{
		getCallback().onBindingCreated(new ValueModelToValueTargetBinding(model, widget), widget);
	}

	public void to(final ParameterisedCommand command)
	{
		AbstractBinding binding= new ValueModelToValueTargetBinding(model, new ValueTarget()
		{
			public void setValue(T value)
			{
				command.execute(value);
			}
		});
		getCallback().onBindingCreated(binding, command);
	}

	public void to(final Destination destination)
	{
		AbstractBinding binding= new ValueModelToValueTargetBinding(model, new ValueTarget()
		{
			public void setValue(T value)
			{
				destination.receive(value);
			}
		});
		getCallback().onBindingCreated(binding, destination);
	}

	/**
	 * @deprecated User {@link #toTextOf(com.google.gwt.user.client.ui.HasText)} instead.
	 * @param target the binding target.
	 * @return a builder to optionally configure the format.
	 */
	@Deprecated
	public DisplayFormatBuilder toLabel(HasText target)
	{
		return toTextOf(target);
	}

	/**
	 * Binds the value model to the specified {@link HasText} target.
	 * @param target the binding target.
	 * @return a builder to optionally configure the format.
	 */
	public DisplayFormatBuilder toTextOf(HasText target)
	{
		ValueModelToHasTextBinding binding= new ValueModelToHasTextBinding(model, target);
		getCallback().onBindingCreated(binding, target);
		return new DisplayFormatBuilder(binding);
	}

	/**
	 * Binds the value model to the specified {@link HasHTML} target.
	 * @param target the binding target.
	 * @return a builder to optionally configure the format.
	 */
	public DisplayFormatBuilder toHtmlOf(HasHTML target)
	{
		ValueModelToHasHtmlBinding binding= new ValueModelToHasHtmlBinding(model, target);
		getCallback().onBindingCreated(binding, target);
		return new DisplayFormatBuilder(binding);
	}

	protected BindingBuilderCallback getCallback()
	{
		return callback;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy