/*
#=============================================================================
#																			   
#			opyright (c) 2009 Origin Enterprise Solution LTD.		   
#																			   
#=============================================================================
# File name: SubmitAttachmentInWorkflowCommand.java
# File description: 										   	
#=============================================================================
#	Date		Name		Action	Description of Change					   
#								   
#=============================================================================
*/
package cust.com.rac.workflow;

import cn.com.customization.imports.importfiles.ImportFile;

import com.teamcenter.rac.aif.AbstractAIFCommand;
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentPseudoFolder;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.util.MessageBox;

/**
 * @author 
 */
public class SubmitAttachmentInWorkflowCommand extends AbstractAIFCommand {

	public AbstractAIFUIApplication	application;
	private TCComponent theTargetComp= null;
	private TCComponent parentComp = null;
	
	public SubmitAttachmentInWorkflowCommand(AbstractAIFUIApplication abstractaifapplication) throws TCException {
		application = abstractaifapplication;
		execute();
	}

	private void execute() throws TCException {
		InterfaceAIFComponent aifComp = application.getTargetComponent();
		if(!(aifComp instanceof TCComponentPseudoFolder)){
			MessageBox.post("请选择流程中item Revision下的关系文件夹执行操作！", "警告", MessageBox.WARNING);
			return;
		}
		
		TCComponent target = (TCComponent) aifComp;
		AIFComponentContext[] context = target.whereReferenced();
		for(int i = 0; context != null && i < context.length ;i++ ){
			parentComp = (TCComponent) context[i].getComponent(); 
			if(parentComp instanceof TCComponentItemRevision){
				String strJobName = parentComp.getProperty("current_job");
				System.out.println("strJobName = " + strJobName);
				if(!strJobName.equals("") && !strJobName.equals("没有值")){
					theTargetComp = (TCComponent) aifComp;
					break;
				}
			}
		}
		if(theTargetComp == null){
			MessageBox.post("请选择流程中item Revision下的关系文件夹执行操作！", "警告", MessageBox.WARNING);
			return;
		}
		new Thread() {
			public void run() {
				new ImportFile(application,new TCComponent[]{parentComp,theTargetComp});
			}
		}.start();
		
		
	}
}
