//----------------------------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/willow
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : willow@lists.sourceforge.net 
 */
//----------------------------END  LICENSE----------------------------
package org.huihoo.god4j.actions;

import java.awt.event.ActionEvent;

import org.huihoo.god4j.GOD4JFactory;
import org.huihoo.god4j.util.UUID;
import org.huihoo.workflow.impl.xpdl.WorkflowPackageHeaderImpl;
import org.huihoo.workflow.impl.xpdl.WorkflowPackageImpl;
import org.huihoo.workflow.impl.xpdl.WorkflowProcessHeaderImpl;
import org.huihoo.workflow.impl.xpdl.WorkflowProcessImpl;
import org.huihoo.workflow.xpdl.ExtendedAttribute;
import org.huihoo.workflow.xpdl.WorkflowPackage;
import org.huihoo.workflow.xpdl.WorkflowPackageHeader;
import org.huihoo.workflow.xpdl.WorkflowProcess;
import org.huihoo.workflow.xpdl.WorkflowProcessHeader;
import org.huihoo.workflow.xpdl.XPDLGlobals;

/**
 * @author liangce
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class New extends ActionBase
{

	public New()
	{
		super();
		setEnabled(true);
	}

	public void actionPerformed(ActionEvent e)
	{
		if(Close.closeDocumentIfPossible())
		{
			newDocumentIfPossible();
		}
	}
	
	public static boolean newDocumentIfPossible()
	{
		WorkflowPackageHeader header = new WorkflowPackageHeaderImpl();
		WorkflowPackage default_pkg = new WorkflowPackageImpl(UUID.generate(), sm_jgraph.getString("jgraph.packageLabel"));

		WorkflowProcessHeader procheader = new WorkflowProcessHeaderImpl();
		WorkflowProcess wflProc = new WorkflowProcessImpl(UUID.generate(), sm_jgraph.getString("jgraph.processLabel"));
		wflProc.setWorkflowPackage(default_pkg);

		default_pkg.getWorkflowProcesses().add(wflProc);
		default_pkg.addExtendedAttribute(new ExtendedAttribute(XPDLGlobals.ID_PROCESS_MAIN, wflProc.getUUID()));

		GOD4JFactory.getGOD4J().loadDocument(default_pkg);
		GOD4JFactory.getGOD4J().setDirty(true);
		
		return true;
	}
}
