/**
 * @author tyl
 * @Action  ini
 * 2011-4-4
 */
package cn.com.origin.autocode.newitem.generatcode;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import javax.swing.JDialog;
import javax.xml.bind.JAXBException;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;

import cn.com.origin.autocode.jfom.util.JFomBZJBean;
import cn.com.origin.autocode.jfom.util.JFomBean;
import cn.com.origin.autocode.jfom.util.JFomLovBean;
import cn.com.origin.autocode.jfom.util.JFomMethodUtil;
import cn.com.origin.autocode.jfom.util.JFomUtil;
import cn.com.origin.autocode.newitem.origin.ORAfterNewItemCustomization;
import cn.com.origin.autocode.newitem.origin.ORCreateICOObject;
import cn.com.origin.autocode.newitem.origin.ORSaveObjectDescOperation;
import cn.com.origin.autocode.newitem.system.ORItemInfoPanel;
import cn.com.origin.autocode.newitem.system.ORNewItemDialog;
import cn.com.origin.autocode.saveas.ORSaveItemAsDialog;
import cn.com.origin.autocode.views.itemtypeview.NewItemClassificationView;
import cn.com.origin.autocode.xmlutil.CNCompontent;
import cn.com.origin.autocode.xmlutil.CNPart;
import cn.com.origin.autocode.xmlutil.CNPartList;
import cn.com.origin.autocode.xmlutil.CNProperty;
import cn.com.origin.autocode.xmlutil.CNXmlUtil;
import cn.com.origin.autocodemanager.common.AutoCodeManagerPropertyName;
import cn.com.origin.autocodemanager.common.CreateCompositeUtil;
import cn.com.origin.autocodemanager.common.PackCodeDescInfos;
import cn.com.origin.autocodemanager.common.TCLOVUtil;
import cn.com.origin.autocodemanager.common.TCPreferenceUitl;
import cn.com.origin.autocodemanager.common.TCQueryUtil;
import cn.com.origin.autocodemanager.common.operations.GetCodeNumber;
import cn.com.origin.autocodemanager.common.operations.PackCodeNodeInfo;
import cn.com.origin.autocodemanager.common.operations.TreeAndListCodeOperation;
import cn.com.origin.autocodemanager.common.tree.AbstractTreeData;
import cn.com.origin.autocodemanager.common.tree.TreeViewOperation;
import cn.com.origin.autocodemanager.views.listcodeview.NewItemListCodeView;
import cn.com.origin.autocodemanager.views.treecodeview.NewItemTreeCodeView;

import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.ListOfValuesInfo;
import com.teamcenter.rac.kernel.SoaUtil;
import com.teamcenter.rac.kernel.TCAccessControlService;
import com.teamcenter.rac.kernel.TCClassificationService;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentFormType;
import com.teamcenter.rac.kernel.TCComponentGroup;
import com.teamcenter.rac.kernel.TCComponentICO;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemRevisionType;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCComponentListOfValues;
import com.teamcenter.rac.kernel.TCComponentListOfValuesType;
import com.teamcenter.rac.kernel.TCComponentPseudoFolder;
import com.teamcenter.rac.kernel.TCComponentRole;
import com.teamcenter.rac.kernel.TCComponentUser;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCExceptionPartial;
import com.teamcenter.rac.kernel.TCPreferenceService;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.kernel.ics.ICSAdminClass;
import com.teamcenter.rac.kernel.ics.ICSAdminClassAttribute;
import com.teamcenter.rac.kernel.ics.ICSApplicationObject;
import com.teamcenter.rac.kernel.ics.ICSProperty;
import com.teamcenter.rac.kernel.ics.ICSPropertyDescription;
import com.teamcenter.rac.kernel.ics.ICSSearchResult;
import com.teamcenter.rac.kernel.ics.ICSView;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException;
import com.teamcenter.services.rac.core.DataManagementService;
import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateInput;
import com.teamcenter.soa.client.model.LovValue;

public class NewCodeItemDialog extends Dialog {
	private Table propTable;
	private Table formTable;
	private List<JFomBean> propBeanList;
	private JFomBean propBean;
	private Hashtable<TableItem, TableItemControls> formTablecontrols = new Hashtable<TableItem, TableItemControls>();
	// 
	private Hashtable<TableItem, TableItemControls> tablecontrols = new Hashtable<TableItem, TableItemControls>();
	// 表单类型中英文对照
	private HashMap<String, String> propMapping = new HashMap<String, String>();
	// 表单属性
	private HashMap<String, JFomBZJBean> formPropBean = new HashMap<String, JFomBZJBean>();
	private String bzjFLFormType = "";
	private JFomBZJBean formBean;
	private HashMap<Integer, JFomLovBean> lovBeanList = new HashMap<Integer, JFomLovBean>();
	private HashMap<Integer, JFomLovBean> formLovBeanList = new HashMap<Integer, JFomLovBean>();
	
	// 
	private SashForm sashFormCodeView;
	private CTabItem codeTreeCTab;
	private CTabItem codeListCTab;
	private Composite compositCodeTree;
	private Composite compositCodeList;
	private CTabFolder ctabFolder;
	private Text idLengthText;
	private Text DescText;
	private Text idText;
	private Text revText;
	private Text nameText;
	private Combo unitCombo;
	private NewItemClassificationView classificationView;
	private NewItemListCodeView listView;
	private NewItemTreeCodeView treeView;
	private TreeViewer classificationTreeViewer;
	private TreeViewOperation treeViewOperation;
	public TreeAndListCodeOperation treeAndListCodeOperation;
	private TCSession session;
	private TCComponentItemType tccomponentitemtype;
	private AbstractTreeData selectedSegmentNode = null;
	private TCComponent selectedSegmentTCComponent = null;
	private AbstractTreeData icoTreeData;
	private String pattern = "";
	private String codeDesc = "";
	private String codeStyle = "";
	private String newSeq = "";
	private String counterID = "";
	private String newID = "";
	private String finalPattern = "";
	private String idPattern = "";
	//20170510 class id
	private String codeRemark = "";

	private int codeLength;
	private Map<String, String> icoPropertyMap;
	private String firstListICOName = "";
	private String codeCounterName = "";
	private Map<AbstractTreeData, String> segmentItemType;
	private TCComponent newComp;
	private String showItemType = "";
	private Boolean isTypeFilter = false;
	private String origin_isNewItemMustLastNode = "origin_isNewItemMustLastNode";
	private String origin_idNeddExamineAndApproveTypes = "origin_idNeddExamineAndApproveTypes";
	private String origin_sendToClassification_excludeType = "origin_sendToClassification_excludeType";
	private String origin_sendToPreviousTreeNode = "origin_sendToPreviousTreeNode";
	private String origin_sendToClassification_Automatic = "origin_sendToClassification_Automatic";
	private String origin_isCodePatternCanEditTypes = "origin_isCodePatternCanEditTypes";
	private String unitLOVName = "Unit of Measures";
	private String origin_newItem_isShowUnit = "origin_newItem_isShowUnit";
	private String origin_showUnit_excludeTypes = "origin_showUnit_excludeTypes";
	private JDialog newItemDialog;
	private ORItemInfoPanel orNewItemInfoPanel;
	private TCComponent[] units = null;
	private String origin_isItemNameTextDefaultNull = "origin_isItemNameTextDefaultNull";
	private PackCodeDescInfos packCodeDescInfos = null;
	private SashForm container;
	private SashForm itemInfoComposite;
	private SashForm sashFormClassfication;
	private String origin_isMustSelecteUnit = "origin_isMustSelecteUnit";
	private String origin_searchGenerateID = "origin_searchGenerateID";
	private String origin_isNotSaveNewItemToPseudoFolder = "origin_isNotSaveNewItemToPseudoFolder";
	private String origin_isShowPCUnitLast = "origin_isShowPCUnitLast";
	private String origin_newCodeSequenceNumber = "origin_newCodeSequenceNumber";
	private String origin_sequenceExcludeFirstPatternTypes = "origin_sequenceExcludeFirstPatternTypes";
	private String connor_isCanCreateTempMaterial = "connor_isCanCreateTempMaterial";

	private Composite cpxCompsite;
	private Label cpxLabel;
	private Text cpxText;
	private Label nfLabel;
	private Text nfText;
	private Label cpxLabel2;
	private Combo cpxText2;
	
	private final String CPX = "CPDM";
	private final String NF = "NF";
	private final String CPX2 = "CP";
	private final String JY_CPX_Option = "JY_CPX_Option";
	private  HashMap<String, String> jyCPXMap;
	
	// 2017.05.10
	private Button isCreateTempItemButton = null;
	private Boolean isCreateTempItem = false;
	
	// 2017.06.02
	//private List<>
	private Composite objPropComposite;
	private Composite classPropComposite;
	private static TCClassificationService classService;
	private static ICSAdminClass adminClass;
	
	// 2017.06.26
	private String LPBIGString;
	private String LPSString;
	
	//2017.07.02
	private CNPartList cnPartList;
	private CNPart currentCNPart;
	private List<CNProperty> cnpropList; 
	
	public Text getIdLengthText() {
		return idLengthText;
	}

	public void setIdLengthText(Text idLengthText) {
		this.idLengthText = idLengthText;
	}

	public Combo getUnitCombo() {
		return unitCombo;
	}

	public void setUnitCombo(Combo unitCombo) {
		this.unitCombo = unitCombo;
	}

	public Text getDescText() {
		return DescText;
	}

	public void setDescText(Text descText) {
		DescText = descText;
	}

	public Text getIdText() {
		return idText;
	}

	public void setIdText(Text idText) {
		this.idText = idText;
	}

	public Text getRevText() {
		return revText;
	}

	public void setRevText(Text revText) {
		this.revText = revText;
	}

	public Text getNameText() {
		return nameText;
	}

	public void setNameText(Text nameText) {
		this.nameText = nameText;
	}

	public TCComponent getNewComp() {
		return newComp;
	}

	public void setNewComp(TCComponent newComp) {
		this.newComp = newComp;
	}

	public NewCodeItemDialog(Shell parentShell) {
		super(parentShell);
		treeViewOperation = new TreeViewOperation();
		treeAndListCodeOperation = new TreeAndListCodeOperation();
		session = (TCSession) AIFUtility.getCurrentApplication().getSession();
		segmentItemType = new HashMap<AbstractTreeData, String>();
		try {
			tccomponentitemtype = (TCComponentItemType) (session
					.getTypeComponent("Item"));
		} catch (TCException e) {
			e.printStackTrace();
		}
	}

	public NewCodeItemDialog(Shell parentShell, String showItemType) {
		super(parentShell);
		treeViewOperation = new TreeViewOperation();
		this.showItemType = showItemType.trim();
		treeAndListCodeOperation = new TreeAndListCodeOperation();
		session = (TCSession) AIFUtility.getCurrentApplication().getSession();
		segmentItemType = new HashMap<AbstractTreeData, String>();
		try {
			tccomponentitemtype = (TCComponentItemType) (session
					.getTypeComponent("Item"));
		} catch (TCException e) {
			e.printStackTrace();
		}
	}
	
	public NewCodeItemDialog(Shell parentShell, String showItemType,Boolean isFilterType) {
		super(parentShell);
		treeViewOperation = new TreeViewOperation();
		this.showItemType = showItemType.trim();
		this.isTypeFilter = isFilterType;
		treeAndListCodeOperation = new TreeAndListCodeOperation();
		session = (TCSession) AIFUtility.getCurrentApplication().getSession();
		segmentItemType = new HashMap<AbstractTreeData, String>();
		try {
			tccomponentitemtype = (TCComponentItemType) (session
					.getTypeComponent("Item"));
		} catch (TCException e) {
			e.printStackTrace();
		}
	}

	public NewCodeItemDialog(JDialog newItemDialog, Shell parentShell,
			String showItemType) {
		super(parentShell);
		this.newItemDialog = newItemDialog;
		treeViewOperation = new TreeViewOperation();
		this.showItemType = showItemType.trim();
		treeAndListCodeOperation = new TreeAndListCodeOperation();
		session = (TCSession) AIFUtility.getCurrentApplication().getSession();
		segmentItemType = new HashMap<AbstractTreeData, String>();
		try {
			tccomponentitemtype = (TCComponentItemType) (session
					.getTypeComponent("Item"));
		} catch (TCException e) {
			e.printStackTrace();
		}
	}

	public NewCodeItemDialog(Shell parentShell, String showItemType,
			PackCodeDescInfos packCodeDescInfos) {
		super(parentShell);
		treeViewOperation = new TreeViewOperation();
		this.showItemType = showItemType.trim();
		treeAndListCodeOperation = new TreeAndListCodeOperation();
		session = (TCSession) AIFUtility.getCurrentApplication().getSession();
		segmentItemType = new HashMap<AbstractTreeData, String>();
		this.packCodeDescInfos = packCodeDescInfos;
		try {
			tccomponentitemtype = (TCComponentItemType) (session
					.getTypeComponent("Item"));
		} catch (TCException e) {
			e.printStackTrace();
		}
	}

