package cust.com.rac.changename;

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

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

/**
 * Our sample handler extends AbstractHandler, an IHandler base class.
 * @see org.eclipse.core.commands.IHandler
 * @see org.eclipse.core.commands.AbstractHandler
 */
public class ChangeNameHandler extends AbstractHandler {
	/**
	 * The constructor.
	 */
	public ChangeNameHandler() {
	}

	/**
	 * the command has been executed, so extract extract the needed information
	 * from the application context.
	 */
	public Object execute(ExecutionEvent event) throws ExecutionException {
		TCSession session=(TCSession) AIFUtility.getCurrentApplication().getSession();
		TCComponent inter=(TCComponent) AIFUtility.getCurrentApplication().getTargetComponent();
		try {
			TCComponentUser user=session.getUser();
			String userTarget=inter.getProperty("owning_user");
			boolean flag1=false;
			System.out.println("=====userTarget==========="+userTarget);
			System.out.println("======user.toString()=========="+user.toString());
			if(userTarget.equals(user.toString())){
				flag1=true;
			}
			boolean flag=session.getCurrentGroup().isDBA();
			if(flag||flag1){
				ChangeNameAction action=new ChangeNameAction(AIFUtility.getCurrentApplication(),"");
				new Thread(action).start();
			}else{
				MessageBox.post("您不是对象的所有者，无权更改。如需更改请与管理员联系!", "提示！", 2);
				return null;
			}
			
		} catch (TCException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}

