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

org.robobinding.viewattribute.grouped.GroupedViewAttributeBinderFactory Maven / Gradle / Ivy

The newest version!
package org.robobinding.viewattribute.grouped;

import java.util.Map;

import org.robobinding.attribute.PendingGroupAttributes;
import org.robobinding.attribute.ResolvedGroupAttributes;

/**
 * @since 1.0
 * @author Cheng Wei
 *
 */
public class GroupedViewAttributeBinderFactory {
	private final GroupedViewAttributeFactory factory;
	private final GroupAttributesResolver groupAttributesResolver;
	private final ViewAttributeBinderFactory viewAttributeBinderFactory;
	
	@SuppressWarnings("unchecked")
	public GroupedViewAttributeBinderFactory(GroupedViewAttributeFactory factory, 
			GroupAttributesResolver groupAttributesResolver,
			ViewAttributeBinderFactory viewAttributeBinderFactory) {
		this.factory = (GroupedViewAttributeFactory)factory;
		this.groupAttributesResolver = groupAttributesResolver;
		this.viewAttributeBinderFactory = viewAttributeBinderFactory;
	}

	public GroupedViewAttributeBinder create(Object view, Map presentAttributeMappings) {
		PendingGroupAttributes pendingGroupAttributes = new PendingGroupAttributes(presentAttributeMappings);
		GroupedViewAttribute viewAttribute = factory.create();
		ResolvedGroupAttributes resolvedGroupAttributes = groupAttributesResolver.resolve(pendingGroupAttributes, viewAttribute);
		ChildViewAttributesBuilderImpl childViewAttributesBuilder = new ChildViewAttributesBuilderImpl(
				resolvedGroupAttributes, viewAttributeBinderFactory);

		return new GroupedViewAttributeBinder(view, viewAttribute, childViewAttributesBuilder);

	}
}