/**
 * @author tyl
 * @Action  ini
 * 2011-3-17
 */
package cn.com.origin.autocodemanager.views.testview;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
import cn.com.origin.autocodemanager.common.AutoCodeManagerPropertyName;
import cn.com.origin.autocodemanager.common.CreateCompositeUtil;
import cn.com.origin.autocodemanager.common.TCPreferenceUitl;
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.codeview.NewCodeTestView;
import cn.com.origin.autocodemanager.views.listcodeview.NewItemListCodeView;
import cn.com.origin.autocodemanager.views.treecodeview.NewItemTreeCodeView;

import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException;

public class CreateCodeTestView {
	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 NewCodeTestView 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 String pattern = "";
	private String codeDesc = "";
	private String codeStyle = "";
	private String newSeq = "";
	private int codeLength;
	private String firstListICOName = "";
	private Map<AbstractTreeData, String> segmentItemType;
	private String origin_isCodePatternCanEditTypes = "origin_isCodePatternCanEditTypes";
	private String origin_showUnit_excludeTypes = "origin_showUnit_excludeTypes";
	private String origin_isItemNameTextDefaultNull = "origin_isItemNameTextDefaultNull";
	private SashForm itemInfoComposite;
	private SashForm sashFormClassfication;

	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 CreateCodeTestView(Composite composite, String rootName, ViewPart viewPart) {
		treeViewOperation = new TreeViewOperation();
		treeAndListCodeOperation = new TreeAndListCodeOperation();
		session = (TCSession) AIFUtility.getCurrentApplication().getSession();
		try {
			tccomponentitemtype = (TCComponentItemType) (session.getTypeComponent("Item"));
		} catch (TCException e) {
			e.printStackTrace();
		}
		createDialogArea(composite);
	}

	protected Control createDialogArea(Composite parent) {
		Composite container = parent;
		FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);
		container.setLayout(fillLayout);
		sashFormClassfication = new SashForm(container, SWT.NONE);
		// SashForm sashFormClassfication = new SashForm(container, SWT.BORDER | SWT.H_SCROLL);
		// sashFormClassfication.setOrientation(SWT.HORIZONTAL);
		classificationView = new NewCodeTestView(sashFormClassfication, "编码规则");
		
		classificationTreeViewer = classificationView.treeViewer;
		addMouseAction();
		sashFormCodeView = new SashForm(container, SWT.NONE);
		GridData gridData9 = new GridData();
		gridData9.heightHint = 70;
		gridData9.horizontalAlignment = GridData.FILL;
		gridData9.verticalAlignment = GridData.CENTER;
		gridData9.grabExcessHorizontalSpace = true;

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

