package com.connor.bhdz.pdm.partToCapp;

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

import com.connor.bhdz.pdm.drawingToCapp.ProgressReporterDialog;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.util.MessageBox;

public class SendPartToCappHandler extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent arg0) throws ExecutionException {
		AbstractAIFApplication app = AIFUtility.getCurrentApplication();
//		判断选中（多个）对象中是否有非H8_wuliao类型的物料对象
		InterfaceAIFComponent[] components = app.getTargetComponents();
		try {
			if (components != null && components.length > 0) {
				//遍历每一个选中对象
				for (InterfaceAIFComponent component : components) 	{
					TCComponentItem item;
					String componentType = "";
					if (component instanceof TCComponentItemRevision) {
						TCComponentItemRevision rev = (TCComponentItemRevision) component;
						item = rev.getItem();
						componentType = "rev";

					}else if (component instanceof TCComponentItem) {
						item = (TCComponentItem) component;
						componentType = "item";
					}else {
						MessageBox.post("请选择物料对象","提示",MessageBox.INFORMATION);
						return null;
					}
					//判断选中对象是否是H8_drawing
					String typeString = item.getStringProperty("object_type");
					System.out.println("当前选中对象的item类型=="+typeString);

					if (!typeString.equals("H8_wuliao")) {
						MessageBox.post("请选择物料对象","提示",MessageBox.INFORMATION); return null; }

				}
			}
			System.out.println("》》》调用进度弹窗");
			
			
			System.out.println("》》》即将开始下发");
			//全是H8_drawing类型的对象，才能转发给action
			SendPartToCappAction ac = new SendPartToCappAction(app, null, null);
			new Thread(ac).start();
			System.out.println("》》》下发完成，即将关闭进度弹窗");
			
		} catch (TCException e) {
			e.printStackTrace();
		}
		return null;
	}

}
