//----------------------------BEGIN LICENSE----------------------------
/* 
 * Willow : the Open Source WorkFlow Project
 * Distributable under GNU LGPL license by gun.org
 *
 * Copyright (C) 2004-2010 huihoo.org 
 * Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com> 
 * 
 * ====================================================================
 * Project Homepage : http://www.huihoo.org/god4j
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : god4j@lists.sourceforge.net 
 */
//----------------------------END  LICENSE-----------------------------
package org.huihoo.god4j.editor;

import org.huihoo.god4j.editor.panels.JavaPanel;
import org.huihoo.workflow.WorkflowComponent;

/**
 * @author reic
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class XPDLCollectionComponent extends XPDLComplexComponent
{
	protected XPDLAttribute attrId     = null;
	protected XPDLCollection container = null;
	
	public XPDLCollectionComponent(XPDLCollection myCollection)
	{
		this(myCollection,null);
	}
	public XPDLCollectionComponent(XPDLCollection myCollection,String name)
	{
		super(myCollection.getParentComponent(),name);
		container=myCollection;
	}

	public String getUUID()
	{
		return attrId.toString();
	}
	
	public XPDLCollection getOwnerCollection()
	{
		return container;
	}
	
	public Object clone()
	{
		XPDLCollectionComponent d = (XPDLCollectionComponent) super.clone();
		d.attrId = (XPDLAttribute) this.attrId.clone();
		
		d.container=this.container;
		
		return d;
	}

	public boolean nameIsUniqueAndValid (JavaPanel p) 
	{
		return true;
	}
	
	//==================================================================
	public void initComponent()
	{
		//	-----------------------------------------------
		super.initComponent();
		//	-----------------------------------------------
		attrId = new XPDLAttribute( this,"Id"); //required
		attrId.initComponent();
		attrId.setRequired(true);
		attrId.setReadOnly(true);
	}

	public void structComponent()
	{
		//	-----------------------------------------------
		super.structComponent();
		//	-----------------------------------------------
		attrId.structComponent();
		
		complexChildren.add(attrId);
		attributes.add(attrId);
	}

	public void loadComponent()
	{
		//	-----------------------------------------------
		super.loadComponent();
		//	-----------------------------------------------
		attrId.loadComponent();
	}

	public void saveComponent()
	{
    if(isReadOnly())
    {
      return;
    }	
    
		//	-----------------------------------------------
		super.saveComponent();
		//	-----------------------------------------------
		attrId.saveComponent();
	}

	public void saveComponent(WorkflowComponent workflow_component)
	{
		//	-----------------------------------------------
		super.saveComponent(workflow_component);
		//	-----------------------------------------------
		attrId.saveComponent(workflow_component);	
	}
	//==================================================================
}