//----------------------------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.tree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;

import org.huihoo.god4j.GOD4JFactory;
/**
 * @author reic
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class NodeExplorerSelectionListener implements TreeSelectionListener
{
	private NodeExplorer nodeTree;
	public NodeExplorerSelectionListener(NodeExplorer tree)
	{
		this.nodeTree = tree;
	}
	public void valueChanged(TreeSelectionEvent e)
	{
		//System.err.println("---Enter--NodeTreeSelectionListener#getUpdateCaller() : "+nodeTree.getDesigner().getTriggerSource());
		
		if ((GOD4JFactory.getGOD4J().getEventTrigger() != null))
		{
			GOD4JFactory.getGOD4J().setEventTrigger(null);
			//System.err.println("---Leave--NodeTreeSelectionListener#getUpdateCaller() : "+nodeTree.getDesigner().getTriggerSource());
			return;
		}

		GOD4JFactory.getGOD4J().setEventTrigger(nodeTree);
		//System.err.println("---Leave--NodeTreeSelectionListener#getUpdateCaller() : "+nodeTree.getDesigner().getTriggerSource());
		Object node = nodeTree.getLastSelectedPathComponent();
	
		if(node instanceof ExplorerNode)
		{
			GOD4JFactory.getGOD4J().selectionChanged(null, (ExplorerNode)node, true);
		}
		else
		{
			GOD4JFactory.getGOD4J().selectionChanged(null, null, true);
		}
	}
}
