package cn.net.connor.std.processedit.commands;

import java.util.ArrayList;
import java.util.List;

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

import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentBOMWindowType;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;

import cn.net.connor.std.aifrcp.util.KUtil;

public class CreateBOMViewHandler extends AbstractHandler {

//	@Override
//	public Object execute(ExecutionEvent arg0) throws ExecutionException {
//		// TODO Auto-generated method stub
//		AbstractAIFApplication app = AIFUtility.getCurrentApplication();
//		TCSession session = (TCSession) app.getSession();
//		InterfaceAIFComponent targetComponent = app.getTargetComponent();
//		if(targetComponent instanceof TCComponentBOMLine) {
//			TCComponentBOMLine bomLine = (TCComponentBOMLine)targetComponent;
//			try {
//				TCComponentItemRevision revision = (TCComponentItemRevision)bomLine.getRelatedComponent("bl_line_object");
//				TCComponent[] reference = revision.getReferenceListProperty("structure_revisions");
//				if(reference != null && reference.length > 0) {
//					MessageBox.post("该物料已有BOM,不能重复创建!",
//							"提示",MessageBox.INFORMATION);
//					return null;
//				}else {
//					KUtil.setByPassItk(session, true);
//					TCComponentItemType t = (TCComponentItemType) session.getTypeService().getTypeComponent("Item");
//					TCComponentItem item1 = t.findItems("000001")[0];
//					TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
//					TCComponentBOMWindow window = bomWinType.create(null);
//					TCComponentBOMLine newBom = window.setWindowTopLine(null, revision, null, null);
//					TCComponentBOMLine newnewLine = newBom.add(item1, item1.getLatestItemRevision(), null, false);
//					window.save();
//					newnewLine.cut();
//					window.save();
//					window.close();
//					KUtil.setByPassItk(session, false);
//					MessageBox.post("创建成功!", "", MessageBox.INFORMATION);
//				}
//			} catch (TCException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}else {
//			MessageBox.post("请选择BOMLine对象!", "提示", MessageBox.INFORMATION);
//			
//		}
//		return null;
//	}

	
	
	@SuppressWarnings("unused")
	@Override
	public Object execute(ExecutionEvent arg0) throws ExecutionException {
		// TODO Auto-generated method stub
		AbstractAIFApplication app = AIFUtility.getCurrentApplication();
		TCSession session = (TCSession) app.getSession();
		InterfaceAIFComponent targetComponent = app.getTargetComponent();
		if(targetComponent instanceof TCComponentBOMLine) {
			
			TCComponentBOMLine bomLine = (TCComponentBOMLine)targetComponent;

			G4MDialog classDialog = new G4MDialog("精雕分类", null, session,bomLine);
			new Thread(classDialog).start();
			

			
		
		}else {
			MessageBox.post("请选择BOMLine对象!", "提示", MessageBox.INFORMATION);
			
		}
		return null;
	}
}
