//----------------------------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.XPDLComplexComponent;
import org.huihoo.god4j.editor.XPDLSimpleComponent;
import org.huihoo.god4j.editor.panels.JavaMultiLineTextPanel;
import org.huihoo.god4j.editor.panels.JavaPanel;
import org.huihoo.workflow.WorkflowComplexComponent;
import org.huihoo.workflow.WorkflowComponent;
import org.huihoo.workflow.WorkflowSimpleComponent;
/**
* Represents a WfMC DTD element that has the similar name.
*
* @see XPDL
*/
public class XPDLDescription extends XPDLSimpleComponent
{
	public XPDLDescription(XPDLComplexComponent parent)
	{
		super("Description", parent);
	}

	/**
	* Prepares the panel for entering/reading description of
	* some XPDL element. This panel alowes entering of multiple
	* lines of text.
	*
	* @return XPDLPanel to be shown.
	*/
	public JavaPanel getJavaPanel()
	{
		return new JavaMultiLineTextPanel(this);
	}

	//==================================================================
	public void initComponent()
	{
		//	-----------------------------------------------
		super.initComponent();
		//	-----------------------------------------------	
	}

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

	public void loadComponent()
	{
		//	-----------------------------------------------
		super.loadComponent();
		//	-----------------------------------------------
		XPDLComplexComponent parent_component = getParentComponent();
		if (parent_component != null)
		{
			WorkflowComponent workflow_component = parent_component.getWorkflowComponent();

			if (workflow_component != null && (workflow_component instanceof WorkflowSimpleComponent))
			{
				WorkflowSimpleComponent simple_component = (WorkflowSimpleComponent) workflow_component;
				setValue(simple_component.getDescription());
			}
		}
	}

	public void saveComponent()
	{
    if(isReadOnly())
    {
      return;
    }
    
		//	-----------------------------------------------
		super.saveComponent();
		//	-----------------------------------------------		
		XPDLComplexComponent parent_component = getParentComponent();
		if (parent_component != null)
		{
			WorkflowComponent workflow_component = parent_component.getWorkflowComponent();

			if (workflow_component != null && (workflow_component instanceof WorkflowSimpleComponent))
			{
				WorkflowSimpleComponent simple_component = (WorkflowSimpleComponent) workflow_component;
				simple_component.setDescription(this.toString());
			}
		}
	}

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

		if (workflow_component != null && (workflow_component instanceof WorkflowComplexComponent))
		{
			((WorkflowComplexComponent) workflow_component).setDescription(this.toString());
		}
	}
	//==================================================================
}
