package cust.com.rac.integration;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCPreferenceService;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;

public class AccepComHandler extends AbstractHandler{

	private TCSession tcsession  = null;
	
	public Object execute(ExecutionEvent arg0) throws ExecutionException {
		// TODO Auto-generated method stub
		final AbstractAIFUIApplication app = AIFUtility.getCurrentApplication();
		InterfaceAIFComponent aifComponent = app.getTargetComponent();
		tcsession = (TCSession) app.getSession();
		
		if(aifComponent == null){
			MessageBox.post("请选择验收委托单版本对象！", "消息提示", MessageBox.INFORMATION);
			return null;
		}
		
		if( aifComponent instanceof TCComponentItemRevision){
			TCComponentItemRevision AccepComRevision = (TCComponentItemRevision)aifComponent;
			String itemRevType = AccepComRevision.getType();
			if(itemRevType.equals("YSR8_AccepComRevision")){
				String url = tcsession.getPreferenceService().getString(TCPreferenceService.TC_preference_site, "Cust_PLM_To_BPM_URL");
				String msg = InterationOperation.sendAccepComToBPM(AccepComRevision, url);
				MessageBox.post(msg, "消息提示", MessageBox.INFORMATION);
			}else{
				MessageBox.post("您选择的不是验收委托单，请选择正确的文件！", "消息提示", MessageBox.INFORMATION);
				return null;
			}
		}else{
			MessageBox.post("请选择验收委托单版本对象！", "消息提示", MessageBox.INFORMATION);
			return null;
		}
		return null;
	}

}
