com.dragome.forms.bindings.client.binding.ValueBindingBuilder 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.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 super T> widget)
{
getCallback().onBindingCreated(new ValueModelToValueTargetBinding(model, widget), widget);
}
public void to(final ParameterisedCommand super T> 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 super T> 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;
}
}