//----------------------------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-----------------------------
/*
 * Created on 2004-12-22
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.huihoo.god4j.editor.elements.atoms;
import java.util.ArrayList;

import org.huihoo.god4j.editor.XPDLComplexChoice;
import org.huihoo.god4j.editor.XPDLComplexComponent;
import org.huihoo.god4j.editor.XPDLComponent;
import org.huihoo.god4j.editor.elements.XPDLExternalReference;
import org.huihoo.god4j.editor.panels.JavaDataTypesPanel;
import org.huihoo.god4j.editor.panels.JavaPanel;

/**
 * @author reic
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class XPDLDataTypes extends XPDLComplexChoice
{
	private XPDLBasicType basicType;
	private XPDLExternalReference externalReference;

	private int choosenIndex = 0;

	public XPDLDataTypes(XPDLComplexComponent parent, int choosenIndex)
	{
		super(parent, "Type", null, 0);
		this.choosenIndex = choosenIndex;
	}

	public void setValue(Object v)
	{
		super.setValue(v);
		if (!(v instanceof XPDLBasicType))
		{
			basicType = null;
		}

		if (!(v instanceof XPDLExternalReference))
		{
			externalReference = null;
		}
	}

	public JavaPanel getJavaPanel()
	{
		return new JavaDataTypesPanel(this, getLabel());
	}

	public Object[] getChoices()
	{
		ArrayList chs = new ArrayList();

		chs.add(basicType);

		if (choosen == null)
		{
			choosen = chs.get(choosenIndex);
		}
		choices = chs.toArray();
		return choices;
	}

	/**
	* Overrides super-class method to retrieve the defined
	* condition.
	*
	* @return The condition of transition.
	*/
	public String toString()
	{
		if (choosen != null)
		{
			return ((XPDLComponent) choosen).toString();
		}
		else
		{
			return "";
		}
	}

	//==================================================================
	public void initComponent()
	{
		//	-----------------------------------------------
		super.initComponent();
		//	-----------------------------------------------	
		basicType = new XPDLBasicType(this);
		basicType.initComponent();
	}

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

	}

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

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

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