package com.connor.jd.erp;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

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.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;

public class erpIntegrationHandler extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent arg0) throws ExecutionException {
		// TODO Auto-generated method stub
		// 获取当前系统活动
		AbstractAIFApplication app = AIFUtility.getCurrentApplication();
		TCSession session = (TCSession) app.getSession();
		// 获取tc当前选择的操作
		InterfaceAIFComponent target = app.getTargetComponent();
		if (target instanceof TCComponentItemRevision) {
			try {
				String[] value = session.getPreferenceService().getStringValues("JD_WLKCCXLX");
				List<String> list = new ArrayList<>(Arrays.asList(value));
				if (list.contains(((TCComponentItemRevision) target).getStringProperty("object_type"))) {
					TCComponentItemRevision f = (TCComponentItemRevision) target;
					erpIntegrationOpertaion operation = new erpIntegrationOpertaion(session, f);
					session.queueOperation(operation);
				} else {
					MessageBox.post("请选择物料执行操作", "提示", MessageBox.INFORMATION);
					return null;
				}
			} catch (TCException e) {
				e.printStackTrace();
			}		
		}
		return null;
	}

}
