//----------------------------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.panels;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JComboBox;
import javax.swing.JList;

import org.huihoo.god4j.editor.XPDLChoice;
import org.huihoo.god4j.editor.XPDLCollection;
import org.huihoo.god4j.editor.XPDLComplexComponent;
import org.huihoo.god4j.editor.XPDLComponent;
import org.huihoo.god4j.editor.JavaDialog;
import org.huihoo.god4j.editor.elements.set.XPDLFormalParameters;
/**
* Creates a control panel for table panel.
*/
public class JavaActualParametersListControlPanel extends JavaListControlPanel
{
	public JavaActualParametersListControlPanel(XPDLCollection myOwner, String title, boolean isVertical, boolean hasBorder)
	{
		super(myOwner, title, isVertical, hasBorder, true);
		Dimension dim = getPreferredDimension(new String[] { "x" });
		final JavaButton buttonView = new JavaButton("", "ViewFormalParameters", dim);
		buttonView.setToolTipText(sm.getString("ViewFormalParametersKey"));
		add(Box.createRigidArea(new Dimension(0, 10)));
		add(buttonView);
		// action listener for viewing formal params
		buttonView.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				JavaGroupPanel gp = (JavaGroupPanel) getParent().getParent();
				JavaComboxPanel cp = (JavaComboxPanel) gp.getComponent(0);
				JComboBox cb = cp.getComboBox();
				Object sel = cp.getSelectedItem();
				if (!(sel instanceof XPDLComplexComponent))
					return;
				XPDLComplexComponent selected = (XPDLComplexComponent) sel;
				if (selected == null)
					return;
				XPDLComponent fps = selected.get("FormalParameters");
				if (fps == null)
				{ // 'selected' is instance of Application
					Object tmp = selected.get("Choice");
					tmp = ((XPDLChoice) tmp).getChoosen();
					if (tmp instanceof XPDLFormalParameters)
					{
						fps = (XPDLComponent) tmp;
					}
				}
				if (fps != null)
				{
					JavaDialog de = new JavaDialog(getDialog(), selected.toString() + " - " + fps.getLabel());
					de.editXPDLComponent(fps.getJavaPanel(), false, false);
				}
				JList l = ((JavaListPanel) controlledPanel).getList();
				l.requestFocus();
			}
		});
	}
	
	public void applyChanges()
	{
	}
}
