package fr.lteconsulting.hexa.databinding.gwt;

import com.google.gwt.user.client.ui.HasValue;

import com.google.gwt.user.client.ui.ListBox;
import fr.lteconsulting.hexa.databinding.Converter;
import fr.lteconsulting.hexa.databinding.Mode;
import fr.lteconsulting.hexa.databinding.propertyadapters.PropertyAdapter;
import fr.lteconsulting.hexa.databinding.propertyadapters.gwt.ListBoxPropertyAdapter;
import fr.lteconsulting.hexa.databinding.propertyadapters.gwt.WidgetPropertyAdapter;

/**
 * Second part of the fluent API for Data Binding. When a binding is
 * prepared by calling a method on the Binder class, an instance of
 * this class is returned to finish the binding creation process.
 * 
 * @author Arnaud Tournier
 * (c) LTE Consulting - 2015
 * http://www.lteconsulting.fr
 *
 */
public class BindingCreation extends fr.lteconsulting.hexa.databinding.BindingCreation
{
	protected boolean fDeferActivate;

	public BindingCreation( PropertyAdapter source )
	{
		super(source);
	}
	
	/**
	 * Final step, defines the data binding destination and activates the
	 * binding.
	 * 
	 * The object used as the binding's destination is a HasValue widget, like a
	 * TextBox. The binding system will the use setValue, getValue and
	 * addValueChangeHandler methods to set, get and get change notifications on
	 * the @param widget parameter.
	 * 
	 * @param widget
	 *            The widget
	 * @return The DataBinding object
	 */
	public DataBinding to( HasValue<?> widget )
	{
		return (DataBinding)to(new WidgetPropertyAdapter(widget));
	}

	/**
	 * Final step, defines the data binding destination and activates the
	 * binding.
	 *
	 * The object used as the binding's destination is a ListBox widget.
	 * The binding system will the use setValue, getValue and addChangeHandler
	 * methods to set, get and get change notifications on the @param widget parameter.
	 *
	 * @param listBox
	 *            The widget
	 * @return The DataBinding object
	 */
	public DataBinding to( ListBox listBox )
	{
		return (DataBinding)to(new ListBoxPropertyAdapter(listBox));
	}
	
	@Override
	public BindingCreation log(String prefix) {
		super.log(prefix);
		return this;
	}

	/**
	 * Second step, parameters.
	 *
	 * The created data binding will be activated at the next event loop. The
	 * Scheduler.get().scheduleDeferred() method will be used.
	 *
	 * @return The Binder to continue specifying the data binding
	 */
	public BindingCreation deferActivate()
	{
		fDeferActivate = true;

		return this;
	}
	
	@Override
	public BindingCreation mode(Mode mode) {
		super.mode(mode);
		return this;
	}
	
	@Override
	public BindingCreation withConverter( Converter converter) {
		super.withConverter(converter);
		return this;
	}

	/**
	 * Final step, defines the data binding destination and activates the
	 * binding
	 *
	 * This method accepts any implementation of PropertyAdapter, especially
	 * user ones so that is a good start to customize the data binding
	 * possibilities
	 *
	 * @param destination
	 *            The destination property adapter
	 * @return The DataBinding object
	 */
	@Override
	public DataBinding to( PropertyAdapter destination )
	{
		// create the binding according to the parameters
		DataBinding binding = new DataBinding( source, destination, mode, converter, logPrefix );

		// activate the binding : launch a value event
		if( fDeferActivate )
			binding.deferActivate();
		else
			binding.activate();

		return binding;
	}
}

@@ -1479,37 +1479,24 @@
 %09%7B%0A%09%09return 
-(DataBinding)
 to(new Widge
@@ -1522,16 +1522,16 @@
 dget));%0A
+
 %09%7D%0A%0A%09/**
@@ -1997,21 +1997,8 @@
 urn 
-(DataBinding)
 to(n
@@ -2692,375 +2692,8 @@
 %09%7D%0A%0A
-%09/**%0A%09 * Final step, defines the data binding destination and activates the%0A%09 * binding%0A%09 *%0A%09 * This method accepts any implementation of PropertyAdapter, especially%0A%09 * user ones so that is a good start to customize the data binding%0A%09 * possibilities%0A%09 *%0A%09 * @param destination%0A%09 *            The destination property adapter%0A%09 * @return The DataBinding object%0A%09 */%0A
 %09@Ov

Remove redundant javadoc and no need to cast here.