package com.connor.jingdiao.handlers;

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

import com.teamcenter.rac.aif.AIFDesktop;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentUser;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;

//标准化审核
public class LoginIPSetHandler extends AbstractHandler implements IHandler{
	
	public Object execute(ExecutionEvent arg0) throws ExecutionException {
		System.out.println("LoginIPSetHandler");
		new Thread() {
			public void run() {
				AIFDesktop desktop = AIFUtility.getActiveDesktop();
				try {
					TCSession session = (TCSession) AIFUtility.getCurrentApplication().getSession();
					TCComponentUser user = session.getUser();
					if(!user.getUserId().equals("infodba")) {
						MessageBox.post(desktop, "禁止操作", "ERROR", MessageBox.ERROR);
						return;
					}
					String[] options = session.getPreferenceService().getStringValues("Jd_TC_Info_Connect");
					if(options == null || options.length < 4) {
						MessageBox.post(desktop, "首选项Jd_TC_Info_Connect配置不正确", "ERROR", MessageBox.ERROR);
						return;
					}
					String option = session.getPreferenceService().getStringValue("Jd6_IP_model");
					if(option == null || option.isEmpty()) {
						MessageBox.post(desktop, "首选项Jd6_IP_model配置不正确", "ERROR", MessageBox.ERROR);
						return;
					}
					TCComponent dataset = session.stringToComponent(option);
					if(dataset==null || !dataset.getType().equals("MSExcelX")) {
						MessageBox.post(desktop, "首选项Jd6_IP_model配置不正确", "ERROR", MessageBox.ERROR);//QiAAAI4S5kSPsC
						return;
					}
					new LoginIPSetDialog(session, dataset, options);
				}catch(Exception e) {
					e.printStackTrace();
					MessageBox.post(desktop, "错误："+e.getMessage(), "ERROR", MessageBox.ERROR);
					return;
				}
			}
		}.start();
		return null;
	}
}