		codeTreeCTab = new CTabItem(ctabFolder, SWT.NONE);
		codeTreeCTab.setText("编码树");
		compositCodeTree = new Composite(ctabFolder, SWT.NONE);
		compositCodeTree.setBackground(new Color(Display.getCurrent(), 255, 255, 255));
		
		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);
		return container;
	}

	private void createNewItemInfo(Composite parent) {
		Composite 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, "");

		CreateCompositeUtil.createNewLabel(composite, "物料版本");
		revText = CreateCompositeUtil.createNewText(composite, "");

		CreateCompositeUtil.createNewLabel(composite, "物料名称");
		nameText = CreateCompositeUtil.createNewText(composite, "");
		CreateCompositeUtil.createNewLabel(composite, "描述");
		DescText = CreateCompositeUtil.createTextArea(composite, "", 90, 300);
		idText.setEnabled(false);
		idLengthText.setEnabled(false);
		revText.setEnabled(false);
		DescText.setEnabled(false);
	}

	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) {
				try {
					initClassificationMouseClick();
					selectedSegmentNode = treeViewOperation.getSelectedTreeNode(classificationTreeViewer);
					if (selectedSegmentNode == null) {
						return;
					}
					selectedSegmentTCComponent = selectedSegmentNode.getPackCodeNodeInfo().getNodeComponent();
					if (selectedSegmentTCComponent == null) {
						return;
					}
					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();
						if (TCPreferenceUitl.isSelectExsitToTCPreferenceValues(session, origin_showUnit_excludeTypes, realType)) {
							unitCombo.setEnabled(false);
						}
					}
					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) {
								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();
								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(selectedSegmentNode.getPackCodeNodeInfo().getNodeComponent());
								getSequenceNo(pattern, selectedData.getPackCodeNodeInfo().getNodeComponent());
								idText.setText(getID(codeStyle));
								setIDPatternTextIsCanEdit();
								idLengthText.setText(String.valueOf(idText.getText().replace(" ", "").trim().length()));
								DescText.setText(codeDesc);
							}
						});
					} 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();
											revText.setText(tccomponentitemtype.getNewRev(null));

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

											if (!TCPreferenceUitl.isTrueTCPreferenceValue(session, origin_isItemNameTextDefaultNull)) {
												nameText.setText(firstListICOName);
											} else {
												nameText.setText("");
											}
											getFinalPattern(selectedSegmentNode.getPackCodeNodeInfo().getNodeComponent());
											getSequenceNo(pattern, selectedSegmentNode.getPackCodeNodeInfo().getNodeComponent());
											idText.setText(getID(codeStyle));
											setIDPatternTextIsCanEdit();
											idLengthText.setText(String.valueOf(idText.getText().replace(" ", "").trim().length()));
											DescText.setText(codeDesc);
										} catch (Exception e1) {
											e1.printStackTrace();
										}
									}
								});
							}
						}
					}
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		});
	}

	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";
				}
			}
		}
	}

	private void initTreeOrListMouseClick() {
		try {
			if (treeViewOperation.getSelectedTreeNode(classificationTreeViewer) == null) {
				return;
			}
			pattern = "";
			codeDesc = "";
			newSeq = "";
			DescText.setText("");
			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;
			}
			pattern = "";
			codeDesc = "";
			pattern = "";
			newSeq = "";
			DescText.setText("");
			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;
	}

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

	private String getFinalPattern(TCComponent seqComponent) {
		newSeq = "";
		int codeSeqLength = 0;
		try {
			if (seqComponent != null) {
				String[] propNames = { AutoCodeManagerPropertyName.TreeAndListCodeNode_code_style, AutoCodeManagerPropertyName.TreeAndListCodeNode_code_length, AutoCodeManagerPropertyName.TreeAndListCodeNode_seq_length };
				String[] propValues = seqComponent.getProperties(propNames);
				codeStyle = propValues[0];
				codeLength = Integer.valueOf(propValues[1]);
				codeSeqLength = Integer.valueOf(propValues[2]);
			}
		} catch (TCException e) {
			e.printStackTrace();
		}
		String finalPattern = replaceSpecialValue(codeStyle);
		int coverNum = codeLength - finalPattern.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 + " ";
			}
		}
		return pattern;
	}

	private String getSequenceNo(String codeCounterName, TCComponent selectedComponent) {
		try {
			codeCounterName = codeCounterName.replace(" ", "").trim();
			TCComponent seqComponent = selectedComponent.getReferenceProperty(AutoCodeManagerPropertyName.TreeAndListCodeNode_rule_node);
			if (seqComponent != null) {
				String[] propNames = { AutoCodeManagerPropertyName.TreeAndListCodeNode_code_style, AutoCodeManagerPropertyName.TreeAndListCodeNode_code_length, AutoCodeManagerPropertyName.TreeAndListCodeNode_seq_begin_value, AutoCodeManagerPropertyName.TreeAndListCodeNode_seq_length,
						AutoCodeManagerPropertyName.TreeAndListCodeNode_seq_max_value };
				String[] propValues = seqComponent.getProperties(propNames);
				codeStyle = propValues[0];
				codeLength = Integer.valueOf(propValues[1]);
				int startValue = Integer.valueOf(propValues[2]);
				int codeSeqLength = Integer.valueOf(propValues[3]);
				int endValue = Integer.valueOf(propValues[4]);
				int increaseStep = 1;
				String excludeStr = "";
				int seqValue = startValue + increaseStep;
				if (seqValue > endValue) {
					seqValue = startValue;
				}
				String seqStr = String.valueOf(seqValue);
				if (excludeStr.length() > 0) {
					int exclude = Integer.valueOf(excludeStr);

					if (seqStr.contains(excludeStr)) {
						seqStr.replace(excludeStr, String.valueOf(exclude++));
					}
				}
				int length1 = seqStr.length();
				if (codeSeqLength > 0) {
					if (length1 > codeSeqLength) {
						newSeq = seqStr.substring(0, codeSeqLength - 1);
					} else {
						newSeq = seqStr;
						for (int i = 0; i < (codeSeqLength - length1); i++) {
							newSeq = "0" + newSeq;
						}
					}
				}
			}
		} catch (TCException e) {
			e.printStackTrace();
			return newSeq;
		}
		return newSeq;
	}
}
