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

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

There is a newer version: 0.96-beta4
Show newest version
/*
 * Copyright 2009 Andrew Pietsch 
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you 
 * may not use this file except in compliance with the License. You may 
 * obtain a copy of the License at 
 *      
 *      http://www.apache.org/licenses/LICENSE-2.0 
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 * implied. See the License for the specific language governing permissions 
 * and limitations under the License. 
 */

package com.dragome.forms.bindings.client.binding;

import org.w3c.dom.Element;

import com.dragome.forms.bindings.client.command.UiCommand;
import com.dragome.forms.bindings.client.form.metadata.binding.ConditionBinderBuilder;
import com.dragome.forms.bindings.client.form.metadata.binding.MetadataBinder;
import com.dragome.forms.bindings.client.value.MutableValueModel;
import com.dragome.forms.bindings.client.value.ValueModel;
import com.dragome.model.interfaces.HasEnabled;
import com.dragome.model.interfaces.HasVisible;
import com.dragome.model.interfaces.list.ListModel;
import com.dragome.model.interfaces.list.MutableListModel;

/**
 * Base class for binders that provides the common registration and dispose methods.
 */
public class Binder extends AbstractBindingContainer
{
	// moving metadata enable/show methods to here, will eventually move all the Metadata binder
	// functionality from the MetadataBinder to here..
	protected MetadataBinder metadataBinder= new MetadataBinder();

	private BindingBuilderCallback bindingCallback= new BindingBuilderCallback()
	{
		public void onBindingCreated(AbstractBinding binding, Object target)
		{
			registerDisposableAndUpdateTarget(binding);
		}
	};

	public Binder()
	{
		registerDisposable(metadataBinder);
	}

	// Value Model Bindings
	public  ValueBindingBuilder bind(ValueModel field)
	{
		return new ValueBindingBuilder(field, bindingCallback);
	}

	public  MutableValueBindingBuilder bind(MutableValueModel field)
	{
		return new MutableValueBindingBuilder(field, bindingCallback);
	}

	public  ListBindingBuilder bind(ListModel field)
	{
		return new ListBindingBuilder(field, bindingCallback);
	}

	public  MutableListBindingBuilder bind(final MutableListModel field)
	{
		return new MutableListBindingBuilder(field, bindingCallback);
	}

	public  TransitionBindingBuilder onTransitionOf(ValueModel model)
	{
		return new TransitionBindingBuilder(this, model);
	}

	// Metadata Bindings
	public ConditionBinderBuilder show(HasVisible uiObject)
	{
		return metadataBinder.show(uiObject);
	}

	public ConditionBinderBuilder hide(HasVisible uiObject)
	{
		return metadataBinder.hide(uiObject);
	}

	//   public ConditionBinderBuilder show(UIObject uiObject)
	//   {
	//      return metadataBinder.show(uiObject);
	//   }
	//
	//   public ConditionBinderBuilder hide(UIObject uiObject)
	//   {
	//      return metadataBinder.hide(uiObject);
	//   }

	public ConditionBinderBuilder show(Element element)
	{
		return metadataBinder.show(element);
	}

	public ConditionBinderBuilder hide(Element element)
	{
		return metadataBinder.hide(element);
	}

	//   public ConditionBinderBuilder enable(FocusWidget widget)
	//   {
	//      return metadataBinder.enable(widget);
	//   }

	public ConditionBinderBuilder enable(HasEnabled widget)
	{
		return metadataBinder.enable(widget);
	}

	public ConditionBinderBuilder disable(HasEnabled widget)
	{
		return metadataBinder.disable(widget);
	}

	//   public ConditionBinderBuilder disable(FocusWidget widget)
	//   {
	//      return metadataBinder.disable(widget);
	//   }

	// Command and Channel bindings
	public UiCommandBindingBuilder bind(UiCommand uiCommand)
	{
		return new UiCommandBindingBuilder(this, uiCommand);
	}

	//   public  UiCommandChanelBindingBuilder displayResultOf(AsyncUiCommand command)
	//   {
	//      return new UiCommandChanelBindingBuilder(this, command.getResults());
	//   }
	//
	//   public  UiCommandChanelBindingBuilder displayErrorOf(AsyncUiCommand command)
	//   {
	//      return new UiCommandChanelBindingBuilder(this, command.getErrors());
	//   }
	//
	//   public  ChanelBindingBuilder bind(Channel channel)
	//   {
	//      return new ChanelBindingBuilder(this, channel);
	//   }
	//
	//   public UiCommandEventsBindingBuilder bindEventsOf(UiCommand command)
	//   {
	//      return new UiCommandEventsBindingBuilder(this, command);
	//   }
	//
	//   public  UiCommandAsyncEventsBindingBuilder bindEventsOf(AsyncUiCommand command)
	//   {
	//      return new UiCommandAsyncEventsBindingBuilder(this, command);
	//   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy