//----------------------------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.elements.atoms;
import org.huihoo.god4j.editor.XPDLAttribute;
import org.huihoo.god4j.editor.XPDLComplexComponent;
import org.huihoo.god4j.editor.panels.JavaPanel;

public class XPDLBasicType extends XPDLComplexComponent
{
	//required
	private XPDLAttribute attrType = null;

	private XPDLDataTypes refDataTypes;
	/**
	* Creates a new instance of the class.
	*/
	public XPDLBasicType(XPDLDataTypes parent)
	{
		super(null, "BasicType");
		refDataTypes = parent;
	}

	/**
	* Returns the value of choosen type. The value is not the
	* text displayed in combo box (this is a language dependent
	* representation of value), but the text defined in WfMC DTD
	* for this element "Type" attribute.
	*
	* @return The value of choosen type.
	*/
	public Object getValue()
	{
		return attrType.getValue();
	}

	public void setValue(Object value)
	{
		attrType.setValue(value);
	}

	/**
	* Prepares the panel with a combo box to choose the one of
	* allowed basic types.
	*
	* @return XPDLPanel to be shown.
	*/
	public JavaPanel getJavaPanel()
	{
		return attrType.getJavaPanel();
	}
	/**
	* Used to create exact copy of instance of this class.
	* The newly created instance will have all the properties
	* same as the copied one.
	*
	* @return The newly created instance of this class.
	*/
	public Object clone()
	{
		XPDLBasicType bt = (XPDLBasicType) super.clone();
		bt.attrType = (XPDLAttribute) this.attrType.clone();
		bt.structComponent();
		return bt;
	}

	public String toString()
	{
		if (labelName != null)
		{
			return labelName;
		}
		return "";
	}
	//==================================================================

	public void initComponent()
	{
		//	-----------------------------------------------
		super.initComponent();
		//	-----------------------------------------------
		//attrType =new XPDLAttribute("Type",this, new String[] { "STRING", "FLOAT", "INTEGER", "REFERENCE", "DATETIME", "BOOLEAN", "PERFORMER" }, 0);
		attrType = new XPDLAttribute(this, "Type", new String[] { "STRING", "FLOAT", "INTEGER", "BOOLEAN" }, 0);
		attrType.initComponent();
		attrType.setLabel(sm.getString("SubTypeKey"));
		attrType.setRequired(true);
	}

	public void structComponent()
	{
		//	-----------------------------------------------
		super.structComponent();
		//	-----------------------------------------------
		attrType.structComponent();

		complexChildren.add(attrType);
		attributes.add(attrType);
	}

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

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

	//==================================================================
}
