//----------------------------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.JGraphActivity;
import org.huihoo.god4j.jgraph.JGraphTransition;
import org.huihoo.god4j.jgraph.XPDLJGraph;
import org.jgraph.event.GraphModelEvent;
import org.jgraph.event.GraphModelListener;

/**
 * @author reic
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class XPDLJGraphModelListener  implements GraphModelListener
{
	private XPDLJGraph graph;
	
	public XPDLJGraphModelListener(XPDLJGraph graph)
	{
		this.graph=graph;
	}
	
	public void graphChanged(GraphModelEvent e)
	{
		Object[] cells = graph.getSelectionCells();
		for (int i = 0; cells != null && i < cells.length; i++)
		{
			Object cell = cells[i];
			if (cell != null )
			{
				if((cell instanceof JGraphActivity))
				{
					graph.updateActivityAttributes((JGraphActivity) cell);
				}				
				else if((cell instanceof JGraphTransition))
				{
					graph.updateTransitionAttributes((JGraphTransition) cell);
				}				
			}
			
			GOD4JFactory.getGOD4J().setDirty(true);
		}
	}
}
