package ${entity.getPackage('tapestry.component')};

import org.apache.commons.lang.enum.Enum;
import org.apache.tapestry.BaseComponent;
import org.apache.tapestry.form.IPropertySelectionModel;
import org.asyrinx.brownie.core.lang.UnsupportedClassRuntimeException;
import org.asyrinx.brownie.tapestry.components.form.SimpleEnumPropertySelectionModel;
import org.asyrinx.joey.tapestry.page.DetailView;

import ${entity.getPackage('entity')}.*;
#foreach( $ety in ${entity.getReferenceEntitiesAll()} )
import ${ety.getPackage('service')}.${servicePrefix}${ety.getName()}${serviceSuffix};
#end
#foreach ($importFqn in ${entity.getImports()})
import ${importFqn};
#end

/**
 */
public abstract class ${tapestryComponentDetailPrefix}${entity.getName()}${tapestryComponentDetailSuffix} extends BaseComponent implements DetailView {

	public ${tapestryComponentDetailPrefix}${entity.getName()}${tapestryComponentDetailSuffix}(){
		super();
	}
	
	private ${entity.getName()} target = null;
	
	public ${entity.getName()} getTarget(){
		return this.target;
	}

	public void setTarget(${entity.getName()} target){
		this.target = target;
	}

    public Object getTargetObject() {
        return getTarget();
    }

    public void setTargetObject(Object target) {
        if (target instanceof ${entity.getName()})
            this.setTarget((${entity.getName()}) target);
        else
            throw new UnsupportedClassRuntimeException("Illegal target class '" + target.getClass()
                    + "'. Target must be '" + ${entity.getName()}.class.getName() + "'");
    }

## 
## define enum array
## 
#foreach ( $prop in ${entity.getProperties().toList()} )
#if( ${prop.getEnumType()} )
#set( $enum = ${prop.getEnumType()} )
	public static final IPropertySelectionModel ENUM_${enum.getName().toUpperCase()} =
		new SimpleEnumPropertySelectionModel(
			new Enum[] { 
	#foreach ( $entry in ${enum.toList()} )
				${enum.getName()}.${entry.getName().toUpperCase()}, 
	#end
				});
#end
#end
}
