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

import javax.swing.JOptionPane;
import javax.swing.TransferHandler;

import org.huihoo.god4j.GOD4JFactory;
import org.huihoo.god4j.JGraphFrame;
import org.huihoo.god4j.jgraph.BusinessActivity;
import org.huihoo.god4j.jgraph.XPDLJGraph;
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 Cut extends ActionBase
{
	
	public Cut()
	{
		super();
		setEnabled(false);
	}
	
	public void actionPerformed(ActionEvent event)
	{
		JGraphFrame frame = GOD4JFactory.getGOD4J().getControlPanel().getSelectedJGraph();
		if (frame == null)
		{
			return;
		}

		XPDLJGraph graph=frame.getJGraph();
		
		DefaultGraphCell cell = (DefaultGraphCell) graph.getSelectionCell();
		if (cell == null)
		{
			return;
		}
		
		if (!(cell instanceof BusinessActivity))
		{
			JOptionPane.showMessageDialog(
				GOD4JFactory.getGOD4J(),
				sm_jgraph.getString("joptionpane.warnCannotCutElement"),
				sm_jgraph.getString("joptionpane.warn"),
				JOptionPane.WARNING_MESSAGE);
			return;
		}	
		
		TransferHandler.getCutAction().actionPerformed(new ActionEvent(graph, event.getID(), event.getActionCommand()));
			
		GOD4JFactory.getGOD4J().getActionMap().getAction("paste").setEnabled(true);
		GOD4JFactory.getGOD4J().getActionMap().getAction("pasteAt").setEnabled(true);
		GOD4JFactory.getGOD4J().setDirty(true);
	}
}