	public NewCodeItemDialog(ORItemInfoPanel newItemInfoPanel,
			Shell parentShell, String showItemType) {
		super(parentShell);
		this.orNewItemInfoPanel = newItemInfoPanel;
		treeViewOperation = new TreeViewOperation();
		this.showItemType = showItemType.trim();
		treeAndListCodeOperation = new TreeAndListCodeOperation();
		session = (TCSession) AIFUtility.getCurrentApplication().getSession();
		segmentItemType = new HashMap<AbstractTreeData, String>();
		try {
			tccomponentitemtype = (TCComponentItemType) (session
					.getTypeComponent("Item"));
		} catch (TCException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 添加物料属性页面
	 * 添加分类熟悉页面
	 * @param parent
	 */
	public void createClassTablePannel(Composite parent1){
		
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 2;
		GridData gridData1 = new GridData();
		gridData1.heightHint = 240;
		gridData1.horizontalAlignment = GridData.FILL;
		gridData1.verticalAlignment = GridData.CENTER;
		gridData1.grabExcessHorizontalSpace = true;

		CTabFolder ctabFolder = new CTabFolder(parent1, SWT.BORDER);
		ctabFolder.setBorderVisible(true);
		ctabFolder.setSimple(false);
		ctabFolder.setLayoutData(gridData1);
		CTabItem objPropTab = new CTabItem(ctabFolder, SWT.NONE);
		objPropTab.setText("对象属性");
		Composite objectCompsite = new Composite(ctabFolder, SWT.BORDER);
		objectCompsite.setLayout(new FillLayout());
		final ScrolledComposite objectSrolledComposite = new ScrolledComposite(objectCompsite,  SWT.V_SCROLL);
		objPropComposite = new Composite(objectSrolledComposite, SWT.NONE);
		objPropComposite.setLayout(gridLayout);
		objectSrolledComposite.setContent(objPropComposite);//设置受控面板
		objectSrolledComposite.setExpandHorizontal(true);
		objectSrolledComposite.setExpandVertical(true);
		objectSrolledComposite.addControlListener(
			new ControlAdapter() {
				public void controlResized(ControlEvent e) {
					Point r = objPropComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
					objectSrolledComposite.setMinSize(objectSrolledComposite.computeSize(r.x, r.y));
				}
			}
		);
		objPropTab.setControl(objectCompsite);
		ctabFolder.setSelection(0);
		//
		CTabItem classPropTab = new CTabItem(ctabFolder, SWT.NONE);
		classPropTab.setText("分类属性");
		Composite classCompsite = new Composite(ctabFolder, SWT.BORDER);
		classCompsite.setLayout(new FillLayout());
		final ScrolledComposite classSrolledComposite = new ScrolledComposite(classCompsite,  SWT.V_SCROLL);
		classPropComposite = new Composite(classSrolledComposite, SWT.NONE);//ctabFolder
		classPropComposite.setLayout(gridLayout);
		classSrolledComposite.setContent(classPropComposite);//设置受控面板
		classSrolledComposite.setExpandHorizontal(true);
		classSrolledComposite.setExpandVertical(true);
		classSrolledComposite.addControlListener(
			new ControlAdapter() {
				public void controlResized(ControlEvent e) {
					Point r = classPropComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
					classSrolledComposite.setMinSize(classSrolledComposite.computeSize(r.x, r.y));
				}
			}
		);
		classPropTab.setControl(classCompsite);
		
	}
	
	public List<Label> classLabelList = new ArrayList<>();
	public List<Widget> classTextList = new ArrayList<>();
	public List<CNClassPropBean> classPropList = new ArrayList<>();
	/**
	 * 绘制分类属性界面
	 */
	public void addClassPropComosite(String classID){
		//classPropComposite.dispose();
		//GridLayout gridLayout = new GridLayout();
		//gridLayout.numColumns = 2;
		//a
		for(int i = 0;i < classLabelList.size();i++){
			Label label = classLabelList.get(i);
			Widget text = classTextList.get(i);
			label.dispose();
			text.dispose();
		}
		classPropList.clear();
		classLabelList.clear();
		classTextList.clear();
		
		try {
			if(session == null){
				session = (TCSession) AIFUtility.getCurrentApplication().getSession();
			}
			if(classService == null){
				classService = session.getClassificationService();
			}
			if(adminClass == null){
				adminClass = classService.newICSAdminClass();
			}
			
			
			adminClass.load(classID);
			
			ICSAdminClassAttribute[] icsAttrS = adminClass.getAttributes();
			if(icsAttrS != null){
				for(ICSAdminClassAttribute attr : icsAttrS){
					if(attr.isReferenceAttribute()){
						continue;
					}
					if(attr.isReference()){
						continue;
					}
					CNClassPropBean bean = new CNClassPropBean(attr);
					classPropList.add(bean);
					Label label = CreateCompositeUtil.createNewLabel(classPropComposite,bean.propDisName);
					label.getParent().layout();
					classLabelList.add(label);
					Widget widget = null;
					if(!bean.isLov){
						Text propText = CreateCompositeUtil.createNewText(classPropComposite, "");
						propText.getParent().layout();
						
						widget = propText;
					}else{
						Combo combo = CreateCompositeUtil.createNotFillNewCombo(
								 classPropComposite, bean.keyList.toArray(new String[bean.keyList.size()]));
						combo.getParent().layout();
						widget = combo;
					}
					classTextList.add(widget);
				}
			}
		} catch (TCException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		classPropComposite.update();
		classPropComposite.layout();
	}
	
	public List<Label> generalPropLabelList = new ArrayList<>();
	public List<Widget> generalPropTextList = new ArrayList<>();
	
	public void addGeneralPropComosite(){
		for(int i = 0;i < generalPropLabelList.size();i++){
			Label label = generalPropLabelList.get(i);
			Widget text = generalPropTextList.get(i);
			label.dispose();
			text.dispose();
		}
		generalPropLabelList.clear();
		generalPropTextList.clear();
		
		if(this.cnpropList!=null){
			for(CNProperty cnProp : this.cnpropList){
				Label label = CreateCompositeUtil.createNewLabel(objPropComposite,cnProp.getDisplayName());
				generalPropLabelList.add(label);
				Widget widget = null;
				if (!cnProp.getIsLov()) {
					if(cnProp.getPropertyType().toUpperCase().equals("STRING")){
						final Text text = CreateCompositeUtil.createNewText(objPropComposite, cnProp.getDefaultValue());
						widget = text;
					}else if(cnProp.getPropertyType().toUpperCase().equals("INTEGER")){
						final Text text = CreateCompositeUtil.createNewText(objPropComposite, cnProp.getDefaultValue());
						widget = text;
						text.addVerifyListener(new VerifyListener() {
							@Override
							public void verifyText(VerifyEvent e) {
							    boolean b = "0123456789".indexOf(e.text) >= 0 ;
						        e.doit = b;  //doit属性如果为true,则字符允许输入,反之不允许
							}
						});
					}
					else if(cnProp.getPropertyType().toUpperCase().equals("DATE")){
						final DateTime text = new DateTime(objPropComposite, SWT.DATE);
						widget = text;
					}else if(cnProp.getPropertyType().toUpperCase().equals("BOOLEAN")){
						final Combo comb = CreateCompositeUtil
								.createNotFillNewCombo(objPropComposite, new String[]{"true","false"}); // new
						comb.setText(cnProp.getDefaultValue());																	// Combo(propTable,
						widget = comb;																	// SWT.NONE);
					}
				} else {// lovBeanList
					final Combo comb = CreateCompositeUtil
							.createNotFillNewCombo(objPropComposite, cnProp.lovDisplayValueList
									.toArray(new String[cnProp.lovDisplayValueList.size()])); // new
					widget = comb;																	// Combo(propTable,																	// SWT.NONE);
					comb.setText(cnProp.getDefaultValue());
				}
				generalPropTextList.add(widget);
			}
		}
		objPropComposite.update();
		objPropComposite.layout();
		
	}
	
	
	/**
	 * 检查分类属性
	 */
	public boolean checkClassficationICO(){
		boolean isContent = false;
		try {
			//codeRemark
			if(classPropList.size()>0){
				ICSProperty icspro[] = new ICSProperty[classPropList.size()];
				for(int i = 0 ;i < classPropList.size();i++){
					CNClassPropBean bean = classPropList.get(i);
					String value = "";
					if(bean.isLov){
						value =((Combo)classTextList.get(i)).getText();
						value = bean.lovMapping.get(value);
					}else{
						value = ((Text)classTextList.get(i)).getText();
					}
					icspro[i] = new ICSProperty(bean.propID, value);
				}
				
				TCClassificationService classificationService = this.session.getClassificationService(); 
				ICSAdminClass c = classificationService.newICSAdminClass();
				c.load(codeRemark);
				//查询分类对象
				//参数1，分类的ID
				//参数2，根据属性过滤
				//参数3，默认（FIND_VALUES_UNIT_SYSTEM_NONE）
				ICSSearchResult[] results = classificationService.searchICOs(codeRemark,icspro , 0);
				if(results == null ||results.length == 0){
					System.out.println(" 搜索得到的结果为0");
					isContent = false;
				}else{
					System.out.println(" 搜索得到的结果为:"+results.length);
					isContent = true;
				}
//				for(int i = 0;i<results.length;i++){
//					//String icoID = results[i].getIcoId();
//					String icoUid = results[i].getIcoUid();
//					InterfaceAIFComponent comp2 = this.session.stringToComponent(icoUid);
//			        //获取分类属性
//					ICSProperty[] icsProps = ((TCComponentICO)comp2).getICSProperties(true);
//					for(int w = 0 ;w <icsProps.length;w++){
//			                 //属性值
//						    icsProps[w].getValue();
//			                 //属性ID
//			                icsProps[w].getId();
//					}
//				}
			}
		} catch (TCException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return isContent;
	}
	
	/**
	 * 发送对象到分类
	 * @return
	 */
	public void sendObjToClassfication(TCComponentItem item){
		try {
			if( !codeRemark.replace(" ", "").equals("") && item !=null){
				String partid = item.getStringProperty("item_id");
				TCComponentItemRevision rev = item.getLatestItemRevision();
				TCClassificationService myService = session.getClassificationService();
				ICSApplicationObject icsAppObj=myService.newICSApplicationObject("ICM");
				icsAppObj.create(partid, rev.getUid());
				icsAppObj.setView(codeRemark);
				ICSView icsview = icsAppObj.getView();
				ICSPropertyDescription icsproperty[] = icsview
						.getPropertyDescriptions();
				ICSProperty icspro[] = new ICSProperty[classPropList.size()];
			    //设置分类属性
				for (int i = 0; i < icspro.length; i++) {
					//System.out.println(" CLASS ID = " + integers[i] + "  =" + vals[i]);
					CNClassPropBean bean = classPropList.get(i);
					String value = "";
					if(bean.isLov){
						value =((Combo)classTextList.get(i)).getText();
						value = bean.lovMapping.get(value);
					}else{
						value = ((Text)classTextList.get(i)).getText();
					}
					icspro[i] = new ICSProperty(bean.propID, value);
				}
				icsAppObj.setProperties(icspro);
				icsAppObj.save();

			}
		} catch (TCException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/*
	 * 创建对话框的内容
	 * @see
	 * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
	 * .Composite)
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		// 获取首选项中的配置
		propBeanList = JFomMethodUtil.getTcPropInfo(
				JFomUtil.ITEM_TYPE_PROP_MAPPING_REF, session);
		propMapping = JFomMethodUtil.getMapping(
				JFomUtil.FORM_TYPE_PROP_MAPPING, session);
		formPropBean = JFomMethodUtil.getBZJFormMapping(
				JFomUtil.FORM_PROPS_MAPPING, session);
		String puid = JFomMethodUtil.getOptionValue(JFomUtil.AUTOCODE_UID_REF, session);
		
		
		try {
			TCComponent datasetcomp = session.stringToComponent(puid);
			String filePath = JFomMethodUtil.downLoadFile(datasetcomp);
			Object object = CNXmlUtil.xmlToBean(filePath, CNPartList.class);
			CNPartList parts = (CNPartList) object;
			this.cnPartList = parts;
			List<CNPart> partList = parts.getPartList();

			for (int i = 0; i < partList.size(); i++) {
				System.out.println(partList.get(i).getType());
				for (CNCompontent comp : partList.get(i).getCompontentList()) {
					System.out.println(comp.getType());
					System.out.println(comp.getCompententType());
					for (CNProperty prop : comp.getPropertyList()) {
						System.out.println(prop.getDisplayName());
					}
				}
			}
			System.out.println("-----------------------------");
		} catch (TCException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (JAXBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		

		Composite container1 = (Composite) super.createDialogArea(parent);
		// container1.
		FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);
		container1.setLayout(fillLayout);

		Shell shell = container1.getShell();
		shell.setFullScreen(true);
		//TODO 2017.06.02
		int x = shell.getSize().x ;//+ 200;
		Dimension srcDim = Toolkit.getDefaultToolkit().getScreenSize();
		shell.setSize(x, srcDim.height);
		// shell.open();
		container = new SashForm(container1, SWT.NONE);

		sashFormClassfication = new SashForm(container, SWT.NONE);
		// SashForm sashFormClassfication = new SashForm(container, SWT.BORDER |
		// SWT.H_SCROLL);
		// sashFormClassfication.setOrientation(SWT.HORIZONTAL);
		classificationView = new NewItemClassificationView(
				sashFormClassfication, "编码分类", showItemType,isTypeFilter);
		if(isTypeFilter = true){
			showItemType = "";
		}
		classificationTreeViewer = classificationView.treeViewer;
		addMouseAction();
		sashFormCodeView = new SashForm(container, SWT.NONE);
		GridData gridData1 = new GridData();
		gridData1.heightHint = 70;
		gridData1.horizontalAlignment = GridData.FILL;
		gridData1.verticalAlignment = GridData.CENTER;
		gridData1.grabExcessHorizontalSpace = true;

		ctabFolder = new CTabFolder(sashFormCodeView, SWT.BORDER);
		ctabFolder.setBorderVisible(true);
		ctabFolder.setSimple(false);
		ctabFolder.setLayoutData(gridData1);

		codeTreeCTab = new CTabItem(ctabFolder, SWT.NONE);
		codeTreeCTab.setText("编码树");
		compositCodeTree = new Composite(ctabFolder, SWT.NONE);

		compositCodeTree.setLayout(new FillLayout());
		codeTreeCTab.setControl(compositCodeTree);
		treeView = new NewItemTreeCodeView(compositCodeTree, "root");

		codeListCTab = new CTabItem(ctabFolder, SWT.NONE);
		codeListCTab.setText("编码列表");
		ctabFolder.setSelection(0);
		compositCodeList = new Composite(ctabFolder, SWT.NONE);
		compositCodeList.setLayout(new FillLayout());
		codeListCTab.setControl(compositCodeList);

		listView = new NewItemListCodeView();
		ctabFolder.setSelection(1);

		itemInfoComposite = new SashForm(container, SWT.NONE);
		createNewItemInfo(itemInfoComposite);

		try {
			classificationView
					.createOrgAutoCodeNodeChildren(new AbstractTreeData[] { (AbstractTreeData) classificationView.treeViewer
							.getTree().getTopItem().getData() });
		} catch (Exception e) {
			e.printStackTrace();
		}
		container.setWeights(new int[] { 3, 5, 6 });
		// container.getShell().setFullScreen(true);
		// Dimension srcDim = Toolkit.getDefaultToolkit().getScreenSize();
		// container1.getShell().setSize(srcDim.width, srcDim.height);
		// Point p =container1.getShell().getSize();
		// System.out.println("");
		// MessageBox.post(p.x+"|"+p.y,"P",1);
		return container;
	}

	// 得到最低层的节点
	// public TreeItem getLastChild(TreeItem item){
	// TreeItem childItem =item;
	// if(item.getItemCount()>0){
	// childItem= getLastChild(item.getItem(0));
	// }
	// System.out.println("i am in getLastChild "+childItem.getText());
	// return childItem
	// }

	/*
	 * //设置打开界面的时候默认选择最终节点 public void initSelectedCodeTree() { try {
	 * classificationView.createOrgAutoCodeNodeChildren(new
	 * AbstractTreeData[]{(AbstractTreeData)
	 * classificationView.treeViewer.getTree().getTopItem().getData()} );
	 * ctabFolder.setSelection(0);
	 * if(classificationTreeViewer.getTree().getTopItem().getItemCount()>0){
	 * if(classificationTreeViewer.getTree().getTopItem().getItem(0).
	 * getItemCount()>0){
	 * classificationTreeViewer.getTree().setSelection(classificationTreeViewer.
	 * getTree().getTopItem().getItem(0).getItem(0));
	 * setTreeNodes(treeViewOperation.getSelectedTreeNode(classificationView.
	 * treeViewer)); ctabFolder.redraw(); // showRule(); addMouseAction()方法中的内容，
	 * // 去掉 classificationTreeViewer.getTree().addSelectionListener(new
	 * SelectionAdapter() { // public void widgetSelected(SelectionEvent e) { }}
	 * } }
	 * 
	 * } catch (Exception e) { e.printStackTrace(); } }
	 */

	
	
	/**
	 * 获取产品线
	 * @return
	 */
	private String[] getAllCpx(){
		String[] cpxS =null;
		TCPreferenceService service = session.getPreferenceService();
		jyCPXMap = new HashMap<>();
		
		String[] value = service.getStringValues(JY_CPX_Option);
		if(value!=null){
			cpxS = new String[value.length];
			for(int i = 0;i <value.length;i++ ){
				String cpx = value[i];
				String[] valueS = cpx.split("=");
				if(valueS!=null && valueS.length ==2){
					cpxS[i] = valueS[0];
					jyCPXMap.put( valueS[0],  valueS[1]);
				}
			}
		}
		
		return cpxS;
	}
	
	
	/**
	 * CPX::产品代码
	 * NF::年份
	 * @param cpx
	 * @param nf
	 */
	private void setMidComposite(){
		String text = "";
		if(DescText!=null){
			text = DescText.getText();
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		System.out.println("DESC ==>"+text);
		
		if(text.contains(CPX2+"::")){
			System.out.println("CPX2 ADD");
			if(cpxLabel2 == null && cpxText2 ==null ){
				cpxLabel2 = CreateCompositeUtil.createNewLabel(cpxCompsite, "产品线");
				cpxText2 = CreateCompositeUtil.createNotFillNewCombo(
						cpxCompsite, getAllCpx());;
				//cpxText2.setEditable(true);
				cpxLabel2.getParent().layout();
			}
		}else{
			if(cpxLabel2 !=null && cpxText2!=null ){
				cpxLabel2.dispose();
				cpxText2.dispose();
				cpxLabel2 = null;
				cpxText2 = null;
			}
		}
		
		
		if(text.contains(CPX+"::")){
			System.out.println("CPX ADD");
			if(cpxLabel == null && cpxText ==null ){
				cpxLabel = CreateCompositeUtil.createNewLabel(cpxCompsite, "产品代码");
				cpxText = CreateCompositeUtil.createNewText(cpxCompsite, "");
				cpxText.setEditable(true);
				cpxLabel.getParent().layout();
			}
		}else{
			if(cpxLabel !=null && cpxText!=null ){
				cpxLabel.dispose();
				cpxText.dispose();
				cpxLabel = null;
				cpxText = null;
			}
		}
		//nfCompsite = new Composite(composite, SWT.BORDER);
		//nfCompsite.setLayout(gridLayout);
		if(text.contains(NF+"::")){
			System.out.println("NF ADD");
			if(nfLabel == null && nfText ==null ){
				
				nfLabel = CreateCompositeUtil.createNewLabel(cpxCompsite, "年份");
				nfText = CreateCompositeUtil.createNewText(cpxCompsite, "");
				nfText.setEditable(true);
				nfText.setText(sdf.format(new Date()));
				nfLabel.getParent().layout();
			}
		}else{
			if(nfLabel !=null && nfText!=null ){
				nfLabel.dispose();
				nfText.dispose();
				nfLabel = null;
				nfText = null;
			}
		}
		cpxCompsite.update();
		cpxCompsite.layout();
		composite.update();
		composite.layout();
	}
	private Composite composite;
	private void createNewItemInfo(Composite parent) {
		composite = new Composite(parent, SWT.BORDER);
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 1;
		composite.setLayout(gridLayout);
		CreateCompositeUtil.createNewLabel(composite, "特征码");
		idText = CreateCompositeUtil.createNewText(composite, "");

		CreateCompositeUtil.createNewLabel(composite, "特征码长度");
		idLengthText = CreateCompositeUtil.createNewText(composite, "");
		
		//===JY 2017.01.09====
		GridLayout gridLayout2 = new GridLayout();
		gridLayout2.numColumns = 4;
		
		cpxCompsite = new Composite(composite, SWT.BORDER);
		cpxCompsite.setLayout(gridLayout2);
		setMidComposite();
		//cpxLabel.dispose();//setVisible(false);
		//cpxText.dispose();//setVisible(false);
		
		CreateCompositeUtil.createNewLabel(composite, "版本");
		revText = CreateCompositeUtil.createNewText(composite, "");

		CreateCompositeUtil.createNewLabel(composite, "名称");
		nameText = CreateCompositeUtil.createNewText(composite, "");

		if (TCPreferenceUitl.isTrueTCPreferenceValue(session,
				origin_newItem_isShowUnit)) {
			try {
				CreateCompositeUtil.createNewLabel(composite, "度量单位");
				TCComponentListOfValues listOfValues = TCLOVUtil.findLOVByName(
						session, unitLOVName);
				ListOfValuesInfo listOfValuesInfo = listOfValues
						.getListOfValues();
				String[] values = listOfValuesInfo.getLOVDisplayValues();
				units = listOfValuesInfo.getTagListOfValues();
				if (values != null) {
					String[] unitvalues = new String[values.length + 1];
					if (TCPreferenceUitl.isTrueTCPreferenceValue(session,
							origin_isShowPCUnitLast)) {
						for (int i = 0; i < values.length; i++) {
							unitvalues[i] = values[i];
						}
						unitvalues[values.length] = "";// 每个
					} else {
						unitvalues[0] = "";// 每个
						for (int i = 0; i < values.length; i++) {
							unitvalues[i + 1] = values[i];
						}
					}
					unitCombo = CreateCompositeUtil.createNotFillNewCombo(
							composite, unitvalues);
				}
			} catch (TCException e) {
				e.printStackTrace();
			}
		}
		createClassTablePannel(composite);
		//CreateCompositeUtil.createNewLabel(composite, "描述");
		DescText = CreateCompositeUtil.createTextArea(composite, "", 1, 300);
		DescText.setVisible(false);
		
		// 进行扩展
		//CreateCompositeUtil.createNewLabel(objPropComposite, "属性");
		// 修改 20170626   
		propTable = CreateCompositeUtil.createNewTable(objPropComposite, "", 170, 230);

		idText.setEnabled(false);
		idLengthText.setEnabled(false);
		revText.setEnabled(false);
		DescText.setEnabled(false);
		// TODO 扩展
		propTable.setHeaderVisible(true);
		propTable.setLinesVisible(true);
		TableColumn tc = new TableColumn(propTable, SWT.CENTER);
		NameValue nameValue = new NameValue("SXMC", "属性名称");
		tc.setData(nameValue);
		tc.setText(nameValue.getValue());
		tc.setWidth(100);
		tc.setResizable(true);
		tc.setMoveable(false);

		TableColumn tc1 = new TableColumn(propTable, SWT.CENTER);
		NameValue nameValue1 = new NameValue("SXZ", "属性值");
		tc1.setData(nameValue1);
		tc1.setText(nameValue1.getValue());
		tc1.setWidth(130);
		tc1.setResizable(true);
		tc1.setMoveable(false);

		// GridData gridData = new GridData();
		// gridData.horizontalAlignment = SWT.FILL;
		// gridData.grabExcessHorizontalSpace = true;
		// gridData.grabExcessVerticalSpace = true;
		// gridData.verticalAlignment = SWT.FILL;
		// propTable.setLayoutData(gridData);
		// 标准件表单扩展
		Label icoPropLabel = CreateCompositeUtil.createNewLabel(composite, "标准件分类表单属性");
		icoPropLabel.setVisible(false);
		formTable = CreateCompositeUtil.createNewTable(composite, "", 170, 230);
		formTable.setVisible(false);
		formTable.setHeaderVisible(true);
		formTable.setLinesVisible(true);
		TableColumn tcf = new TableColumn(formTable, SWT.CENTER);
		NameValue nameValuef = new NameValue("SXMC1", "属性名称");
		tcf.setData(nameValuef);
		tcf.setText(nameValuef.getValue());
		tcf.setWidth(100);
		tcf.setResizable(true);
		tcf.setMoveable(false);

		TableColumn tcf1 = new TableColumn(formTable, SWT.CENTER);
		NameValue nameValuef1 = new NameValue("SXZ1", "属性值");
		tcf1.setData(nameValuef1);
		tcf1.setText(nameValuef1.getValue());
		tcf1.setWidth(130);
		tcf1.setResizable(true);
		tcf1.setMoveable(false);
		// formTable.setLayoutData(gridData);
		// tableItem = new TableItem(propTable, SWT.NONE);
		// tableItem.setText(0,"prop1");
		// List<String> nameList = new ArrayList<String>();
		// nameList.add("prop1");
		// nameList.add("prop2");
		// nameList.add("prop3");
		// nameList.add("prop4");
		// nameList.add("prop5");
		// nameList.add("prop6");
		// setTableItemValue(nameList);

	}

	/**
	 * 对属性TABLE添加内容
	 * 
	 * @param nameList
	 */
	public void setTableItemValue(Table propTable,
			Hashtable<TableItem, TableItemControls> tablecontrols,
			List<String> nameList, List<String> lovNameList,List<String> proTypeList,List<String> propIsMustList,List<String> propDefaultValueList, int codeNo) {
		if (nameList == null||nameList.size()==0)
			return;
		// propTable.removeAll();
		this.lovBeanList.clear();
		this.formLovBeanList.clear();
		delectTableValue(propTable, tablecontrols);
		for (int i = 0; i < nameList.size(); i++) {
			TableItem item = new TableItem(propTable, SWT.NONE);
			if(propIsMustList.get(i).toUpperCase().equals("T"))
				item.setText(0, "*"+nameList.get(i));
			else
				item.setText(0, nameList.get(i));
			
			item.setText(1, propDefaultValueList.get(i).equals("#")?"":propDefaultValueList.get(i));
			
			String lovName = lovNameList.get(i);
			String propType = proTypeList.get(i);
			List<String> lovValueStrList = new ArrayList<String>();
			List<String> lovDisValueStrList = new ArrayList<String>();

			// ******************
			try {
				TCComponentListOfValues lov = TCComponentListOfValuesType
						.findLOVByName(lovName);
				if (lov != null) {
					ListOfValuesInfo info = lov.getListOfValues();
					info.getLOVDisplayValues();
					List<LovValue> lovValueList = info.getValues();
					for (LovValue lovV : lovValueList) {
						lovDisValueStrList.add(lovV.getDisplayValue());
						System.out
								.println("LOV DIS =" + lovV.getDisplayValue());
						lovValueStrList.add(lovV.getStringValue());
						System.out.println("LOV =" + lovV.getStringValue());
						System.out.println(" codeNo =" + codeNo);
					}
				}
			} catch (TCException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			// *******************
			final TableEditor editor = new TableEditor(propTable);
			editor.grabHorizontal = true;
			if (lovName.equals("")) {
				if(propType.toUpperCase().equals("STRING")){
					final Text text = new Text(propTable, SWT.NONE);
					text.setText(item.getText(1));
					editor.setEditor(text, item, 1);
					text.addModifyListener(new ModifyListener() {
						public void modifyText(ModifyEvent e) {
							editor.getItem().setText(1, text.getText());
						}
					});
					TableItemControls cons = new TableItemControls(text, editor);
					tablecontrols.put(item, cons);
				}else if(propType.toUpperCase().equals("INTEGER")){
					
					final Text text = new Text(propTable, SWT.NONE);
					text.setText(item.getText(1));
					editor.setEditor(text, item, 1);
					text.addModifyListener(new ModifyListener() {
						public void modifyText(ModifyEvent e) {
							editor.getItem().setText(1, text.getText());
						}
					});
					text.addVerifyListener(new VerifyListener() {
						
						@Override
						public void verifyText(VerifyEvent e) {
							// TODO Auto-generated method stub
							// TODO Auto-generated method stub
							//if(type==1){//只能输入数字
								 boolean b = "0123456789".indexOf(e.text) >= 0 ;
					             e.doit = b;  //doit属性如果为true,则字符允许输入,反之不允许
					         //    return;
							//}
						}
					});
					TableItemControls cons = new TableItemControls(text, editor);
					tablecontrols.put(item, cons);
				}
				
				else if(propType.toUpperCase().equals("DATE")){
					final DateTime text = new DateTime(propTable, SWT.DATE);
					editor.setEditor(text, item, 1);
					text.addFocusListener(new FocusListener() {
						
						@Override
						public void focusGained(FocusEvent arg0) {
							// TODO Auto-generated method stub
							System.out.println("11111");
							editor.getItem().setText(1, ""+text.getYear() +"-"+(text.getMonth()+1)+"-"+text.getDay() );
							//editor.getItem().setText(0, ""+text.getYear() +"-"+(text.getMonth()+1)+"-"+text.getDay() );
							
							System.out.println(text.getYear() +"-"+text.getMonth()+"-"+text.getDay() +" 00:00");
						}

						@Override
						public void focusLost(FocusEvent arg0) {
							// TODO Auto-generated method stub
							System.out.println("2222");
							editor.getItem().setText(1, ""+text.getYear() +"-"+(text.getMonth()+1)+"-"+text.getDay() );
							//editor.getItem().setText(0, ""+text.getYear() +"-"+(text.getMonth()+1)+"-"+text.getDay());
							
							System.out.println(text.getYear() +"-"+text.getMonth()+"-"+text.getDay() +" 00:00");
						}
					});
					editor.getItem().setText(1, ""+text.getYear() +"-"+(text.getMonth()+1)+"-"+text.getDay() );
					
					TableItemControls cons = new TableItemControls(text, editor);
					tablecontrols.put(item, cons);
					
				}else if(propType.toUpperCase().equals("BOOLEAN")){
					final Combo comb = CreateCompositeUtil
							.createNotFillNewCombo(propTable, new String[]{"true","false"}); // new
																						// Combo(propTable,
																						// SWT.NONE);
					comb.setText(item.getText(1));
					editor.setEditor(comb, item, 1);
					comb.addModifyListener(new ModifyListener() {
						public void modifyText(ModifyEvent e) {
							editor.getItem().setText(1, comb.getText());
						}
					});
					TableItemControls cons = new TableItemControls(comb, editor);
					tablecontrols.put(item, cons);
				}
			} else {// lovBeanList
				JFomLovBean bean = new JFomLovBean();
				bean.setDisValueList(lovDisValueStrList);
				bean.setValueList(lovValueStrList);
				if (lovDisValueStrList.size() > 0 && codeNo == 2) {
					this.formLovBeanList.put(i, bean);
				} else if (lovDisValueStrList.size() > 0 && codeNo == 1) {
					this.lovBeanList.put(i, bean);
				}
				final Combo comb = CreateCompositeUtil
						.createNotFillNewCombo(propTable, lovDisValueStrList
								.toArray(new String[lovDisValueStrList.size()])); // new
																					// Combo(propTable,
																					// SWT.NONE);
				comb.setText(item.getText(1));
				editor.setEditor(comb, item, 1);
				comb.addModifyListener(new ModifyListener() {
					public void modifyText(ModifyEvent e) {
						editor.getItem().setText(1, comb.getText());
					}
				});
				TableItemControls cons = new TableItemControls(comb, editor);
				tablecontrols.put(item, cons);
			}
		}
	}

	public class TableItemControls {
		Text text;

		Combo combo;
		
		DateTime dateTime;

		TableEditor tableeditor;

		// TableEditor tableeditor1;

		public TableItemControls(Text text, TableEditor tableeditor) {
			// super();
			this.text = text;
			// this.combo = combo;
			this.tableeditor = tableeditor;
			// this.tableeditor1 = tableeditor1;
		}

		public TableItemControls(Combo combo, TableEditor tableeditor) {
			// super();
			this.combo = combo;
			this.tableeditor = tableeditor;
			// this.tableeditor1 = tableeditor1;
		}
		
		public TableItemControls(DateTime dateTime, TableEditor tableeditor) {
			// super();
			this.dateTime = dateTime;
			this.tableeditor = tableeditor;
			// this.tableeditor1 = tableeditor1;
		}

		public void dispose() {
			if (text != null)
				text.dispose();
			if (combo != null)
				combo.dispose();
			if(dateTime !=null)
				dateTime.dispose();
			tableeditor.dispose();
			// tableeditor1.dispose();
		}
	};

	public void delectTableValue(Table propTable,
			Hashtable<TableItem, TableItemControls> tablecontrols) {
		TableItem[] items = propTable.getItems();
		// propTable.removeAll();
		for (int i = items.length - 1; i >= 0; i--) {
			int index = propTable.indexOf(items[i]);
			// 如果没有该行，继续循环
			if (index < 0)
				continue;
			// 删除绑定的控件
			// 删除绑定的控件
			TableItemControls cons = tablecontrols.get(items[index]);
			if (cons != null) {
				cons.dispose();
				tablecontrols.remove(items[index]);
				System.out.println("dispose " + index);
			}
			propTable.remove(index);
			System.out.println("i=" + i + ", index=" + index);
			System.out.println("行数:" + propTable.getItemCount());
		}
	}

	private class NameValue {
		private String name = "";
		private String value = "";

		public NameValue(String name, String value) {
			this.name = name;
			this.value = value;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getValue() {
			return value;
		}

		public void setValue(String value) {
			this.value = value;
		}

	}

	private TCComponent[] getParentGroupNode(AbstractTreeData segmentNode) {
		TCComponent[] tccomponents = null;
		classificationTreeViewer.refresh();
		if (segmentNode == null) {
			return null;
		}
		if ((segmentNode.getPackCodeNodeInfo().getNodeComponent() != null)
				&& (segmentNode.getPackCodeNodeInfo().is_root)) {
		} else {
			return null;
		}
		getRealItemType(segmentNode, segmentNode.getParentTreeData());
		return tccomponents;
	}

	private void getRealItemType(AbstractTreeData segmentNode,
			AbstractTreeData parentNode) {
		if ((parentNode != null)
				&& (parentNode.getPackCodeNodeInfo().getNode_type()
						.equals(AutoCodeManagerPropertyName.ItemName))) {
			String realItemType = parentNode.getPackCodeNodeInfo()
					.getRealTypeName().trim();
			if (!segmentItemType.containsKey(segmentNode)) {
				segmentItemType.put(segmentNode, realItemType);
			}
		} else {
			if (parentNode != null) {
				parentNode = parentNode.getParentTreeData();
				getRealItemType(segmentNode, parentNode);
			}
		}
	}

	public void setTreeNodes(AbstractTreeData segmentNode) {
		try {
			classificationTreeViewer.refresh();
			if (segmentNode == null) {
				return;
			}
			getRealItemType(segmentNode, segmentNode.getParentTreeData());
			TCComponent autoCodeDataComponent = segmentNode
					.getPackCodeNodeInfo().getNodeComponent();
			TreeAndListCodeOperation treeAndListCodeOperation = new TreeAndListCodeOperation();
			HashMap<Object, Object> hashMap = new HashMap<Object, Object>();

			String parentStr = "";
			parentStr = treeAndListCodeOperation.getParentStr(segmentNode,
					parentStr);
			if (autoCodeDataComponent != null) {
				hashMap.put(
						AutoCodeManagerPropertyName.CodeRelation_current_node,
						autoCodeDataComponent.getUid());
				hashMap.put(
						AutoCodeManagerPropertyName.CodeRelation_parent_node,
						parentStr);
			} else {
				hashMap.put(
						AutoCodeManagerPropertyName.CodeRelation_parent_node,
						"");
				hashMap.put(
						AutoCodeManagerPropertyName.CodeRelation_current_node,
						"");
			}
			String parentStr2 = "";
			if (autoCodeDataComponent != null) {
				if (parentStr.trim().length() == 0) {
					parentStr2 = autoCodeDataComponent.getUid();
				} else {
					parentStr2 = parentStr + ","
							+ autoCodeDataComponent.getUid();
				}
			} else {
				parentStr2 = parentStr;
			}
			List<PackCodeNodeInfo> packCodeNodeInfos = treeAndListCodeOperation
					.searchTreeORListNodeInfos(
							hashMap,
							parentStr2,
							AutoCodeManagerPropertyName.searchTreeAndListCodeNodePropNames);
			if (packCodeNodeInfos != null && packCodeNodeInfos.size() > 0) {
				AbstractTreeData autoCodeDataTCComs[] = new AbstractTreeData[packCodeNodeInfos
						.size()];
				for (int k = 0; k < packCodeNodeInfos.size(); k++) {
					if (packCodeNodeInfos.get(k).getNodeComponent() == null) {
						continue;
					}
					PackCodeNodeInfo packCodeNodeInfo = packCodeNodeInfos
							.get(k);
					autoCodeDataTCComs[k] = new AbstractTreeData(segmentNode,
							packCodeNodeInfo);
					if (packCodeNodeInfo.isContainsChildren()) {
						autoCodeDataTCComs[k]
								.setTreeAutoCodeNodeChildren(new AbstractTreeData[] { new AbstractTreeData() });
					}
				}
				treeView.treeViewer.setInput(autoCodeDataTCComs);
				treeView.treeViewer.refresh();
			}
		} catch (ServiceException e) {
			e.printStackTrace();
		} catch (TCException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void addMouseAction() {
		classificationTreeViewer.getTree().addSelectionListener(
				new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						// MessageBox.post("prop","xxx",MessageBox.ERROR);
						try {
							initClassificationMouseClick();
							selectedSegmentNode = treeViewOperation
									.getSelectedTreeNode(classificationTreeViewer);
							if (selectedSegmentNode == null) {
								return;
							}
							//System.out.println("---->>>>>>> selectedSegmentNode =111>"+selectedSegmentNode.getParentTreeData().getPackCodeNodeInfo());
							getParentGroupNode(selectedSegmentNode);
							selectedSegmentTCComponent = selectedSegmentNode
									.getPackCodeNodeInfo().getNodeComponent();
							if (selectedSegmentTCComponent == null) {
								return;
							}
							if(selectedSegmentNode.getParentTreeData()!=null){
								//System.out.println("---->>>>>>> selectedSegmentNode =222>"+selectedSegmentNode.getPackCodeNodeInfo().rule_node);
								if("电子件".equals(selectedSegmentNode.getPackCodeNodeInfo().rule_node)){
									isCreateTempItemButton.setVisible(true);
								}else{
									isCreateTempItemButton.setVisible(false);
								}
							}
							
							if (selectedSegmentTCComponent
									.getLogicalProperty(AutoCodeManagerPropertyName.TreeAndListCodeNode_is_lock)) {
								ScrolledComposite scrolledComposite = new ScrolledComposite(
										ctabFolder, SWT.H_SCROLL | SWT.V_SCROLL);
								codeListCTab.setControl(scrolledComposite);
								treeView.treeViewer.setInput(null);
								return;
							}

							if ((selectedSegmentNode.getPackCodeNodeInfo()
									.getNode_type()
									.equals(AutoCodeManagerPropertyName.TreeName))
									|| (selectedSegmentNode
											.getPackCodeNodeInfo()
											.getNode_type()
											.equals(AutoCodeManagerPropertyName.ListName))) {
								// String realType =
								// selectedSegmentNode.getPackCodeNodeInfo().getRealTypeName();
								String realType = "";
								if (segmentItemType != null) {
									realType = (String) segmentItemType
											.get(selectedSegmentNode);
								}
								if ((realType == null)
										|| (realType.trim().length() == 0)) {
									realType = showItemType;
								}
								if (TCPreferenceUitl
										.isSelectExsitToTCPreferenceValues(
												session,
												origin_showUnit_excludeTypes,
												realType)) {
									if (unitCombo != null) {
										unitCombo.setEnabled(false);
									}
								} else {
									if (unitCombo != null) {
										unitCombo.setEnabled(true);
									}
								}
								if ((realType != null)
										&& (realType.length() > 0)) {
									tccomponentitemtype = (TCComponentItemType) (session
											.getTypeComponent(realType));
								}
								// System.out.println("类型 realType = "+realType);
							}
							if (selectedSegmentNode
									.getPackCodeNodeInfo()
									.getNode_type()
									.equals(AutoCodeManagerPropertyName.TreeName)) {
								classificationView.treeViewer.refresh();
								listView.setPropertyComb(null);
								treeView.treeViewer.setInput(null);
								Composite compositTemp = new Composite(
										ctabFolder, SWT.NONE);
								codeListCTab.setControl(compositTemp);
								setTreeNodes(treeViewOperation
										.getSelectedTreeNode(classificationView.treeViewer));
								ctabFolder.setSelection(0);
								ctabFolder.redraw();

								treeView.treeViewer.getTree()
										.addSelectionListener(
												new SelectionAdapter() {
													public void widgetSelected(
															SelectionEvent e) {
														// MessageBox.post("yyyyyys","xxx",MessageBox.ERROR);
														initTreeOrListMouseClick();
														AbstractTreeData selectedData = treeViewOperation
																.getSelectedTreeNode(treeView.treeViewer);
														if (selectedData == null) {
															return;
														}
														if (selectedData
																.getPackCodeNodeInfo()
																.getNodeComponent() == null) {
															return;
														}
														if ((selectedData
																.getPackCodeNodeInfo().is_lock)) {
															return;
														}
														String currentNodeDesc = "";
														String currentNodeValue = "";
														String name = "";
														// 得到编码相关信息
														getCodeInfo(selectedData);
														name = selectedData
																.getPackCodeNodeInfo()
																.getNode_name();
														icoTreeData = selectedData;
														if(selectedData.getParentTreeData() !=null){
															LPBIGString = selectedData.getParentTreeData().getPackCodeNodeInfo().getNode_name();
														}else{
															LPBIGString = "";
														}
														LPSString = selectedData.getPackCodeNodeInfo().getNode_name();
														currentNodeValue = replaceSpecialValue(selectedData
																.getPackCodeNodeInfo().node_value);
														if (currentNodeValue
																.length() > 0) {
															currentNodeDesc = currentNodeValue
																	+ "::"
																	+ selectedData
																			.getPackCodeNodeInfo()
																			.getNode_name();
														}
														if (currentNodeValue
																.trim()
																.length() > 0) {
															pattern = pattern
																	+ " "
																	+ currentNodeValue
																	+ " ";
														}
														if (currentNodeDesc
																.trim()
																.length() > 0) {
															codeDesc = codeDesc
																	+ currentNodeDesc;
														}
														if (!TCPreferenceUitl
																.isTrueTCPreferenceValue(
																		session,
																		origin_isItemNameTextDefaultNull)) {
															nameText.setText(name);
														} else {
															nameText.setText("");
														}
														getFinalPattern();
														// idText.setText(pattern);
														idText.setText(finalPattern);
														setIDPatternTextIsCanEdit();
														idLengthText.setText(String
																.valueOf(idText
																		.getText()
																		.replace(
																				" ",
																				"")
																		.trim()
																		.length()));
														DescText.setText(codeDesc);
														setMidComposite();
														// String msg =
														// selectedData.getPackCodeNodeInfo().getRealTypeName();
														// MessageBox.post("Info
														// =
														// >"+msg,"INFO",MessageBox.ERROR);

													}
												});
							} else if (selectedSegmentNode
									.getPackCodeNodeInfo()
									.getNode_type()
									.equals(AutoCodeManagerPropertyName.ListName)) {
								treeView.treeViewer.setInput(null);
								ctabFolder.setLayout(new FillLayout());
								ScrolledComposite scrolledComposite = new ScrolledComposite(
										ctabFolder, SWT.H_SCROLL | SWT.V_SCROLL);
								Composite compositTemp = new Composite(
										scrolledComposite, SWT.NONE);
								compositTemp.setLayout(new FillLayout());
								scrolledComposite.setContent(compositTemp);
								getParentGroupNode(selectedSegmentNode);

								listView.createCombox(compositTemp,
										selectedSegmentNode);
								codeListCTab.setControl(scrolledComposite);
								scrolledComposite.setExpandHorizontal(true);
								scrolledComposite.setExpandVertical(true);
								scrolledComposite.setMinWidth(250);
								scrolledComposite.setMinHeight(1000);
								ctabFolder.setSelection(1);
								ctabFolder.redraw();

								Combo[] coms = listView.getPropertyComb();
								if (coms == null) {
									return;
								}
								for (int i = 0; i < coms.length; i++) {
									if (coms[i] == null) {
										continue;
									}
									int comboStyle = coms[i].getStyle();
									if (comboStyle == 33554692) {
										coms[i].addFocusListener(new FocusListener() {
											public void focusGained(
													FocusEvent event) {
											}

											public void focusLost(
													FocusEvent event) {
												initTreeOrListMouseClick();
												try {
													firstListICOName = listView
															.getFirstComboName();
													listView.getListPropertyValue(selectedSegmentNode);
													codeDesc = listView
															.getCodeDesc()
															.toString();
													pattern = listView
															.getPattern()
															.toString();
													icoPropertyMap = listView
															.getIcoPropertyMap();
													revText.setText(tccomponentitemtype
															.getNewRev(null));

													if (!TCPreferenceUitl
															.isTrueTCPreferenceValue(
																	session,
																	origin_isItemNameTextDefaultNull)) {
														nameText.setText(firstListICOName);
													} else {
														nameText.setText("");
													}
													getFinalPattern();
													// idText.setText(pattern);
													idText.setText(finalPattern);
													setIDPatternTextIsCanEdit();
													idLengthText.setText(String
															.valueOf(idText
																	.getText()
																	.replace(
																			" ",
																			"")
																	.trim()
																	.length()));
													DescText.setText(codeDesc);
													setMidComposite();
												} catch (Exception e1) {
													e1.printStackTrace();
												}
											}
										});
									} else {
										coms[i].addSelectionListener(new SelectionAdapter() {
											public void widgetSelected(
													SelectionEvent selectionevent) {
												initTreeOrListMouseClick();
												// MessageBox.post("jjjjjj","xxx",MessageBox.ERROR);
												try {
													firstListICOName = listView
															.getFirstComboName();
													listView.getListPropertyValue(selectedSegmentNode);
													codeDesc = listView
															.getCodeDesc()
															.toString();
													pattern = listView
															.getPattern()
															.toString();
													icoPropertyMap = listView
															.getIcoPropertyMap();
													revText.setText(tccomponentitemtype
															.getNewRev(null));

													if (!TCPreferenceUitl
															.isTrueTCPreferenceValue(
																	session,
																	origin_isItemNameTextDefaultNull)) {
														nameText.setText(firstListICOName);
													} else {
														nameText.setText("");
													}
													getFinalPattern();
													idText.setText(finalPattern);
													// idText.setText(pattern);
													setIDPatternTextIsCanEdit();
													idLengthText.setText(String
															.valueOf(idText
																	.getText()
																	.replace(
																			" ",
																			"")
																	.trim()
																	.length()));
													DescText.setText(codeDesc);
													setMidComposite();
													// TODO 分类表单属性添加属性
													getFormProps();

												} catch (Exception e1) {
													e1.printStackTrace();
												}
											}
										});
									}
								}
							}
							if (tccomponentitemtype != null) {

								// TODO
								String type = tccomponentitemtype.getType();
								if (type.equals("TM2_powder")) {
									nameText.setEditable(false);
								} else {
									nameText.setEditable(true);
								}

								if (!type.equals("JF3_BZJ")) {
									setTableItemValue(formTable,
											formTablecontrols,
											new ArrayList<String>(),
											new ArrayList<String>(),
											new ArrayList<String>(),new ArrayList<String>(),new ArrayList<String>(), 2);
								}
								Boolean isHave = false;
								for (JFomBean bean : propBeanList) {
									if (bean.getItemType().equals(type)) {
										propBean = bean;
										setTableItemValue(propTable,
												tablecontrols,
												bean.getDisPropList(),
												bean.getLovPropName(),
												bean.getPropType(),bean.getPropIsMust(),bean.getDefaultValue(), 1);
										isHave = true;
										break;
									}
								}
								if (!isHave) {
									setTableItemValue(propTable, tablecontrols,
											new ArrayList<String>(),
											new ArrayList<String>(),
											new ArrayList<String>(),new ArrayList<String>(),new ArrayList<String>(), 1);
								}
								// MessageBox.post("TYPE =
								// "+tccomponentitemtype.getType(),"Type",MessageBox.ERROR);
							}
						} catch (Exception e1) {
							e1.printStackTrace();
						}
					}
				});
	}

	/**
	 * 标准件分类表单属性
	 */
	public void getFormProps() {
		// MessageBox.post(""+propMapping.size()+"|"+formPropBean.size(),"111",MessageBox.ERROR);
		if (segmentItemType != null) {
			String itemType = (String) segmentItemType.get(selectedSegmentNode);
			// MessageBox.post("111"+itemType,"",1);
			if (itemType.equals("TM2_powder")) {
				this.nameText.setEnabled(false);

			} else {
				this.nameText.setEnabled(true);
			}
			if (itemType.equals("JF3_BZJ")) {
				String desc = nameText.getText();
				// MessageBox.post("2222"+desc,"",1);
				if (!desc.isEmpty()) {
					// desc = desc.replace("\\n", "");
					// String bzjFL =
					// desc.substring(desc.indexOf("::")+2,desc.length());
					// MessageBox.post("3333"+bzjFL,"",1);
					// TODO DD获取分类表单属性 将属性加载到属性表单中
					this.bzjFLFormType = this.propMapping.get(desc);
					this.formBean = this.formPropBean.get(bzjFLFormType);
					setTableItemValue(formTable, formTablecontrols,
							formBean.getZhName(), formBean.getLovName(),formBean.getLovName(),formBean.getLovName(),formBean.getLovName(), 2);
				} else {
					setTableItemValue(formTable, formTablecontrols,
							new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(),new ArrayList<String>(),new ArrayList<String>(), 2);
				}
			} else {
				setTableItemValue(formTable, formTablecontrols,
						new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(),new ArrayList<String>(),2);
			}
		} else {
			setTableItemValue(formTable, formTablecontrols,
					new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(),new ArrayList<String>(),new ArrayList<String>(), 2);
		}
	}

	private void setIDPatternTextIsCanEdit() {
		String realItemType = "Item";
		if (segmentItemType != null) {
			realItemType = (String) segmentItemType.get(selectedSegmentNode);
		}
		if (TCPreferenceUitl.isSelectExsitToTCPreferenceValues(session,
				origin_isCodePatternCanEditTypes, realItemType)) {
			idText.setEnabled(true);
		}
	}

	public String replaceSpecialValue(String value) {
		Date date = new Date(System.currentTimeMillis());
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		String dateStr = formatter.format(date);
		String temps[] = dateStr.split("-");
		if (value.contains(AutoCodeManagerPropertyName.Code_year4)) {
			value = value.replace(AutoCodeManagerPropertyName.Code_year4,
					temps[0]);
			value = value + " ";
		}
		if (value.contains(AutoCodeManagerPropertyName.Code_year2)) {
			value = value.replace(AutoCodeManagerPropertyName.Code_year2,
					temps[0].substring(2));
			value = value + " ";
		}
		if (value.contains(AutoCodeManagerPropertyName.Code_mouth1)) {
			value = value.replace(AutoCodeManagerPropertyName.Code_mouth1,
					temps[1]);
			value = value + " ";
		}
		if (value.contains(AutoCodeManagerPropertyName.Code_mouth2)) {
			value = value.replace(AutoCodeManagerPropertyName.Code_mouth2,
					temps[1]);
			value = value + " ";
		}

		if (value.contains(AutoCodeManagerPropertyName.Code_date1)) {
			value = value.replace(AutoCodeManagerPropertyName.Code_date1,
					temps[2]);
			value = value + " ";
		}
		if (value.contains(AutoCodeManagerPropertyName.Code_date2)) {
			value = value.replace(AutoCodeManagerPropertyName.Code_date2,
					temps[2]);
			value = value + " ";
		}
		// if (value.contains(AutoCodeManagerPropertyName.Code_seq)) {
		// value = value.replace(AutoCodeManagerPropertyName.Code_seq, newSeq);
		// value = value + " ";
		// }
		if (value.contains(AutoCodeManagerPropertyName.Code_pattern)) {
			value = value.replace(AutoCodeManagerPropertyName.Code_pattern,
					pattern);
			value = value + " ";
		}
		return value;
	}

	public void getCodeInfo(AbstractTreeData treeData) {
		if (treeData != null) {
			AbstractTreeData parentData = treeData.getParentTreeData();
			if ((parentData != null)
					&& (parentData.getPackCodeNodeInfo().getNodeComponent() != null)) {
				getCodeInfo(parentData);
				String nodeValue = "";
				String nodeName = "";
				if (!parentData.getPackCodeNodeInfo().getNode_type()
						.equals(AutoCodeManagerPropertyName.ItemName)) {
					nodeValue = replaceSpecialValue(parentData
							.getPackCodeNodeInfo().getNode_value());
					nodeName = parentData.getPackCodeNodeInfo().getNode_name();
				}
				if (nodeValue.trim().length() > 0) {
					pattern = pattern + nodeValue;
					pattern = pattern + " ";
					codeDesc = codeDesc + nodeValue;
					codeDesc = codeDesc + "::";
					codeDesc = codeDesc + nodeName;
					codeDesc = codeDesc + "\n";
				}
				this.codeRemark = treeData.getPackCodeNodeInfo().getNode_desc();
				String cnpartType = ""; //treeData.getPackCodeNodeInfo().getNode_type();
				if (segmentItemType != null) {
					cnpartType = (String) segmentItemType
							.get(selectedSegmentNode);
				}
				System.out.println("cnpartType =>"+cnpartType);
				this.cnpropList = new ArrayList<>();
				if(this.cnPartList!=null && this.cnPartList.getPartList() !=null){
					for(CNPart cnpart1 : this.cnPartList.getPartList() ){
						if(cnpart1 !=null && cnpart1.getType().endsWith(cnpartType)){
							this.currentCNPart = cnpart1;
							if(cnpart1.getCompontentList()!=null ){
								for(CNCompontent cncomp : cnpart1.getCompontentList()){
									if(cncomp.getPropertyList()!=null){
										for(CNProperty cnprop :cncomp.getPropertyList() ){
											if(cnprop!=null){
												this.cnpropList.add(cnprop);
											}
										}
									}
								}
							}
						}
					}
				}
				//TODO CLASS
				addClassPropComosite(codeRemark);
				addGeneralPropComosite();
				System.out.println("node_desc ===>"+treeData.getPackCodeNodeInfo().getNode_desc());
			}
		}
	}

	private void initTreeOrListMouseClick() {
		try {
			if (treeViewOperation.getSelectedTreeNode(classificationTreeViewer) == null) {
				return;
			}
			icoPropertyMap = new HashMap<String, String>();
			pattern = "";
			codeDesc = "";
			newSeq = "";
			DescText.setText("");
			setMidComposite();
			codeCounterName = "";
			idText.setText("");
			if (unitCombo != null) {
				unitCombo.setText("");
			}
			idText.setEnabled(false);
			revText.setText(tccomponentitemtype.getNewRev(null));
			idLengthText.setText("");
			nameText.setText("");
		} catch (TCException e) {
			e.printStackTrace();
		}
	}

	private void initClassificationMouseClick() {
		try {
			if (treeViewOperation.getSelectedTreeNode(classificationTreeViewer) == null) {
				return;
			}
			icoPropertyMap = new HashMap<String, String>();
			pattern = "";
			codeDesc = "";
			pattern = "";
			newSeq = "";
			codeCounterName = "";
			DescText.setText("");
			setMidComposite();
			idText.setText("");
			if (unitCombo != null) {
				unitCombo.setText("");
			}
			idText.setEnabled(false);
			idLengthText.setText("");
			revText.setText(tccomponentitemtype.getNewRev(null));
			nameText.setText("");
		} catch (TCException e) {
			e.printStackTrace();
		}
	}

	public String getParentCodeData(AbstractTreeData treeData, String str) {
		if (treeData != null) {
			AbstractTreeData parentData = treeData.getParentTreeData();
			if ((parentData != null)
					&& (parentData.getPackCodeNodeInfo().getNodeComponent() != null)) {
				str = getParentCodeData(parentData, str);
				String nodeValue = parentData.getPackCodeNodeInfo()
						.getNode_value();
				if (nodeValue.trim().length() > 0) {
					str = str + nodeValue;
					str = str + " ";
				}
			}
		}
		return str;
	}

	public String getParentDescData(AbstractTreeData treeData, String str) {
		if (treeData != null) {
			AbstractTreeData parentData = treeData.getParentTreeData();
			if ((parentData != null)
					&& (parentData.getPackCodeNodeInfo().getNodeComponent() != null)) {
				str = getParentDescData(parentData, str);
				String nodeValue = parentData.getPackCodeNodeInfo()
						.getNode_value();
				String nodeDesc = parentData.getPackCodeNodeInfo()
						.getNode_name();
				if (nodeValue.trim().length() > 0) {
					str = str + nodeValue;
					str = str + "::";
					str = str + nodeDesc;
					str = str + "\n";
				}
			}
		}
		return str;
	}

	@Override
	protected void buttonPressed(int buttonId) {
		if (buttonId == IDialogConstants.YES_ID || buttonId == IDialogConstants.FINISH_ID) {
			
			if(buttonId == IDialogConstants.FINISH_ID){
				isCreateTempItem = true;
			}else{
				isCreateTempItem = false;
			}
			
			if ((newItemDialog != null) || (orNewItemInfoPanel != null)
					|| (packCodeDescInfos != null)) {
				long time1 = System.nanoTime();
				transferInfoToDialog();
				long time2 = System.nanoTime();
				System.out.println("申請流水总用时(ms)： " + (time2 - time1) / 1000000);
			} else {
				long time1 = System.nanoTime();
				createPressed();
				long time2 = System.nanoTime();
				System.out.println("创建总用时(ms)： " + (time2 - time1) / 1000000);
			}
		}
		if (buttonId == IDialogConstants.CANCEL_ID) {
			cancelPressed();
		}
	}

	/**
	 * 生成物料
	 */
	public void transferInfoToDialog() {
		try {
			if (!beforeGetNewSequenceNo()) {
				return;
			}
			String tezh = idText.getText();
			pattern = tezh.replaceAll(" ", "");

			String realItemType = "Item";
			if (segmentItemType != null) {
				realItemType = (String) segmentItemType
						.get(selectedSegmentNode);
			}
			// getSequenceNo(realItemType);
			// while (newID == null || tccomponentitemtype.find(newID) != null)
			// {
			getSequenceNo(realItemType);
			// }

			if ((newID == null) || (newID.trim().length() == 0)) {
				MessageBox.post("ID不能为空!", "INFO", MessageBox.WARNING);
				return;
			}
			while (tccomponentitemtype.find(newID) != null) {
				getSequenceNo(realItemType);
			}
			tccomponentitemtype = (TCComponentItemType) (session
					.getTypeComponent(realItemType));
			TCComponentItem oldItem = tccomponentitemtype.find(newID);
			if (oldItem != null) {
				new GetCodeNumber().delete_recycleID(counterID);
				MessageBox.post("ID为【" + newID + "】的物料已经存在!", "INFO",
						MessageBox.WARNING);
				return;
			} else {
				String[] keys = { AutoCodeManagerPropertyName.Item_generateID };
				String[] values = { newID };
				InterfaceAIFComponent[] components = TCQueryUtil
						.searchComponentsCollection(session,
								origin_searchGenerateID, keys, values);
				if (components != null) {
					if (components.length > 0) {
						new GetCodeNumber().delete_recycleID(counterID);
						MessageBox.post("ID为【" + newID + "】的物料已经存在!", "INFO",
								MessageBox.WARNING);
						return;
					}
				}
			}
			if ((newItemDialog != null)
					&& (newItemDialog instanceof ORSaveItemAsDialog)) {
				ORSaveItemAsDialog orSaveItemAsDialog = (ORSaveItemAsDialog) newItemDialog;
				if ((newID.length() > 0) && (revText.getText().length() > 0)) {
					PackCodeDescInfos packCodeDescInfos = new PackCodeDescInfos();
					// packCodeDescInfos.setCodeStyle(codeStyle);
					packCodeDescInfos.setCodeStyle(finalPattern);

					packCodeDescInfos.setCodetz(codeCounterName
							.replace(" ", "").trim());
					packCodeDescInfos.setGenerateID(newID);
					packCodeDescInfos.setIdDesc(DescText.getText());
					packCodeDescInfos.setIdjl(counterID);
					packCodeDescInfos
							.setSelectedSegmentNode(selectedSegmentNode);
					orSaveItemAsDialog.setPackCodeDescInfos(packCodeDescInfos);

					if (!TCPreferenceUitl.isSelectExsitToTCPreferenceValues(
							session, origin_idNeddExamineAndApproveTypes,
							realItemType)) {
						orSaveItemAsDialog.setItemID(newID);
					} else {
						orSaveItemAsDialog.setItemID(tccomponentitemtype
								.getNewID());
					}
					orSaveItemAsDialog.setItemName(nameText.getText());
					orSaveItemAsDialog.setItemRev(revText.getText());
				}
			} else if ((orNewItemInfoPanel != null)
					&& (orNewItemInfoPanel instanceof ORItemInfoPanel)) {
				if (newID.length() > 0) {
					ORNewItemDialog newItemDialog = (ORNewItemDialog) orNewItemInfoPanel.itemPanel.dialog;
					PackCodeDescInfos packCodeDescInfos = new PackCodeDescInfos();
					// packCodeDescInfos.setCodeStyle(codeStyle);
					packCodeDescInfos.setCodeStyle(finalPattern);
					packCodeDescInfos.setCodetz(codeCounterName
							.replace(" ", "").trim());
					packCodeDescInfos.setGenerateID(newID);
					packCodeDescInfos.setIdDesc(DescText.getText());
					packCodeDescInfos.setIdjl(counterID);
					packCodeDescInfos
							.setSelectedSegmentNode(selectedSegmentNode);
					newItemDialog.setCodeDescInfos(packCodeDescInfos);

					if (!TCPreferenceUitl.isSelectExsitToTCPreferenceValues(
							session, origin_idNeddExamineAndApproveTypes,
							realItemType)) {
						orNewItemInfoPanel.setNewItemID(newID);
					} else {
						orNewItemInfoPanel.setNewItemID(tccomponentitemtype
								.getNewID());
					}
					orNewItemInfoPanel.setNewItemRev(revText.getText());
					orNewItemInfoPanel.setNewItemName(nameText.getText());
				}

			} else if (packCodeDescInfos != null) {
				if (newID.length() > 0) {
					// packCodeDescInfos.setCodeStyle(codeStyle);
					packCodeDescInfos.setCodeStyle(finalPattern);
					packCodeDescInfos.setCodetz(codeCounterName
							.replace(" ", "").trim());
					packCodeDescInfos.setGenerateID(newID);
					packCodeDescInfos.setIdDesc(DescText.getText());
					packCodeDescInfos.setIdjl(counterID);
					packCodeDescInfos
							.setSelectedSegmentNode(selectedSegmentNode);

					if (!TCPreferenceUitl.isSelectExsitToTCPreferenceValues(
							session, origin_idNeddExamineAndApproveTypes,
							realItemType)) {
						if (packCodeDescInfos.getIdValueIText() != null) {
							packCodeDescInfos.getIdValueIText().setText(newID);
						} else if (packCodeDescInfos.getIdValueJText() != null) {
							packCodeDescInfos.getIdValueJText().setText(newID);
						}
					} else {
						if (packCodeDescInfos.getIdValueIText() != null) {
							packCodeDescInfos.getIdValueIText().setText(
									tccomponentitemtype.getNewID());
						} else if (packCodeDescInfos.getIdValueJText() != null) {
							packCodeDescInfos.getIdValueJText().setText(
									tccomponentitemtype.getNewID());
						}
					}
					if (packCodeDescInfos.getRevValueIText() != null) {
						packCodeDescInfos.getRevValueIText().setText(
								this.revText.getText());
					} else if (packCodeDescInfos.getRevValueJText() != null) {
						packCodeDescInfos.getRevValueJText().setText(
								this.revText.getText());
					}
					if (packCodeDescInfos.getNameValueIText() != null) {
						packCodeDescInfos.getNameValueIText().setText(
								this.nameText.getText());
					} else if (packCodeDescInfos.getNameValueJText() != null) {
						packCodeDescInfos.getNameValueJText().setText(
								this.nameText.getText());
					}
				}
			}
		} catch (TCException e) {
			e.printStackTrace();
		}
		super.okPressed();
	}

	@Override
	protected void cancelPressed() {
		try {
			if ((orNewItemInfoPanel != null)
					&& (orNewItemInfoPanel instanceof ORItemInfoPanel)) {

				orNewItemInfoPanel.setNewItemID("");
				orNewItemInfoPanel.setNewItemRev("");
				orNewItemInfoPanel.setNewItemName("");

			} else if ((newItemDialog != null)
					&& (newItemDialog instanceof ORSaveItemAsDialog)) {
				ORSaveItemAsDialog orSaveItemAsDialog = (ORSaveItemAsDialog) newItemDialog;
				orSaveItemAsDialog.setItemID("");
				orSaveItemAsDialog.setItemName("");
				orSaveItemAsDialog.setItemRev("");
			}

			if (packCodeDescInfos != null) {
				if (packCodeDescInfos.getIdValueIText() != null) {
					packCodeDescInfos.getIdValueIText().setText("");
				} else if (packCodeDescInfos.getIdValueJText() != null) {
					packCodeDescInfos.getIdValueJText().setText("");
				}
				if (packCodeDescInfos.getRevValueIText() != null) {
					packCodeDescInfos.getRevValueIText().setText("");
				} else if (packCodeDescInfos.getRevValueJText() != null) {
					packCodeDescInfos.getRevValueJText().setText("");
				}
				if (packCodeDescInfos.getNameValueIText() != null) {
					packCodeDescInfos.getNameValueIText().setText("");
				} else if (packCodeDescInfos.getNameValueJText() != null) {
					packCodeDescInfos.getNameValueJText().setText("");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		super.okPressed();
	}

	public String getID(String value) {
		String id = replaceSpecialValue(value);
		return id.replace(" ", "").trim();
	}

	private void getFinalPattern() {
		int codeSeqLength = 0;
		try {
			if (selectedSegmentTCComponent != null) {
				String[] propNames = {
						AutoCodeManagerPropertyName.TreeAndListCodeNode_code_style,
						AutoCodeManagerPropertyName.TreeAndListCodeNode_code_length,
						AutoCodeManagerPropertyName.TreeAndListCodeNode_seq_length };
				String[] propValues = selectedSegmentTCComponent
						.getProperties(propNames);
				codeStyle = propValues[0];
				codeLength = Integer.valueOf(propValues[1]);
				codeSeqLength = Integer.valueOf(propValues[2]);
			}
		} catch (TCException e) {
			e.printStackTrace();
		}

		String realItemType = "";
		if (segmentItemType != null) {
			realItemType = (String) segmentItemType.get(selectedSegmentNode);
		}

		String patternStyle = codeStyle;

		HashMap<String, String> sequenceMap = TCPreferenceUitl
				.getPreferenceHashMap(session, 4, origin_newCodeSequenceNumber);
		if ((sequenceMap != null) && (sequenceMap.size() > 0)) {
			String sequences = sequenceMap.get(realItemType
					+ "&&"
					+ selectedSegmentNode.getPackCodeNodeInfo().getNode_name()
							.trim());
			if (sequences != null) {
				String[] nums = sequences.split(";");
				if ((nums != null) && (nums.length > 0)) {
					String[] codeDesc1 = codeDesc.split("\n");
					if ((codeDesc1 != null)) {
						int descLength = codeDesc1.length;
						String newPattern = "";
						for (int n = 0; n < nums.length; n++) {
							String num = nums[n];
							int index = Integer.valueOf(num);
							if ((descLength >= index) && (index - 1 >= 0)) {
								String desc = codeDesc1[index - 1];
								String[] codeDesc2 = desc.split("::");
								if (codeDesc2.length == 2) {
									newPattern = newPattern + codeDesc2[0];
									newPattern = newPattern + " ";
								}
							}
						}
						pattern = newPattern;
					}
				}
			}
		}
		pattern = replaceSpecialValue(patternStyle);
		int coverNum = codeLength - pattern.replace(" ", "").trim().length()
				- codeSeqLength;
		String coverStr = "";
		if (coverNum > 0) {
			for (int i = 0; i < coverNum; i++) {
				coverStr = coverStr + "0";
			}
			if (coverStr.trim().length() > 0) {
				pattern = pattern + coverStr + " ";
			}
		}

		finalPattern = pattern;
		pattern = pattern.replace(" ", "");

	}

	public void getSequenceNo(String realItemType) {
		long time1 = System.nanoTime();
		try {
			TCComponent seqComponent = selectedSegmentTCComponent
					.getReferenceProperty(AutoCodeManagerPropertyName.TreeAndListCodeNode_rule_node);
			if (seqComponent != null) {
				String[] seqPropertys = {
						AutoCodeManagerPropertyName.TreeAndListCodeNode_code_style,
						AutoCodeManagerPropertyName.TreeAndListCodeNode_code_length,
						AutoCodeManagerPropertyName.TreeAndListCodeNode_seq_begin_value,
						AutoCodeManagerPropertyName.TreeAndListCodeNode_seq_length,
						AutoCodeManagerPropertyName.TreeAndListCodeNode_seq_max_value };
				String[] seqValues = seqComponent.getProperties(seqPropertys);
				try {
					codeStyle = seqValues[0];
					codeLength = Integer.valueOf(seqValues[1]);
					int startValue = Integer.valueOf(seqValues[2]);
					int codeSeqLength = Integer.valueOf(seqValues[3]);
					int endValue = Integer.valueOf(seqValues[4]);
					int increaseStep = 1;
					String excludeStr = "";

					if (startValue < 1) {
						startValue = 1;
					}

					finalPattern = this.idText.getText();

					idPattern = finalPattern;
					int seqIndex = idPattern
							.indexOf(AutoCodeManagerPropertyName.Code_seq);
					if (seqIndex > -1) {
						idPattern = idPattern.substring(0, seqIndex);
					}

					String segmentPattern = selectedSegmentNode
							.getPackCodeNodeInfo().getNode_value();
					segmentPattern = replaceSpecialValue(segmentPattern)
							.replace(" ", "");
					String seqPattern = excludeFirstPattern(idPattern,
							realItemType).replace(" ", "");
					if ((seqIndex == -1)) {
						codeCounterName = idPattern + "$" + codeSeqLength + "$"
								+ startValue + "$" + endValue + "$"
								+ increaseStep;
						counterID = seqPattern.replace(" ", "");
						newID = idPattern.replace(" ", "");
					} else {
						codeCounterName = seqPattern + "$" + codeSeqLength
								+ "$" + startValue + "$" + endValue + "$"
								+ increaseStep;
						String newCodeNum = new GetCodeNumber().getCodeNumber(
								seqPattern, codeSeqLength, startValue,
								endValue, increaseStep, excludeStr);
						counterID = newCodeNum.replace(" ", "");
						String newSeq = "";
						newSeq = newCodeNum.substring(newCodeNum
								.indexOf(seqPattern) + seqPattern.length());
						String newCodeNum2 = finalPattern.replace(
								AutoCodeManagerPropertyName.Code_seq, newSeq);
						newID = newCodeNum2.replace(" ", "");
					}
				} catch (ServiceException e) {
					e.printStackTrace();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		long time2 = System.nanoTime();
		System.out.println("申请流水用时(ms)： " + (time2 - time1) / 1000000);
		return;
	}

	private String excludeFirstPattern(String seqPattern, String realItemType) {
		if (TCPreferenceUitl.isSelectExsitToTCPreferenceValues(session,
				origin_sequenceExcludeFirstPatternTypes, realItemType)) {
			String segmentPattern = selectedSegmentNode.getPackCodeNodeInfo()
					.getNode_value();
			int segmentPatternLength = segmentPattern.length();
			if (segmentPatternLength > 0) {
				segmentPattern = replaceSpecialValue(segmentPattern).replace(
						" ", "");
				segmentPatternLength = segmentPattern.length();
				seqPattern = seqPattern.substring(segmentPatternLength);
			}
		}
		return seqPattern;
	}

	public void orCustomizationAction() {
		new ORAfterNewItemCustomization(this, newComp);
	}

	private boolean isHaveWritePrivilige(TCComponent component) {
		boolean privilige = true;
		try {
			TCComponentUser user = session.getUser();
			TCComponentGroup group = session.getCurrentGroup();
			TCComponentRole role = session.getCurrentRole();

			TCComponent coms[] = { user, group, role };
			TCAccessControlService service = session
					.getTCAccessControlService();
			boolean[] flags = service.checkAccessorsPrivileges(coms, component,
					new String[] { "WRITE" });
			for (boolean b : flags) {
				if (!b) {
					privilige = false;
					break;
				}
			}
		} catch (TCException e) {
			e.printStackTrace();
		}
		return privilige;
	}

	/**
	 * 通过SOA创建对象
	 * 
	 * @param itemID
	 * @param itemRev
	 * @param itemType
	 * @param itemName
	 * @param itemDesc
	 */
	private void createNewItemSoa(String itemID, String itemRev,
			String itemType, String itemName, String itemDesc, String prop) {
		Map propMap = new HashMap<String, String>();
		propMap.put("jf3_BZJfl", prop);
		// Map propMap2 = new HashMap<String, String>();
		propMap.put("object_desc", prop);
		// propMap.put("jf3_BZJFL", prop);

		DataManagementService datamanagementservice = DataManagementService
				.getService(session);
		com.teamcenter.services.rac.core._2006_03.DataManagement.CreateItemsResponse createitemsresponse = null;
		com.teamcenter.services.rac.core._2006_03.DataManagement.ItemProperties aitemproperties[] = new com.teamcenter.services.rac.core._2006_03.DataManagement.ItemProperties[1];
		aitemproperties[0] = new com.teamcenter.services.rac.core._2006_03.DataManagement.ItemProperties();
		aitemproperties[0].clientId = Integer.toString(1);
		aitemproperties[0].description = itemDesc;
		aitemproperties[0].itemId = itemID;

		if (itemType.equals("TM2_powder")) {
			itemName = itemID;
		} else {
			aitemproperties[0].name = itemName;
		}
		aitemproperties[0].revId = itemRev;
		aitemproperties[0].type = itemType;
		aitemproperties[0].uom = "";// == null ? "" : uomComp.toString();

		// setFormAttrs();
		// ArrayList arraylist = new ArrayList();
		// com.teamcenter.services.rac.core._2006_03.DataManagement.RevisionIds
		// revids = null;
		// com.teamcenter.services.rac.core._2006_03.DataManagement. revp;
		// com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes
		// extendedattributes2 = new
		// com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes();
		// extendedattributes2 = new
		// com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes();
		//
		// extendedattributes2.objectType = "JF3_BZJ";
		// extendedattributes2.attributes = propMap;
		// arraylist.add(extendedattributes2);

		com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes extendedattributes[] = new com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes[1];
		com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes extendedattributes3 = new com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes();
		extendedattributes3 = new com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes();
		extendedattributes3.objectType = "JF3_BZJRevision";
		extendedattributes3.attributes = propMap;

		extendedattributes[0] = extendedattributes3;
		// arraylist.add(extendedattributes3);
		// com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes
		// extendedattributes4 = new
		// com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes();
		// extendedattributes4 = new
		// com.teamcenter.services.rac.core._2006_03.DataManagement.ExtendedAttributes();
		// extendedattributes4.objectType = "JF3_BZJRevisionMaster";
		// extendedattributes4.attributes = propMap2;
		// arraylist.add(extendedattributes4);
		// if (arraylist.size() != 0)
		aitemproperties[0].extendedAttributes = extendedattributes;
		TCComponent tccomponent1 = null;
		String s1 = "";
		createitemsresponse = datamanagementservice.createItems(
				aitemproperties, tccomponent1, s1);
		if (createitemsresponse.serviceData.sizeOfPartialErrors() == 0) {
			newComp = createitemsresponse.output[0].item;
			if (newComp != null) {
				try {
					TCComponentItemRevision rev = ((TCComponentItem) newComp)
							.getLatestItemRevision();
					rev.lock();
					rev.setStringProperty("jf3_BZJfl", prop);
					rev.save();
					rev.unlock();
					if (!this.bzjFLFormType.isEmpty()) {
						TCComponentFormType type = (TCComponentFormType) session
								.getTypeComponent("Form");
						TCComponentForm form = type.create(itemName, itemDesc,
								this.bzjFLFormType);
						try {
							TableItem items[] = formTable.getItems();
							HashMap<String, String> propMapT = new HashMap<String, String>();
							if (items != null) {
								List<String> nameList = formBean.getEnName();
								JFomLovBean lovBean = null;
								int indexOf = 0;
								for (int i = 0; i < items.length; i++) {
									lovBean = this.formLovBeanList.get(i);
									if (lovBean == null) {
										propMapT.put(nameList.get(i),
												items[i].getText(1));
									} else {
										indexOf = lovBean.getDisValueList()
												.indexOf(items[i].getText(1));
										if (indexOf != -1)
											propMapT.put(
													nameList.get(i),
													lovBean.getValueList().get(
															indexOf));
									}
								}
							}
							if (propMapT.size() != 0) {
								form.lock();
								form.setProperties(propMapT);
								form.save();
								form.unlock();
							}
						} catch (Exception e) {
							e.printStackTrace();
							// MessageBox.post(e.getMessage(),"Error",1);
						}
						rev.add("IMAN_specification", form);
					}
				} catch (TCException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}
		}
	}

	// public void createIrdc(TCComponentItemRevision tccomponentitemrevision) {
	// ArrayList arraylist = new ArrayList();
	// GenericDatasetContainer genericdatasetcontainer;
	//
	// for (Iterator iterator1 = collection.iterator(); iterator1.hasNext();
	// arraylist
	// .add(genericdatasetcontainer.getAbsolutePath()))
	// genericdatasetcontainer = (GenericDatasetContainer) iterator1
	// .next();
	//
	// if (!arraylist.isEmpty())
	// createAndrelateIRDCDatasets(tccomponentitemrevision, arraylist);
	// }

	/**
	 * 通过SOA创建对象
	 * 
	 * @param itemID
	 * @param itemRev
	 * @param itemType
	 * @param itemName
	 * @param itemDesc
	 */
	private void createNewItemSoa2(String itemID, String itemRev,
			String itemType, String itemName, String itemDesc, String[] prop,
			String[] propName) {
		System.out.println(" 好累呀 propName =" + propName + " | value=" + prop);

		try {
			com.teamcenter.services.rac.core._2008_06.DataManagement.CreateInput itemInput = new com.teamcenter.services.rac.core._2008_06.DataManagement.CreateInput();
			itemInput.boName = itemType;
			System.out.println("Item Type  =>>>>"+itemType);
			Map<String, String> itemStringMap = new HashMap();
			itemStringMap.put("object_name", itemName);
			itemStringMap.put("item_id", itemID);
			itemStringMap.put("object_desc", itemDesc);
			itemInput.stringProps = itemStringMap;

			Map<String, CreateInput[]> compMap = new HashMap();

			CreateInput[] compInputS = new CreateInput[1];
			compInputS[0] = new CreateInput();
			compInputS[0].boName = itemType + "Revision";
			Map<String, String> compStringMap = new HashMap();
			compStringMap.put("item_revision_id", itemRev);
			
			compInputS[0].stringProps = compStringMap;
			
			
			Map<String, String> compStringMap2 = new HashMap();
			for (int i = 0; i < propName.length; i++) {
				System.out
						.println("Name =" + propName[i] + " value=" + prop[i]);
				compStringMap2.put(propName[i], prop[i]);
			}
			
			CreateInput[] formCompInputS = new CreateInput[1];
			formCompInputS[0] = new CreateInput();
			formCompInputS[0].boName = itemType + "RevisionMaster";
			formCompInputS[0].stringProps =compStringMap2;
			Map<String, CreateInput[]> formCompMap = new HashMap();
			formCompMap.put("IMAN_master_form_rev", formCompInputS);
			
			compInputS[0].compoundCreateInput = formCompMap;

			compMap.put("revision", compInputS);
			itemInput.compoundCreateInput = compMap;

			DataManagementService datamanagementservice = DataManagementService
					.getService(session);
			com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn createin = new com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn();
			createin.clientId = "Test";
			createin.data = itemInput;
			com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse createresponse = datamanagementservice
					.createObjects(new com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn[] { createin });
			
			
			SoaUtil.handlePartialErrors(createresponse.serviceData, null, null,
					true);
			com.teamcenter.services.rac.core._2008_06.DataManagement.CreateOut acreateout[] = createresponse.output;
			if (acreateout != null && acreateout.length > 0) {
				ArrayList arraylist = new ArrayList(0);
				com.teamcenter.services.rac.core._2008_06.DataManagement.CreateOut acreateout1[];
				int j = (acreateout1 = acreateout).length;
				for (int i = 0; i < j; i++) {
					com.teamcenter.services.rac.core._2008_06.DataManagement.CreateOut createout = acreateout1[i];
					TCComponent atccomponent[] = createout.objects;
					if (atccomponent != null && atccomponent.length > 0) {
						arraylist.addAll(Arrays.asList(atccomponent));
						newComp = atccomponent[0];
					}
				}

			}
		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TCExceptionPartial e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 获取lov属性
	 * 
	 * @param propName
	 * @return
	 */
	public String getPropValue(String propName) {
		String value = "";
		List<String> itemPropList = propBean.getItemRelPropList();
		int index = itemPropList.size();
		List<String> revPropList = propBean.getRevRelPropList();
		int indexRev = revPropList.size() + index;
		TableItem items[] = this.propTable.getItems();
		System.out.println("index =>" + index + "|indexRev=" + indexRev);
		HashMap<String, String> propValueMapping = new HashMap<>();
		for (int i = index; i < indexRev; i++) {
			JFomLovBean lovBean = this.lovBeanList.get(i);
			// lovBean = this.lovBeanList.get(i);
			if (lovBean == null) {
				propValueMapping.put(revPropList.get(i - index),
						items[i].getText(1));
			} else {
				int indexOf = lovBean.getDisValueList().indexOf(
						items[i].getText(1));

				if (indexOf != -1) {
					propValueMapping.put(revPropList.get(i - index), lovBean
							.getValueList().get(indexOf));
					System.out.println("DISPLAYVALUE ="
							+ lovBean.getDisValueList().get(indexOf)
							+ " | RELVALUE ="
							+ lovBean.getValueList().get(indexOf));
				}
			}
		}
		if (propValueMapping.containsKey(propName)) {
			value = propValueMapping.get(propName);
		}
		return value;
	}

	private void createNewItem(String itemID, String itemRev, String itemType,
			String itemName, String itemDesc) {
		try {
			if(!checkIsMust(itemType)){
				MessageBox.post("请填写必填属性","错误",MessageBox.ERROR);
				return;
			}
			
			TCComponent targetObject = (TCComponent) AIFUtility
					.getCurrentApplication().getTargetComponent();
			// tccomponentitemtype.create(s, s1, s2, s3, s4, tccomponent)
			String msg = DescText.getText();
			String[] msgs = msg.split("\\n");
			String propmsg = "";
			if (itemType.endsWith(JFomUtil.JF3_BZJ_TYPE) && msgs != null
					&& msgs.length == 1) {
				String[] values = msgs[0].split("::");
				if (values != null && values.length == 2)
					propmsg = values[1];
			}

			if (targetObject instanceof TCComponentFolder) {
				// TCCreateInfo createInfo =
				// tccomponentitemtype.getCreateProperties();
				if (itemType.endsWith(JFomUtil.JF3_BZJ_TYPE)) {
					createNewItemSoa(itemID, itemRev, itemType, itemName,
							itemDesc, propmsg);
					// MessageBox.post("wwww","gg",MessageBox.INFORMATION);
				} else if (itemType.equals("TM2_powder")) {
					newComp = tccomponentitemtype.create(itemID,
							revText.getText(), itemType, itemID, "", null);
				} else if (itemType.equals("HX3_DJT")
						|| itemType.equals("HX3_WXT")) {
					String propName = itemType.toLowerCase() + "tf";
					String value = getPropValue(propName);
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value },
							new String[] { propName });
				} else if (itemType.equals("HX3_LJT")
						|| itemType.equals("HX3_ZPT")) {
					String propName = itemType.toLowerCase() + "tf";
					String value = getPropValue(propName);
					String value2 = getPropValue("hx3_djblx");
					if (value2.endsWith("从动盘图纸点检表")) {
						value2 = "1";
					} else if (value2.endsWith("压盘图纸点检表")) {
						value2 = "2";
					}
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value, value2 },
							new String[] { propName, "hx3_djblx" });
				} else if (itemType.equals("HX3_GZT")) {
					String propName = "hx3_gztlx";
					String value = getPropValue(propName);
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value },
							new String[] { propName });
				} else if (itemType.equals("HX3_GYT")) {
					String propName = "hx3_lx";
					String value = getPropValue(propName);
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value },
							new String[] { propName });
				} else if(itemType.equals("JY8Design")){
					String propName = "JyDesType";
					String value = getPropValue(propName);
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value },
							new String[] { propName });
				}
				else {
					newComp = tccomponentitemtype.create(itemID,
							revText.getText(), itemType, nameText.getText(),
							"", null);
				}
				// newComp = new CreateNewItemOperation().createNewItem(itemID,
				// itemRev, itemType, itemName, itemDesc, null);
				if (newComp != null) {
					TCComponentFolder folder = (TCComponentFolder) targetObject;
					if (isHaveWritePrivilige(folder)) {
						folder.add("contents", newComp);
						folder.refresh();
					} else {
						session.getUser().getNewStuffFolder()
								.add("contents", newComp);
						session.getUser().getNewStuffFolder().refresh();
					}
				}
			} else if (targetObject instanceof TCComponentPseudoFolder) {
				if (itemType.endsWith(JFomUtil.JF3_BZJ_TYPE)) {
					createNewItemSoa(itemID, itemRev, itemType, itemName,
							itemDesc, propmsg);
				} else if (itemType.equals("HX3_DJT")
						|| itemType.equals("HX3_WXT")) {
					String propName = itemType.toLowerCase() + "tf";
					String value = getPropValue(propName);
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value },
							new String[] { propName });
				} else if (itemType.equals("HX3_LJT")
						|| itemType.equals("HX3_ZPT")) {
					String propName = itemType.toLowerCase() + "tf";
					String value = getPropValue(propName);
					String value2 = getPropValue("hx3_djblx");
					if (value2.endsWith("从动盘图纸点检表")) {
						value2 = "1";
					} else if (value2.endsWith("压盘图纸点检表")) {
						value2 = "2";
					}
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value, value2 },
							new String[] { propName, "hx3_djblx" });
				} else if (itemType.equals("HX3_GZT")) {
					String propName = "hx3_gztlx";
					String value = getPropValue(propName);
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value },
							new String[] { propName });
				} else if (itemType.equals("HX3_GYT")) {
					String propName = "hx3_lx";
					String value = getPropValue(propName);
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value },
							new String[] { propName });
				}else if (itemType.equals("JY8Design")){
					String propName = "JyDesType";
					String value = getPropValue(propName);
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value },
							new String[] { propName });
				}else if (itemType.equals("TM2_powder")) {
					newComp = tccomponentitemtype.create(itemID,
							revText.getText(), itemType, itemID, "", null);
				} else {
					newComp = tccomponentitemtype.create(itemID,
							revText.getText(), itemType, nameText.getText(),
							"", null);
				}
				if (newComp != null) {
					if (TCPreferenceUitl.isTrueTCPreferenceValue(session,
							origin_isNotSaveNewItemToPseudoFolder)) {
						session.getUser().getNewStuffFolder()
								.add("contents", newComp);
						session.getUser().getNewStuffFolder().refresh();
					} else {
						TCComponentPseudoFolder folder = (TCComponentPseudoFolder) targetObject;
						String propertyName = folder
								.getProperty("property_name");
						TCComponent ownerComponent = folder
								.getOwningComponent();
						if (ownerComponent != null) {
							ownerComponent.add(propertyName, newComp);
							ownerComponent.refresh();
						}
					}
				}
			} else {
				if (itemType.endsWith(JFomUtil.JF3_BZJ_TYPE)) {
					createNewItemSoa(itemID, itemRev, itemType, itemName,
							itemDesc, propmsg);
				} else if (itemType.equals("HX3_DJT")
						|| itemType.equals("HX3_WXT")) {
					String propName = itemType.toLowerCase() + "tf";
					String value = getPropValue(propName);
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value },
							new String[] { propName });
				} else if (itemType.equals("HX3_LJT")
						|| itemType.equals("HX3_ZPT")) {
					String propName = itemType.toLowerCase() + "tf";
					String value = getPropValue(propName);
					String value2 = getPropValue("hx3_djblx");
					if (value2.endsWith("从动盘图纸点检表")) {
						value2 = "1";
					} else if (value2.endsWith("压盘图纸点检表")) {
						value2 = "2";
					}
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value, value2 },
							new String[] { propName, "hx3_djblx" });
				} else if (itemType.equals("HX3_GZT")) {
					String propName = "hx3_gztlx";
					String value = getPropValue(propName);
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value },
							new String[] { propName });
				} else if (itemType.equals("HX3_GYT")) {
					String propName = "hx3_lx";
					String value = getPropValue(propName);
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value },
							new String[] { propName });
				}else if(itemType.equals("JY8Design")){
					String propName = "JyDesType";
					String value = getPropValue(propName);
					createNewItemSoa2(itemID, revText.getText(), itemType,
							itemName, "", new String[] { value },
							new String[] { propName });
				} else
					newComp = tccomponentitemtype.create(itemID,
							revText.getText(), itemType, nameText.getText(),
							"", null);
				if(newComp != null && itemType.equals("HX3_WL")&&targetObject!=null && 
						(targetObject.getType().equals("HX3_ZPTRevision") || targetObject.getType().equals("HX3_LJTRevision"))){
					//TC_Is_Represented_By
					((TCComponentItem)newComp).getLatestItemRevision().add("TC_Is_Represented_By", targetObject);
				}
				if (newComp != null) {
					session.getUser().getNewStuffFolder()
							.add("contents", newComp);
					session.getUser().getNewStuffFolder().refresh();
				}
			}
			if (newComp != null) {
				// TODO 设置属性
				// 版本
				TCComponentItemRevision rev = ((TCComponentItem) newComp)
						.getLatestItemRevision();
				
				System.out.println("LP > <"+LPBIGString+">  <"+LPSString+">");
				TCProperty[] lpprops = null;
				if(rev.getType().equals("LP2_Elc_CompRevision")){
					lpprops = rev.getTCProperties(new String[]{"lp2_Elc_Comp_Parent","lp2_Elc_Part_Child"});
				}else if(rev.getType().equals("LP2_Elc_PartRevision")){
					lpprops = rev.getTCProperties(new String[]{"lp2_Elc_Part_Parent","lp2_Elc_Part_Child"});
				}
				if(lpprops!=null){
					if(lpprops[1] !=null){
						TCComponentListOfValues lov = lpprops[1].getLOV();
						if(lov !=null){
							ListOfValuesInfo lovinfo = lov.getListOfValues();
							List<LovValue> lovValueList = lovinfo.getValues();
							for(LovValue lv : lovValueList){
								if(lv.getDisplayValue().endsWith(LPBIGString)){
									lpprops[1].setStringValue((String)lv.getValue());
								}
							}
						}else{
							
							lpprops[1].setStringValue(LPBIGString);
						}
						rev.lock();
						rev.setTCProperty(lpprops[1]);
						rev.save();
						rev.unlock();
					}
					if(lpprops[2]!=null){
						TCComponentListOfValues lov = lpprops[2].getLOV();
						if(lov !=null){
							ListOfValuesInfo lovinfo = lov.getListOfValues();
							List<LovValue> lovValueList = lovinfo.getValues();
							for(LovValue lv : lovValueList){
								if(lv.getDisplayValue().endsWith(LPSString)){
									lpprops[2].setStringValue((String)lv.getValue());
								}
							}
						}else{
							
							lpprops[2].setStringValue(LPSString);
						}
						rev.lock();
						rev.setTCProperty(lpprops[2]);
						rev.save();
						rev.unlock();
					}
				}
				// 版本住属性表单
				TCComponentForm imanRevForm = (TCComponentForm) rev
						.getTCProperty("IMAN_master_form_rev")
						.getReferenceValueArray()[0];
				if(itemType.equals("HX3_WL")){
					//hx3_chfl
					imanRevForm.lock();
					imanRevForm.setStringProperty("hx3_chfl", this.codeRemark);
					imanRevForm.save();
					imanRevForm.unlock();
				}
				
				// MessageBox.post(msgs.length + "", "desc", MessageBox.ERROR);
				if (itemType.endsWith(JFomUtil.JF3_CP_TYPE) && msgs != null
						&& msgs.length == 3) {
					try {
						String[] values = msgs[1].split("::");
						String[] values2 = msgs[2].split("::");
						if (values != null && values.length == 2) {
							imanRevForm.lock();
							imanRevForm.setStringProperty(JFomUtil.JF3_CP_FLMC,
									values[1]);
							imanRevForm.save();
							imanRevForm.unlock();
						}
						if (values2 != null && values2.length == 2) {
							imanRevForm.lock();
							imanRevForm.setStringProperty(JFomUtil.JF3_CP_XMDH,
									values2[1]);
							imanRevForm.save();
							imanRevForm.unlock();
						}
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

				} else if ((itemType.endsWith(JFomUtil.JF3_BCP_TYPE) || itemType
						.endsWith(JFomUtil.JF3_YCL_TYPE))
						&& msgs != null
						&& msgs.length == 3) {
					String[] values = msgs[1].split("::");
					String[] values2 = msgs[2].split("::");
					if (values != null && values.length == 2) {
						imanRevForm.lock();
						imanRevForm.setStringProperty(JFomUtil.JF3_D_FLMC,
								values[1]);
						imanRevForm.save();
						imanRevForm.unlock();
					}
					if (values2 != null && values2.length == 2) {
						imanRevForm.lock();
						imanRevForm.setStringProperty(JFomUtil.JF3_X_FLMC,
								values2[1]);
						imanRevForm.save();
						imanRevForm.unlock();
					}

				}
				if (propBean != null) {
					TCComponentItemType itemtype = (TCComponentItemType) session.getTypeComponent(itemType);
					TCComponentItemRevisionType revtype =(TCComponentItemRevisionType) this.session.getTypeComponent(itemType+"Revision");
					TCComponentFormType formtype = (TCComponentFormType) session.getTypeComponent(itemType+"RevisionMaster");
					SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-M-dd");
					List<String> itemPropList = propBean.getItemRelPropList();
					int index = itemPropList.size();
					List<String> revPropList = propBean.getRevRelPropList();
					int indexRev = revPropList.size() + index;
					List<String> formPropList = propBean.getFormRelPropList();
					int indexForm = formPropList.size() + indexRev;
					HashMap<String, String> propValueMapping = new HashMap<String, String>();
					TableItem items[] = this.propTable.getItems();
					JFomLovBean lovBean = null;
					int indexOf = 0;
					// 设置ITEM的属性
					for (int i = 0; i < index; i++) {
						lovBean = this.lovBeanList.get(i);
						if (lovBean == null) {
							TCProperty prop = newComp.getTCProperty(itemPropList.get(i));
							if(prop !=null && prop.isType(TCProperty.PROP_date)){
								newComp.lock();
								newComp.setDateProperty(itemPropList.get(i), dateFormat.parse(items[i].getText(1)));
								newComp.save();
								newComp.unlock();
							}else{
								propValueMapping.put(itemPropList.get(i),
										items[i].getText(1));
							}
							
						} else {
							indexOf = lovBean.getDisValueList().indexOf(
									items[i].getText(1));
							if (indexOf != -1)
								propValueMapping.put(itemPropList.get(i),
										lovBean.getValueList().get(indexOf));
						}
					}
					if (propValueMapping.size() != 0) {
						try {
							newComp.lock();
							newComp.setProperties(propValueMapping);
							newComp.save();
							newComp.unlock();
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
					propValueMapping.clear();
					// 设置ITEMREV的属性
					for (int i = index; i < indexRev; i++) {
						lovBean = this.lovBeanList.get(i);
						if (lovBean == null) {
							
							TCProperty prop = rev.getTCProperty(revPropList.get(i - index));
							if(prop !=null && prop.isType(TCProperty.PROP_date)){
								rev.lock();
								rev.setDateProperty(revPropList.get(i - index), dateFormat.parse(items[i].getText(1)));
								rev.save();
								rev.unlock();
							}else{
								propValueMapping.put(revPropList.get(i - index),
										items[i].getText(1));
							}
							
						} else {
							indexOf = lovBean.getDisValueList().indexOf(
									items[i].getText(1));
							if (indexOf != -1)
								propValueMapping.put(
										revPropList.get(i - index), lovBean
												.getValueList().get(indexOf));
						}
					}
					if (propValueMapping.size() != 0) {
						try {
							rev.lock();
							rev.setProperties(propValueMapping);
							rev.save();
							rev.unlock();
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
					propValueMapping.clear();
					// 设置ITEMREVMASTER的属性
					for (int i = indexRev; i < indexForm; i++) {
						lovBean = this.lovBeanList.get(i);
						if (lovBean == null) {
							System.out.println(formPropList.get(i - indexRev));
							TCProperty prop = imanRevForm.getTCProperty(formPropList.get(i - indexRev));
							if(prop !=null && prop.isType(TCProperty.PROP_date)){
								imanRevForm.lock();
								imanRevForm.setDateProperty(formPropList.get(i - indexRev), dateFormat.parse(items[i].getText(1)));
								imanRevForm.save();
								imanRevForm.unlock();
							}else{
								propValueMapping.put(
										formPropList.get(i - indexRev),
										items[i].getText(1));
								System.out.println(prop ==null?"":prop.getDescriptor().getType() + "   not prop_date "+ formPropList.get(i - indexRev)+"|"+
										items[i].getText(1));
							}
						} else {
							indexOf = lovBean.getDisValueList().indexOf(
									items[i].getText(1));
							if (indexOf != -1) {
								propValueMapping.put(formPropList.get(i
										- indexRev), lovBean.getValueList()
										.get(indexOf));
								// try {
								// System.out.println("SET LOV prop_name =" +
								// formPropList.get(i - indexRev)
								// + " LOV_DIS=" +
								// lovBean.getDisValueList().get(indexOf) +
								// " LOV="
								// + lovBean.getValueList().get(indexOf));
								// imanRevForm.setStringProperty(formPropList.get(i
								// - indexRev),
								// lovBean.getValueList().get(indexOf));
								// } catch (Exception e) {
								// // TODO Auto-generated catch block
								// e.printStackTrace();
								// }

							}
						}
					}
					if (propValueMapping.size() != 0) {
						try {
							imanRevForm.lock();
							imanRevForm.setProperties(propValueMapping);
							imanRevForm.save();
							imanRevForm.unlock();
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
					propValueMapping.clear();

				}
				// else if (itemType.endsWith(JFomUtil.JF3_BZJ_TYPE) && msgs !=
				// null && msgs.length == 1) {
				// String[] values = msgs[0].split("::");
				// if (values != null && values.length == 2)
				// rev.setStringProperty(JFomUtil.JF3_BZJFL_PROP, values[1]);
				// }
			}

			if (targetObject != null) {
				targetObject.refresh();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	
	
	/**
	 * 判断属性是否必填写
	 * @param itemType
	 * @return
	 */
	private boolean checkIsMust(String itemType){
		boolean isOk = true;
		try {
			if(propBean!=null){
				//ff
				TCComponentItemType itemtype = (TCComponentItemType) session.getTypeComponent(itemType);
				TCComponentItemRevisionType revtype =(TCComponentItemRevisionType) this.session.getTypeComponent(itemType+"Revision");
				TCComponentFormType formtype = (TCComponentFormType) session.getTypeComponent(itemType+"RevisionMaster");
				SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-M-dd");
				List<String> itemPropList = propBean.getItemRelPropList();
				int index = itemPropList.size();
				List<String> revPropList = propBean.getRevRelPropList();
				int indexRev = revPropList.size() + index;
				List<String> formPropList = propBean.getFormRelPropList();
				int indexForm = formPropList.size() + indexRev;
				List<String> propIsMust = propBean.getPropIsMust();
				//HashMap<String, String> propValueMapping = new HashMap<String, String>();
				TableItem items[] = this.propTable.getItems();
				JFomLovBean lovBean = null;
				int indexOf = 0;
				// 设置ITEM的属性
				for (int i = 0; i < index; i++) {
					if(propIsMust.get(i).toUpperCase().equals("T")){
						//lovBean = this.lovBeanList.get(i);
						if (lovBean == null) {
							if(items[i].getText(1).trim().isEmpty()){
								return false;
							}
								
						} else {
							indexOf = lovBean.getDisValueList().indexOf(
									items[i].getText(1));
							if (indexOf != -1)
								return false;
						}
					}
				}
				
				// 设置ITEMREV的属性
				for (int i = index; i < indexRev; i++) {
					if(propIsMust.get(i).toUpperCase().equals("T")){
						//lovBean = this.lovBeanList.get(i);
						if (lovBean == null) {
							
							if(items[i].getText(1).trim().isEmpty()){
								return false;
							}
						} else {
							indexOf = lovBean.getDisValueList().indexOf(
									items[i].getText(1));
							if (indexOf != -1)
								return false;
						}
					}
				}
				
				
				// 设置ITEMREVMASTER的属性
				for (int i = indexRev; i < indexForm; i++) {
					if(propIsMust.get(i).toUpperCase().equals("T")){
						//lovBean = this.lovBeanList.get(i);
						if (lovBean == null) {
							if(items[i].getText(1).trim().isEmpty()){
								return false;
							}	
						} else {
							indexOf = lovBean.getDisValueList().indexOf(
									items[i].getText(1));
							if (indexOf != -1) {
								return false;
								
							}
						}
					}
				}
			}
		} catch (TCException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return isOk;
	}
	
	
	

	/**
	 * 
	 * @return
	 */
	private boolean isMust() {
		boolean isOk = true;
		List<String> itemPropList = propBean.getItemRelPropList();
		int index = itemPropList.size();
		List<String> revPropList = propBean.getRevRelPropList();
		int indexRev = revPropList.size() + index;
		List<String> formPropList = propBean.getFormRelPropList();
		int indexForm = formPropList.size() + indexRev;
		HashMap<String, String> propValueMapping = new HashMap<String, String>();
		TableItem items[] = this.propTable.getItems();
		int indexOf = 0;
		for (int i = indexRev; i < indexForm; i++) {
			JFomLovBean lovBean = this.lovBeanList.get(i);
			if (lovBean == null) {
				propValueMapping.put(formPropList.get(i - indexRev),
						items[i].getText(1));

			} else {
				indexOf = lovBean.getDisValueList()
						.indexOf(items[i].getText(1));
				if (indexOf != -1) {
					propValueMapping.put(formPropList.get(i - indexRev),
							lovBean.getValueList().get(indexOf));

				}
			}
		}
		if (propValueMapping.containsKey("jf3_wllym")) {
			String value = propValueMapping.get("jf3_wllym");
			if (value != null && !value.trim().equals("")) {
				isOk = true;
			} else {
				isOk = false;
			}
		}

		return isOk;

	}

	private boolean beforeGetNewSequenceNo() {
		if (selectedSegmentNode.getPackCodeNodeInfo().getNode_type()
				.equals(AutoCodeManagerPropertyName.ListName)) {
			if (listView != null) {
				Combo[] propCombos = listView.getPropertyComb();
				Label[] propLabels = listView.getPropertyLabel();
				if ((propCombos != null) && (propCombos.length > 0)) {
					for (int i = 0; i < propCombos.length; i++) {
						if (propCombos[i].getSelectionIndex() == -1) {
							if ((propCombos[i].getText() != null)
									&& (propCombos[i].getText().length() == 0)) {
								MessageBox.post("【" + propLabels[i].getText()
										+ "】必填！", "INFO", MessageBox.WARNING);
								return false;
							}
						}
					}
				}
			}
		}
		if (selectedSegmentNode.getPackCodeNodeInfo().getNode_type()
				.equals(AutoCodeManagerPropertyName.TreeName)) {
			if (TCPreferenceUitl.isTrueTCPreferenceValue(session,
					origin_isNewItemMustLastNode)) {
				int childrenNum = icoTreeData.getChildrenDatas().length;
				if (childrenNum > 0) {
					MessageBox.post("请选择末端节点!", "INFO", MessageBox.WARNING);
					return false;
				}
			}
		}
		String tezh = idText.getText();
		if ((tezh == null) || (tezh.trim().length() == 0)) {
			MessageBox.post("特征码不能为空!", "INFO", MessageBox.WARNING);
			return false;
		}
		return true;
	}
	
	/**
	 * 生成九阳新ID
	 * @param newID
	 * @return
	 */
	private String getJYNewID(String newID){
		String jyNewID =newID;
		if(cpxText!=null){
			jyNewID = jyNewID.replace(CPX, cpxText.getText());
		}
		if(nfText !=null){
			jyNewID = jyNewID.replace(NF, nfText.getText().substring(2, 4)+"-");
		}
		if(cpxText2 !=null){
			String cpx = cpxText2.getText();
			String value = jyCPXMap.get(cpx);
			jyNewID = jyNewID.replace(CPX2, value+"-");
		}
		return jyNewID;
	}

	public void createPressed() {
		try {
			if(checkClassficationICO()){
				MessageBox.post("分类库中存在相同属性的分类对象,请重新填写分类属性!", "INFO", MessageBox.WARNING);
				return ;
			}
			if (!beforeGetNewSequenceNo()) {
				return;
			}
			if(cpxText2!=null && cpxText2.getText().trim().isEmpty()){
				MessageBox.post("请填写[产品线]!", "INFO", MessageBox.WARNING);
				return;
			}
			if(cpxText!=null && cpxText.getText().trim().isEmpty()){
				MessageBox.post("请填写[产品代码]!", "INFO", MessageBox.WARNING);
				return;
			}
			if(nfText !=null && nfText.getText().trim().isEmpty()){
				MessageBox.post("请填写[年份]!", "INFO", MessageBox.WARNING);
				return;
			}
			// if (!isMust()) {
			// MessageBox.post("请填写[物料来源码]属性!", "INFO", MessageBox.WARNING);
			// return;
			// }
			if (TCPreferenceUitl.isTrueTCPreferenceValue(session,
					origin_isMustSelecteUnit)) {
				if (unitCombo != null && unitCombo.isEnabled()) {
					if ((unitCombo.getSelectionIndex() == -1)
							|| (unitCombo.getText().trim().length() == 0)) {
						MessageBox.post("请选择单位!", "INFO", MessageBox.WARNING);
						return;
					}
				}
			}
			String tezh = idText.getText();
			String nameTextValue = nameText.getText();
			String type = tccomponentitemtype.getType();
			if (!type.equals("TM2_powder"))
				if ((nameTextValue == null)
						|| (nameTextValue.trim().length() == 0)) {
					MessageBox.post("名称不能为空!", "INFO", MessageBox.WARNING);
					return;
				}
			pattern = tezh.replaceAll(" ", "");

			if (treeViewOperation.getSelectedTreeNode(classificationTreeViewer) == null) {
				return;
			}
			String realItemType = "Item";
			if (segmentItemType != null) {
				realItemType = (String) segmentItemType
						.get(selectedSegmentNode);
			}

			// if (codeStyle.contains(AutoCodeManagerPropertyName.Code_seq)) {

			// while (newID == null || tccomponentitemtype.find(newID) != null)
			// {
			getSequenceNo(realItemType);
			// }
			// }

			if ((newID == null) || (newID.trim().length() == 0)) {
				MessageBox.post("ID不能为空!", "INFO", MessageBox.WARNING);
				return;
			}
			
			//NEW_ID:
			int ii = 0;
			while (tccomponentitemtype.find(getJYNewID(newID)) != null && ii!=5) {
				ii ++;
				System.out.println("newID = " + newID + "已经存在");
				getSequenceNo(realItemType);
				if ((newID == null) || (newID.trim().length() == 0)) {
					MessageBox.post("ID不能为空!", "INFO", MessageBox.WARNING);
					return;
				}
				new GetCodeNumber().delete_recycleID(counterID);
				try {
					new Thread().sleep(500);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				System.out.println("-------");
			}
			tccomponentitemtype = (TCComponentItemType) (session
					.getTypeComponent(realItemType));
			TCComponentItem oldItem = tccomponentitemtype.find(getJYNewID(newID));
			if (oldItem != null) {
				MessageBox.post("ID为【" + getJYNewID(newID) + "】的物料已经存在!", "INFO",
						MessageBox.WARNING);
				new GetCodeNumber().delete_recycleID(counterID);
				return;
			}
			long time11 = System.nanoTime();

			if (!TCPreferenceUitl.isSelectExsitToTCPreferenceValues(session,
					origin_idNeddExamineAndApproveTypes, realItemType)) {
				if(this.isCreateTempItem){
					try {
						String itemID = null;
						do{
							itemID = new GetCodeNumber().getCodeNumber(
									"LS-", 8, 0,
									999999999, 1, "");
						}while(tccomponentitemtype.find(itemID)!=null);
						
						createNewItem(itemID, revText.getText(), "JK8LSMaterial",
								nameText.getText(), "");
						
					} catch (ServiceException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}else{
				
				createNewItem(getJYNewID(newID), revText.getText(), realItemType,
						nameText.getText(), "");
				}
			} else {
				createNewItem(tccomponentitemtype.getNewID(),
						revText.getText(), realItemType, nameText.getText(), "");
			}
			long time12 = System.nanoTime();
			System.out.println("创建item用时(ms)： " + (time12 - time11) / 1000000);

			
				
			
			if (newComp != null) {
				sendObjToClassfication((TCComponentItem)newComp);
				newComp.refresh();
				new GetCodeNumber().delete_recycleID(counterID);
				setClipboard(newID);
				PackCodeDescInfos packCodeDescInfos = new PackCodeDescInfos();
				// packCodeDescInfos.setCodeStyle(codeStyle);
				packCodeDescInfos.setCodeStyle(finalPattern);
				packCodeDescInfos.setCodetz(codeCounterName.replace(" ", "")
						.trim());
				packCodeDescInfos.setGenerateID(newID);
				packCodeDescInfos.setIdDesc(DescText.getText());
				packCodeDescInfos.setIdjl(counterID);
				packCodeDescInfos.setSelectedSegmentNode(selectedSegmentNode);

				ORSaveObjectDescOperation orSaveObjectDescOperation = new ORSaveObjectDescOperation(
						newComp);
				orSaveObjectDescOperation.saveObject_Desc(packCodeDescInfos);
				if (TCPreferenceUitl.isTrueTCPreferenceValue(session,
						origin_isShowPCUnitLast)) {
					if ((unitCombo != null)
							&& (unitCombo.getSelectionIndex() >= 0)
							&& (unitCombo.getSelectionIndex() != (units.length))) {
						orSaveObjectDescOperation.saveUom_tag(units[unitCombo
								.getSelectionIndex()]);
					}
				} else {
					if ((unitCombo != null)
							&& (unitCombo.getSelectionIndex() > 0)) {
						orSaveObjectDescOperation.saveUom_tag(units[unitCombo
								.getSelectionIndex() - 1]);
					}
				}
				if (TCPreferenceUitl.isTrueTCPreferenceValue(session,
						origin_sendToClassification_Automatic)) {
					long time31 = System.nanoTime();
					if (!TCPreferenceUitl.isSelectExsitToTCPreferenceValues(
							session, origin_sendToClassification_excludeType,
							newComp.getType())) {
						AbstractTreeData selectedSegment = treeViewOperation
								.getSelectedTreeNode(classificationTreeViewer);
						if (selectedSegment.getPackCodeNodeInfo()
								.getNode_type()
								.equals(AutoCodeManagerPropertyName.ListName)) {
							new ORCreateICOObject().createListNodeICObject(
									selectedSegment, firstListICOName,
									firstListICOName,
									(TCComponentItem) newComp, icoPropertyMap);
						} else if (selectedSegment.getPackCodeNodeInfo()
								.getNode_type()
								.equals(AutoCodeManagerPropertyName.TreeName)) {
							if (TCPreferenceUitl
									.isSelectExsitToTCPreferenceValues(session,
											origin_sendToPreviousTreeNode,
											newComp.getType())) {
								new ORCreateICOObject().createTreeNodeICObject(
										icoTreeData.getParentTreeData()
												.getParentTreeData(),
										icoTreeData.getParentTreeData(),
										(TCComponentItem) newComp,
										icoPropertyMap);
							} else {
								new ORCreateICOObject().createTreeNodeICObject(
										icoTreeData.getParentTreeData(),
										icoTreeData, (TCComponentItem) newComp,
										icoPropertyMap);
							}
						}
					} else {
						MessageBox.post("零组件" + newComp + "创建成功!", "INFO",
								MessageBox.WARNING);
					}
					long time32 = System.nanoTime();
					System.out.println("分类总用时(ms)： " + (time32 - time31)
							/ 1000000);
				} else {
					MessageBox.post("零组件" + newComp + "创建成功!", "INFO",
							MessageBox.WARNING);
				}
				orCustomizationAction();
			} else {
				MessageBox.post("零组件创建失败!", "INFO", MessageBox.WARNING);
			}
		} catch (TCException e) {
			e.printStackTrace();
			MessageBox.post("创建异常:" + e.getMessage(), "INFO",
					MessageBox.WARNING);
		}
	}

	@Override
	protected int getShellStyle() {
		return super.getShellStyle() | SWT.RESIZE | SWT.MAX;
	}

	@Override
	public boolean close() {
		return super.close();
	}

	// 设置对话框初始大小
	@Override
	protected Point getInitialSize() {
		return new Point(800, 500);
	}

	protected void createButtonsForButtonBar(final Composite parent) {
		
		if ((newItemDialog != null) || (orNewItemInfoPanel != null)
				|| (packCodeDescInfos != null)) {
			this.isCreateTempItemButton =	createButton(parent, IDialogConstants.FINISH_ID, "新建临时物料", false);
			createButton(parent, IDialogConstants.YES_ID, "生成ID", false);
			createButton(parent, IDialogConstants.CANCEL_ID, "取消", false);
		} else {
			session = (TCSession) AIFUtility.getCurrentApplication()
					.getSession();
			String origin_newItemButtonName = "origin_newItemButtonName";
			String name = TCPreferenceUitl.getTCPreferenceValue(session,
					origin_newItemButtonName);
			
			this.isCreateTempItemButton  = createButton(parent, IDialogConstants.FINISH_ID, "新建临时物料", false);
			
			if ((name != null) && (name.trim().length() > 0)) {
				createButton(parent, IDialogConstants.YES_ID, name, false);
			} else {
				createButton(parent, IDialogConstants.YES_ID, "新建", false);
			}
			
			createButton(parent, IDialogConstants.CANCEL_ID, "取消", false);
		}
		String isCanTeam  =TCPreferenceUitl.getTCPreferenceValue(session, connor_isCanCreateTempMaterial);
		
		if((isCanTeam != null) && (isCanTeam.trim().length() > 0) && isCanTeam.toLowerCase().equals("true")){
			this.isCreateTempItemButton .setVisible(true);
		}else{
			this.isCreateTempItemButton .setVisible(false);
		}
		
	}

	public void setClipboard(String str) {
		try {
			if (!"".equals(str)) {
				StringSelection ss = new StringSelection(str);
				Toolkit.getDefaultToolkit().getSystemClipboard()
						.setContents(ss, null);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
