/*
#=============================================================================
#																			   
#			copyright (c) 2009 Origin Enterprise Solution LTD.		   
#																			   
#=============================================================================
# File name: GetTargetComponent.java
# File description: 										   	
#=============================================================================
#	Date		Name		    Action	Description of Change					   
#	2009-11-23	tianyaling  	创建		得到用户所选的对象					
#	2012-04-06  liqz			修改		“windows目录及文件导入”功能开放可以向伪文件夹中导入数据	   
#=============================================================================
 */
package cn.com.customization.imports.importfiles;

import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.util.MessageBox;

public class GetTargetComponent {

	/**
	 * Creates a new instance of GetTargetComponent.
	 */
	private AbstractAIFUIApplication	app;

	public GetTargetComponent(AbstractAIFUIApplication app) {
		this.app = app;
	}

	/**
	 * getRootComponent:得到用户所选的对象
	 * @param @return 设定文件
	 * @return String 对象类型
	 * @throws
	 * @since CodingExample　Ver 1.1
	 */
	public TCComponentItemRevision getItemRevision() {
		if (app.getTargetComponents() != null) {
			TCComponentItemRevision itemRevision = null;
			TCComponent component = (TCComponent) app.getTargetComponents()[0];
			if (component != null) {
				if (component instanceof TCComponentItemRevision) {
					try {
						itemRevision = (TCComponentItemRevision) component;
						// String name =
						// itemRevision.getProperty("object_name");
					}
					catch (Exception e) {
						e.printStackTrace();
					}
				} else {
					MessageBox.post("请选择一个零组件版本！", "信息提示", MessageBox.INFORMATION);
				}
			}
			return itemRevision;
		} else {
			MessageBox.post("请选择一个零组件版本！", "信息提示", MessageBox.INFORMATION);
			return null;
		}
	}

	public TCComponent getSelectedComponent() {
		if (app.getTargetComponents() != null) {
			TCComponent component = (TCComponent) app.getTargetComponents()[0];
			String strType = component.getType();
			System.out.println("strType = " + strType);
			//Modified by liqz on 20120406 如果选择伪文件夹也可以导入 Begin
//			if ((component != null) && (component instanceof TCComponentFolder) ) {
			if ((component != null) && (component instanceof TCComponentFolder || strType.equals("PseudoFolder")) ) {
			//Modified by liqz on 20120406 如果选择伪文件夹也可以导入 End
				return component;
			} else {
				MessageBox.post("请选择一个文件夹！", "信息提示", MessageBox.INFORMATION);
				return null;
			}
		} else {
			MessageBox.post("请选择一个文件夹！", "信息提示", MessageBox.INFORMATION);
			return null;
		}
	}

}
