//----------------------------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.jgraph.event;

import org.huihoo.god4j.GOD4JFactory;
import org.huihoo.god4j.jgraph.XPDLJGraph;
import org.jgraph.event.GraphSelectionEvent;
import org.jgraph.event.GraphSelectionListener;
import org.jgraph.graph.DefaultGraphCell;

/**
 * @author reic
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class XPDLJGraphSelectionListener implements GraphSelectionListener
{
	XPDLJGraph graph;
	public XPDLJGraphSelectionListener(XPDLJGraph graph)
	{
		this.graph = graph;
	}
	public void valueChanged(GraphSelectionEvent graphSelectionEvent)
	{
		//System.err.println("---Enter--WorkflowJGraphSelectionListener#getUpdateCaller() : "+GodJFactory.getGoDJ().getEventTrigger());
		if ((GOD4JFactory.getGOD4J().getEventTrigger() != null))
		{
			GOD4JFactory.getGOD4J().setEventTrigger(null);
			//System.err.println("---Leave--WorkflowJGraphSelectionListener#getUpdateCaller() : "+graph.getDesigner().getUpdateCaller());
			return;
		}

		GOD4JFactory.getGOD4J().setEventTrigger(graph);
		//System.err.println("---Leave--WorkflowJGraphSelectionListener#getUpdateCaller() : "+graph.getDesigner().getUpdateCaller());
		
		Object cell = graphSelectionEvent.getCell();
		if(cell instanceof DefaultGraphCell)
		{	
		  GOD4JFactory.getGOD4J().selectionChanged((DefaultGraphCell)cell, null, false);
	  }
	  else
	  {
	    GOD4JFactory.getGOD4J().selectionChanged(null, null, false);
	  }
	}
}