package com.connor.rb.plm.rb007; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTextField; import javax.swing.JTree; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeNode; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import com.connor.rb.plm.entity.ZC_LBJ_list; import com.connor.rb.plm.newcombox.RwJComboBox; import com.connor.rb.plm.rb012.SearchJComItem; import com.connor.rb.plm.util.ClassAttributeBean; import com.connor.rb.plm.util.ClassProperty; import com.connor.rb.plm.util.CodeBean; import com.connor.rb.plm.util.GetCodeBean; import com.connor.rb.plm.util.MenuBean; import com.connor.rb.plm.util.ParseXML; import com.connor.rb.plm.util.PlmLocaleUtil; import com.connor.rb.plm.util.SoaServerUtil; import com.teamcenter.rac.aif.AbstractAIFApplication; import com.teamcenter.rac.aif.AbstractAIFDialog; import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; import com.teamcenter.rac.common.tcviewer.multiplenamedrefs.MultipleNamedReferencesComboBox; import com.teamcenter.rac.kernel.TCClassificationService; import com.teamcenter.rac.kernel.TCComponent; import com.teamcenter.rac.kernel.TCComponentBOMLine; import com.teamcenter.rac.kernel.TCComponentBOMWindow; import com.teamcenter.rac.kernel.TCComponentBOMWindowType; import com.teamcenter.rac.kernel.TCComponentICO; import com.teamcenter.rac.kernel.TCComponentItem; import com.teamcenter.rac.kernel.TCComponentItemRevision; import com.teamcenter.rac.kernel.TCComponentItemType; import com.teamcenter.rac.kernel.TCComponentListOfValues; import com.teamcenter.rac.kernel.TCComponentQuery; import com.teamcenter.rac.kernel.TCComponentQueryType; import com.teamcenter.rac.kernel.TCException; import com.teamcenter.rac.kernel.TCPreferenceService; import com.teamcenter.rac.kernel.TCProperty; import com.teamcenter.rac.kernel.TCSession; import com.teamcenter.rac.kernel.TCTypeService; import com.teamcenter.rac.kernel.ics.ICSAdminClass; import com.teamcenter.rac.kernel.ics.ICSAdminClassAttribute; import com.teamcenter.rac.kernel.ics.ICSKeyLov; import com.teamcenter.rac.kernel.ics.ICSProperty; import com.teamcenter.rac.util.MessageBox; import com.teamcenter.rac.util.PropertyLayout; import cn.com.origin.autocodemanager.common.CreateCompositeUtil; public class Rb007Dialog extends AbstractAIFDialog { private AbstractAIFApplication app; private TCSession session; private TCPreferenceService service; private String name; private MenuBean menuBean; private JPanel jp1; private JPanel jp2; private JPanel classJpanel; private List> values; private List classList = new ArrayList(); // private List codeBeanList; private CodeBean selCodeBean; private JButton okBut = new JButton("确定"); private JButton button2 = new JButton("图纸引用"); private JButton celBut = new JButton("取消"); private GetCodeBean getcode; private JLabel[] labels1 = null; //private JComboBox comb = null; private String url = ""; private JScrollPane scr2; private boolean classFlag = true; private boolean classFlag2 = false; private Map map2; private Map> boxMap = new HashMap>(); private List revList = new ArrayList(); private List idList = new ArrayList(); private List typeList = new ArrayList(); private JLabel nameLabel; private JComboBox nameComb; private JLabel idLabel; private JTextField idField1; private JLabel revLabel; private JComboBox revBox; private String className2; private TCComponentItemRevision targetItem; private String productNumber = ""; private String drawingNumber = ""; private String HeatTreatment = ""; private Map> attrMap; private Map> attrMap2; private Map objMap = new HashMap(); private Map objMap2 = new HashMap(); private Map lovMap = new HashMap(); private Map lovMap2 = new HashMap(); private List attrList = new ArrayList(); private List esAttrList = new ArrayList(); // private List objList = new ArrayList(); // private List lovList = new ArrayList(); private List attrList2 = new ArrayList(); private List esAttrList2 = new ArrayList(); // private List objList2 = new ArrayList(); // private List lovList2 = new ArrayList(); private List markList = new ArrayList(); private List markList2 = new ArrayList(); private List isNList = new ArrayList(); private List isNList2 = new ArrayList(); private List defaultValueList = new ArrayList(); private List defaultValueList2 = new ArrayList(); private List asList = new ArrayList(); private List esList = new ArrayList(); //优化 private int v=0; private Map lishu_lov=ZC_LBJ_list.LiShu_lov; private Map lishu=ZC_LBJ_list.LiShu; private Map zc_pro_map=new HashMap();//总成的属性键值对 //TextField集合 private List fieldList=new ArrayList(); //box集合 private List comboxList=new ArrayList(); private Map fieldmap=new HashMap<>(); private Map comboxmap=new HashMap<>(); //end优化 // private String[] lovVal = new String[] { "无前辍", "标准钢球", "无接触角", "开式", "不带通气孔", "A:NBR", "0:黑", "无", "球引导", // "SN:180℃±5℃回火", "常规整体马氏体淬火热处理", "单套", "S:(25% to 35%)", "C0","V0","Z0","标准","PC:达到集团C&U品牌精度要求" // ,"P0:达到集团C&U品牌精度要求","其他结构需要编制规则","0:双列角接触球轴承","不标:SECC或者相当材料","其他材料:与部门团队确认审批","BC:35°"}; // private String[] esLovVal = new String[] { "Non", "Standard ball", "Non", "Open", "Without vent hole", "A:NBR", // "0:Black", "Non", "Ball", "SN:180℃±5℃ temper","Conventional monolithic martensite quenching heat treatment", // "Single", "S:(25% to 35%)", "C0","V0","Z0","Standard","PC:Meet the group C&U brand accuracy requirements" // ,"P0:Meet the group C&U brand accuracy requirements","Other structures need to formulate rules","0:Double row angular contact ball bearing" // ,"Not marked: SECC or equivalent","Other materials: confirm with department team for approval","BC:35°"}; public Rb007Dialog(AbstractAIFApplication app, String name) { super(false); this.app = app; this.session = (TCSession) app.getSession(); this.service = session.getPreferenceService(); this.name = name; this.values = new ArrayList>(); this.url = service.getStringValue("Autocode_SendClassServer_URL"); } @Override public void run() { // TODO Auto-generated method stub getcode = new GetCodeBean(session); menuBean = getcode.getMenuBean(name); // codeBeanList = bean.getCodeBeanList(); try { String lovVal = service.getStringValue("RB3_lovVal_default"); String esLovVal = service.getStringValue("RB3_esLovVal_default"); if(lovVal.contains(";")) { String[] vals = lovVal.split(";"); String[] esVals = esLovVal.split(";"); for (int i = 0; i < vals.length; i++) { asList.add(vals[i]); esList.add(esVals[i]); } } ParseXML xml = new ParseXML(); File file = xml.getSXX("RB3_CPHPJFS", session); attrMap = xml.parseXMLAttr(file); if (attrMap == null || attrMap.size() <= 0) { MessageBox.post("首选项RB3_CPHPJFS未配置,请检查!", "WARNING", MessageBox.WARNING); return; } File file2 = xml.getSXX("RB3_THPJFS", session); attrMap2 = xml.parseXMLAttr(file2); if (attrMap2 == null || attrMap2.size() <= 0) { MessageBox.post("首选项RB3_THPJFS未配置,请检查!", "WARNING", MessageBox.WARNING); return; } InterfaceAIFComponent targetComp = app.getTargetComponent(); if (targetComp instanceof TCComponentItemRevision) { targetItem = (TCComponentItemRevision) targetComp; //优化 zc_pro_map=targetItem.getProperties(); //end } init(); } catch (TCException e) { // TODO Auto-generated catch block MessageBox.post("init()出现异常","WARNING",MessageBox.WARNING); e.printStackTrace(); } } /** * 主页面 * * @throws TCException */ private void init() throws TCException{ // TODO Auto-generated method stub this.setTitle(name); //this.setMinimumSize(new Dimension(860,900)); this.setPreferredSize(new Dimension(860, 900)); // this.setLayout(new PropertyLayout()); this.setLayout(new BorderLayout()); classJpanel = new JPanel(new BorderLayout());// 属性界面 jp1 = new JPanel(new BorderLayout()); jp2 = new JPanel(new PropertyLayout()); jp1.setPreferredSize(new Dimension(200, 820)); scr2 = new JScrollPane(jp2); scr2.setPreferredSize(new Dimension(640, 820)); classJpanel.add(scr2); // jp2.setPreferredSize(new Dimension(350, 600)); JTree tree = getTree(menuBean); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { // objList.clear(); // objList2.clear(); // lovList.clear(); // lovList2.clear(); classFlag = true; classFlag2 = false; objMap.clear(); objMap2.clear(); //zc_pro_map.clear(); fieldList.clear(); comboxList.clear(); fieldmap.clear(); comboxmap.clear(); // lovMap.clear(); lovMap2.clear(); attrList.clear(); esAttrList.clear(); attrList2.clear(); esAttrList2.clear(); classList.clear(); markList.clear(); markList2.clear(); isNList.clear(); isNList2.clear(); defaultValueList.clear(); defaultValueList2.clear(); jp2.removeAll(); idList.clear(); DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) e.getPath().getLastPathComponent(); int childCount = treeNode.getChildCount(); System.out.println("当前被选中的节点: " + treeNode + " 子节点数量:" + childCount); if (childCount > 0) { jp2.setVisible(false); } else { String names = getNode(treeNode, ""); selCodeBean = getcode.getCodebean(names); if (selCodeBean == null) { MessageBox.post("请选择最底层节点!!!", "提示", MessageBox.INFORMATION); return; } JTextField idfield = new JTextField(18); idList.add(idfield); JComboBox idbox = new JComboBox(); idList.add(idbox); idbox.addItem(" "); String[] idstrs = new String[99]; for (int j = 0; j < 99; j++) { if (j < 9) { idstrs[j] = "0" + (j + 1); } else { idstrs[j] = (j + 1) + ""; } } for (int j = 0; j < idstrs.length; j++) { idbox.addItem(idstrs[j]); } boxMap.put(PlmLocaleUtil.getString("PartNumber"), idbox); revLabel = new JLabel("版本:"); revBox = new JComboBox(); revBox.setEditable(false); revBox.addItem("B1"); String[] revs = service.getStringValues("RB_Revision_id"); if (revs == null || revs.length <= 0) { MessageBox.post("首选项RB_Revision_id未配置,请联系管理员!!", "错误", MessageBox.ERROR); return; } for (int i = 0; i < revs.length; i++) { revBox.addItem(revs[i]); } nameLabel = new JLabel("名称:"); nameComb = new JComboBox(); nameComb.setEditable(false); nameComb.addItem(""); String[] lbjNames = service.getStringValues("RB3_LBJ_names"); if (lbjNames == null || lbjNames.length <= 0) { MessageBox.post("首选项RB3_LBJ_names未配置,请联系管理员!!", "错误", MessageBox.ERROR); return; } for (int i = 0; i < lbjNames.length; i++) { nameComb.addItem(lbjNames[i]); } //优化 nameComb.setSelectedIndex(1); //end优化 idLabel = new JLabel("总成物料编码:"); idField1 = new JTextField(18); //优化 try { idField1.setText(targetItem.getProperty("item_id")); } catch (TCException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } //end优化 jp2.add("1.1.center.center", new JLabel("")); jp2.add("2.1.center.center", idLabel); jp2.add("2.2.center.center", idField1); jp2.add("3.1.center.center", nameLabel); jp2.add("3.2.center.center", nameComb); jp2.add("4.1.center.center", new JLabel(PlmLocaleUtil.getString("PartNumber"))); jp2.add("4.2.center.center", idfield); jp2.add("4.3.center.center", idbox); jp2.add("5.1.center.center", revLabel); jp2.add("5.2.center.center", revBox); try { String className = targetItem.getClassificationClass(); TCClassificationService classificationService = session.getClassificationService(); ICSAdminClass c = classificationService.newICSAdminClass(); System.out.println("className============" + className); c.load(className); ICSAdminClassAttribute[] icsAttrS = c.getAttributes(); // 获取分类属性 TCComponentICO[] icos = targetItem.getClassificationObjects(); System.out.print("icos:====" + icos); if (icos == null || icos.length <= 0) { MessageBox.post("选中的物料没有发送到分类,请发送!!!", "提示", MessageBox.INFORMATION); return; } Map claMap = new HashMap(); if (icos != null && icos.length > 0) { ICSProperty[] icss = icos[0].getICSProperties(true); for (ICSProperty ics : icss) { for (ICSAdminClassAttribute icsa : icsAttrS) { if (icsa.getAttributeId() == ics.getId()) { System.out.print("icsa.getName():" + icsa.getName()); claMap.put(icsa.getName(), ics.getValue()); } } } } ICSAdminClass c2 = classificationService.newICSAdminClass(); className2 = selCodeBean.getClassID(); // String xmlClassName = className2.substring(0, 6); System.out.println("className2===========" + className2); // System.out.println("xmlClassName==========="+xmlClassName); if (attrMap.containsKey(className2)) { List nameMarkList = attrMap.get(className2); String attrNames = nameMarkList.get(0); String marks = nameMarkList.get(1); String defaultValues = nameMarkList.get(2); String isN = nameMarkList.get(3); if (attrNames.contains(";")) { String[] attrs = attrNames.split(";"); String[] markss = marks.split(";"); String[] valuess = defaultValues.split(";"); String[] isNs = isN.split(";"); for (int i = 0; i < attrs.length; i++) { System.out.println("attrs==============" + attrs[i]); if (attrs[i].contains("+")) { String[] attrss = attrs[i].split("\\+"); attrList.add(attrss[0]); esAttrList.add(attrss[1]); markList.add(markss[i]); defaultValueList.add(valuess[i]); isNList.add(isNs[i]); } } } List nameMarkList2 = attrMap2.get(className2); String attrNames2 = nameMarkList2.get(0); String marks2 = nameMarkList2.get(1); String defaultValues2 = nameMarkList2.get(2); String isNs2 = nameMarkList2.get(3); System.out.println("attrNames2============" + attrNames2); if (attrNames2.contains(";")) { String[] attrs2 = attrNames2.split(";"); String[] markss2 = marks2.split(";"); String[] valuess = defaultValues2.split(";"); String[] isNs2s = isNs2.split(";"); for (int i = 0; i < attrs2.length; i++) { if (attrs2[i].contains("+")) { String[] attrss = attrs2[i].split("\\+"); attrList2.add(attrss[0]); esAttrList2.add(attrss[1]); markList2.add(markss2[i]); defaultValueList2.add(valuess[i]); isNList2.add(isNs2s[i]); } } } } c2.load(className2); String cName = c2.getName(); if (PlmLocaleUtil.getString("BearingAccessories").equals(cName)) { classFlag = false; } else if (PlmLocaleUtil.getString("Cage").equals(cName)) { classFlag2 = true; } System.out.println("cName===" + cName); ICSAdminClassAttribute[] icsAttrS2 = c2.getAttributes(); if (icsAttrS2 != null) { for (ICSAdminClassAttribute attr : icsAttrS2) { ClassAttributeBean bean = new ClassAttributeBean(); if (attr.isReferenceAttribute()) {// 引用属性 continue; } if (attr.isReference()) { continue; } int propID = attr.getAttributeId(); bean.setId(propID); String propDisName = attr.getName(); System.out.print("propDisName:" + propDisName); bean.setName(propDisName); int attrType = attr.getFormat1().getType(); bean.setType(attrType); // 设置分类属性 if (claMap != null && claMap.containsKey(propDisName)) { bean.setVal(claMap.get(propDisName)); } else { bean.setVal(""); } ICSKeyLov lov1 = attr.getFormat1().getKeyLov(); lov1 = (lov1 == null ? attr.getFormat2().getKeyLov() : lov1); if (lov1 != null) { bean.setIslov(true); String[] keys = lov1.getKeys(); Map map1 = new HashMap(); for (String key : keys) { String value = lov1.getValueOfKey(key); map1.put(value, key);// <显示值,真实值> if (key.equals(bean.getVal()) && (!bean.getVal().equals(""))) { bean.setVal(value); } } bean.setLov(map1); } else { bean.setIslov(false); } classList.add(bean); } } } catch (TCException e1) { e1.printStackTrace(); } labels1 = new JLabel[classList.size()]; System.out.print("classList.size():" + classList.size()); for (int i = 0; i < classList.size(); i++) { ClassAttributeBean bean = classList.get(i); String attrName = bean.getName(); labels1[i] = new JLabel(attrName); jp2.add((i + 6) + ".1.center.top", labels1[i]); labels1[i].setBounds(5, 5, 5, 5); String value = bean.getVal(); System.out.println("默认值为:"+value); if (bean.isIslov()) { JComboBox comb = new JComboBox(); //优化 JTextField jt=new JTextField(9); JButton bu=new JButton("搜索"); //end comb.setEditable(false); comb.setSize(new Dimension(60, 40)); if (classFlag2) { if ((PlmLocaleUtil.getString("heatTreatment")).equals(attrName)) { comb.addItem(""); HeatTreatment = value; }else { comb.addItem(value); } } else { comb.addItem(value); } for (Entry entry : bean.getLov().entrySet()) { if(i == 0) { System.out.println("entry.getKey()===="+entry.getKey()); } if (!(value.equals(entry.getKey()))) { comb.addItem(entry.getKey()); } } //优化 bu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub String tip=jt.getText(); System.out.println("搜索"+tip); if(tip.length()>0) { SearchJComItem.changeBox(comb, tip); } } }); //end map2 = new HashMap(); map2.put("JComboBox", comb); values.add(map2); jp2.add((i + 6) + ".2.center.top", comb); jp2.add((i + 6) + ".3.center.top", jt); jp2.add((i + 6) + ".4.center.top", bu); if (attrList.contains(attrName) || esAttrList.contains(attrName)) { objMap.put(attrName, comb); lovMap.put(attrName, "yes"); } if (attrList2.contains(attrName) || esAttrList2.contains(attrName)) { objMap2.put(attrName, comb); lovMap2.put(attrName, "yes"); } if ((PlmLocaleUtil.getString("Category")).equals(attrName)) { typeList.add(comb); } } else { JTextField field = new JTextField(18); field.setText(value); map2 = new HashMap(); map2.put("JTextField", field); values.add(map2); jp2.add((i + 6) + ".2.center.top", field); if ((PlmLocaleUtil.getString("RadialInternalClearance")).equals(attrName)) { JComboBox box = new JComboBox(); //优化 JTextField jt=new JTextField(9); JButton bu=new JButton("搜索"); //end box.addItem(" "); String[] strs = new String[] { "C0", "C2", "C3", "C4", "C5" }; for (int j = 0; j < strs.length; j++) { box.addItem(strs[j]); } //优化 bu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub String tip=jt.getText(); System.out.println("搜索"+tip); if(tip.length()>0) { SearchJComItem.changeBox(box, tip); } } }); boxMap.put(attrName, box); jp2.add((i + 6) + ".3.center.top", box); jp2.add((i + 6) + ".4.center.top", jt); jp2.add((i + 6) + ".5.center.top", bu); } if (attrList.contains(attrName) || esAttrList.contains(attrName)) { objMap.put(attrName, field); lovMap.put(attrName, "no"); } if (attrList2.contains(attrName) || esAttrList2.contains(attrName)) { objMap2.put(attrName, field); lovMap2.put(attrName, "no"); } } v=i+7; } //优化 jp2.add(v+".1.center.top",new JLabel(" ")); jp2.add(v+".2.center.top",new JLabel("***********对象属性***********")); v+=1; // for(String s:lishu_lov.keySet()) { // String val = lishu_lov.get(s); // jp2.add(v+".1.center.top",new JLabel(val)); // JComboBox lishu_comb=new JComboBox(); // lishu_comb.setEditable(false); // lishu_comb.setSize(new Dimension(60,40)); // try { // TCProperty zcLov_val = targetItem.getTCProperty(s); // TCComponentListOfValues lov_val = zcLov_val.getLOV(); // if(lov_val!=null) { // String[] comboxitems=lov_val.getListOfValues().getLOVDisplayValues(); // ComboBoxModel model = new DefaultComboBoxModel(comboxitems); // lishu_comb.setModel(model); // comboxList.add(lishu_comb); // } // lishu_comb.setSelectedItem(zc_pro_map.get(s)); // jp2.add(v+".2.center.top",lishu_comb); // } catch (TCException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } // lishu_comb.setName(s); // v++; // } // for(String m:lishu.keySet()) { // String val=lishu.get(m); // jp2.add(v+".1.center.top",new JLabel(val)); // JTextField jf=new JTextField(18); // jf.setName(m); // jf.setText(zc_pro_map.get(m)); // fieldList.add(jf); // jp2.add(v+".2.center.top",jf); // v++; // } for(int i=0;i disVal=new ArrayList(); String[] comboxitems; for(int a=0;a0) { StringBuilder sb=new StringBuilder(); for(int t=0;t(); zcBox.setSize(new Dimension(60,40)); zcBox.setName(ZC_LBJ_list.LBJPros.get(i)); TCProperty zclov = ((TCComponentItemRevision) targetItem).getTCProperty(ZC_LBJ_list.LBJPros.get(i)); TCComponentListOfValues zcprolov = zclov.getLOV(); String[] comboxitems; JTextField jt=new JTextField(9); JButton bu=new JButton("搜索"); if(zcprolov!=null) { comboxitems = zcprolov.getListOfValues().getLOVDisplayValues(); ComboBoxModel model = new DefaultComboBoxModel(comboxitems); zcBox.setModel(model); bu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub String tip=jt.getText(); System.out.println("搜索"+tip); if(tip.length()>0) { SearchJComItem.changeBox(zcBox, tip); } } }); comboxList.add(zcBox); } zcBox.setSelectedItem(zc_pro_map.get(ZC_LBJ_list.LBJPros.get(i))); //if(!(ZC_LBJ_list.LBJDisPros.get(i)).equals("临时物料标识")) { zcBox.setSelectedIndex(-1); //} jp2.add(v+".2.center.top",zcBox); jp2.add((v)+".3.center.top",jt); jp2.add((v)+".4.center.top",bu); } }else { JTextField field=new JTextField(18); field.setName(ZC_LBJ_list.LBJPros.get(i)); if((ZC_LBJ_list.LBJDisPros.get(i)).equals("创建用户")) { field.setText(zc_pro_map.get(ZC_LBJ_list.LBJPros.get(i))); } jp2.add(v+".2.center.top",field); fieldList.add(field); } } catch (TCException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } v++; } jp2.setVisible(true); jp2.validate(); jp2.repaint(); scr2.validate(); } } }); JScrollPane scrollPane = new JScrollPane(tree); scrollPane.setPreferredSize(new Dimension(250, 250)); // 添加滚动面板到那内容面板 jp1.add(scrollPane, BorderLayout.CENTER); //jp2.setVisible(false); classJpanel.add(scr2); JSplitPane splitPane = new JSplitPane(); splitPane.setOneTouchExpandable(true);// 让分割线显示出箭头 splitPane.setContinuousLayout(true);// 操作箭头,重绘图形 splitPane.setLeftComponent(new JScrollPane(jp1)); splitPane.setRightComponent(new JScrollPane(classJpanel)); JPanel titlePanel = new JPanel(new FlowLayout());// 属性界面 titlePanel.add(new JLabel(" ")); titlePanel.add(new JLabel(" ")); titlePanel.add( button2); titlePanel.add(new JLabel(" ")); titlePanel.add(new JLabel(" ")); titlePanel.add(okBut); titlePanel.add(new JLabel(" ")); titlePanel.add(new JLabel(" ")); titlePanel.add(celBut); this.add(splitPane, BorderLayout.CENTER); this.add(titlePanel, BorderLayout.SOUTH); // add("1.1.center.center", splitPane); // add("1.1.center.center", jp1); // add("1.2.center.center", classJpanel); // add("2.1.center.center", button2); // add("2.2.center.center", okBut); // add("2.3.center.center", celBut); button2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("准备进入分类库"); G4MDialog classDialog = new G4MDialog("人本集团", null, revList, session); new Thread(classDialog).start(); } }); okBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub createItem(); // setVisible(false); } }); celBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub System.out.println("取消"); setVisible(false); } }); this.setVisible(true); this.centerToScreen(); // this.pack(); } /* * 物料创建 */ public void createItem() { // TODO Auto-generated method stub String jhID = ""; try { if (idList != null && idList.size() > 0) { JTextField idField = (JTextField) idList.get(0); JComboBox idbox = (JComboBox) idList.get(1); String id = idField.getText(); String boxID = (String) idbox.getSelectedItem(); // if ("".equals(id.trim()) && "".equals(boxID.trim())) { // MessageBox.post("件号未填写!!!", "提示", MessageBox.INFORMATION); // return; // } if ("".equals(id.trim())) { id = boxID.trim(); } jhID = id; } String typeID = ""; if (typeList != null && typeList.size() > 0) { JComboBox idComb = typeList.get(0); typeID = (String) idComb.getSelectedItem(); if (typeID.indexOf("成品件") >= 0 || typeID.indexOf("Finished product") >= 0) { typeID = ""; } else if (typeID.indexOf("车工件") >= 0 || typeID.indexOf("Turning workpiece") >= 0) { typeID = "C"; } else if (typeID.indexOf("热处理件") >= 0 || typeID.indexOf("Heat treatment parts") >= 0) { typeID = "R"; } else if (typeID.indexOf("冷辗件或冷挤件") >= 0 || typeID.indexOf("Cold rolled parts or cold extrusion parts") >= 0) { typeID = "D"; } else if (typeID.indexOf("锻件") >= 0 || typeID.indexOf("Forge piece") >= 0) { typeID = "D"; } } String item_type = ""; if (selCodeBean != null) { item_type = selCodeBean.getType(); } else { MessageBox.post("请选择最底层节点!!!", "提示", MessageBox.INFORMATION); return; } String targetId = idField1.getText(); if ("".equals(targetId.trim())) { MessageBox.post("请填写总成物料编号!!!", "提示", MessageBox.INFORMATION); return; } String newID = targetId + jhID + typeID; String revID = (String) revBox.getSelectedItem(); String itemName = (String) nameComb.getSelectedItem(); // List asList = Arrays.asList(lovVal); // List esList = Arrays.asList(esLovVal); // StringBuilder sb = new StringBuilder(); // for (int i = 0; i < attrList.size(); i++) { // String attr = attrList.get(i); // String esAttr = esAttrList.get(i); // if(!("".equals(attr.trim()))) { // JComboBox box = null; // if((PlmLocale.getString("RadialInternalClearance")).equals(attr) // || (PlmLocale.getString("PartNumber")).equals(attr)) { // box = boxMap.get(attr); // } // Object obj = objMap.get(attr); // if(obj == null) { // JTextField field = (JTextField)objMap.get(esAttr); // if(box != null) { // String fieldText = field.getText(); // String boxText = (String) box.getSelectedItem(); // if(!("".equals(fieldText.trim())) && !("".equals(boxText.trim()))) { // MessageBox.post(esAttr+"不能同时填写两个值!!!", "提示", MessageBox.INFORMATION); // return; // } // if("".equals(fieldText.trim()) && "".equals(boxText.trim())) { // MessageBox.post(esAttr+"必须填写一个值!!!", "提示", MessageBox.INFORMATION); // return; // } // if(!("".equals(fieldText.trim()))) { // objList.add(field); // lovList.add("no"); // }else { // objList.add(box); // lovList.add("yes"); // } // }else { // objList.add(field); // lovList.add(lovMap.get(esAttr)); // } // }else { // if(box != null) { // JTextField field = (JTextField)obj; // String fieldText = field.getText(); // String boxText = (String) box.getSelectedItem(); // if(!("".equals(fieldText.trim())) && !("".equals(boxText.trim()))) { // MessageBox.post(attr+"不能同时填写两个值!!!", "提示", MessageBox.INFORMATION); // return; // } // if("".equals(fieldText.trim()) && "".equals(boxText.trim())) { // MessageBox.post(attr+"必须填写一个值!!!", "提示", MessageBox.INFORMATION); // return; // } // if(!("".equals(fieldText.trim()))) { // objList.add(field); // lovList.add("no"); // }else { // objList.add(box); // lovList.add("yes"); // } // }else { // objList.add(obj); // lovList.add(lovMap.get(attr)); // } // } // } // } // for (int i = 0; i < attrList2.size(); i++) { // String attr = attrList2.get(i); // String esAttr = esAttrList2.get(i); // if(!("".equals(attr.trim()))) { // JComboBox box = null; // if((PlmLocale.getString("RadialInternalClearance")).equals(attr) // || (PlmLocale.getString("PartNumber")).equals(attr)) { // box = boxMap.get(attr); // } // Object obj = objMap2.get(attr); // if(obj == null) { // JTextField field = (JTextField)objMap.get(esAttr); // if(box != null) { // String fieldText = field.getText(); // String boxText = (String) box.getSelectedItem(); // if(!("".equals(fieldText.trim())) && !("".equals(boxText.trim()))) { // MessageBox.post(esAttr+"不能同时填写两个值!!!", "提示", MessageBox.INFORMATION); // return; // } // if("".equals(fieldText.trim()) && "".equals(boxText.trim())) { // MessageBox.post(esAttr+"必须填写一个值!!!", "提示", MessageBox.INFORMATION); // return; // } // if(!("".equals(fieldText.trim()))) { // objList2.add(field); // lovList2.add("no"); // }else { // objList2.add(box); // lovList2.add("yes"); // } // }else { // objList2.add(field); // lovList2.add(lovMap2.get(esAttr)); // } // }else { // if(box != null) { // JTextField field = (JTextField)obj; // String fieldText = field.getText(); // String boxText = (String) box.getSelectedItem(); // if(!("".equals(fieldText.trim())) && !("".equals(boxText.trim()))) { // MessageBox.post(attr+"不能同时填写两个值!!!", "提示", MessageBox.INFORMATION); // return; // } // if("".equals(fieldText.trim()) && "".equals(boxText.trim())) { // MessageBox.post(attr+"必须填写一个值!!!", "提示", MessageBox.INFORMATION); // return; // } // if(!("".equals(fieldText.trim()))) { // objList2.add(field); // lovList2.add("no"); // }else { // objList2.add(box); // lovList2.add("yes"); // } // }else { // objList2.add(obj); // lovList2.add(lovMap2.get(attr)); // } // } // } // } // for (int i = 0; i < objList.size(); i++) { // String attrValue = ""; // if("yes".equals(lovList.get(i))) { // String value = (String) ((JComboBox) // objList.get(i)).getSelectedItem(); // if(asList.contains(value) || esList.contains(value)) { // value = ""; // }else { // if(value.contains(":")) { // String[] values = value.split(":"); // value = values[0]; // }else if(value.contains(":")) { // String[] values = value.split(":"); // value = values[0]; // } // } // if("成品件".equals(value)) { // value = ""; // }else if("车工件".equals(value)) { // value = "C"; // }else if("热处理件".equals(value)) { // value = "R"; // }else if("冷凝建".equals(value)) { // value = "L"; // }else if("锻件".equals(value)) { // value = "D"; // } // attrValue = value; // }else { // attrValue = ((JTextField) objList.get(i)).getText(); // } // String mark = markList.get(i); // sb.append(mark.trim()); // sb.append(attrValue); // System.out.println("attrValue=============="+attrValue); // } // productNumber = sb.toString(); // System.out.println("productNumber============"+productNumber); // StringBuilder sb2 = new StringBuilder(); // // for (int i = 0; i < objList2.size(); i++) { // String attrValue = ""; // if("yes".equals(lovList2.get(i))) { // String value = (String) ((JComboBox) // objList2.get(i)).getSelectedItem(); // if(asList.contains(value) || esList.contains(value)) { // value = ""; // }else { // if(value.contains(":")) { // String[] values = value.split(":"); // value = values[0]; // }else if(value.contains(":")) { // String[] values = value.split(":"); // value = values[0]; // } // } // if("成品件".equals(value)) { // value = ""; // }else if("车工件".equals(value)) { // value = "C"; // }else if("热处理件".equals(value)) { // value = "R"; // }else if("冷凝建".equals(value)) { // value = "L"; // }else if("锻件".equals(value)) { // value = "D"; // } // attrValue = value; // }else { // attrValue = ((JTextField) objList2.get(i)).getText(); // } // System.out.println("attrValue11111=============="+attrValue); // String mark = markList2.get(i); // sb2.append(mark.trim()); // sb2.append(attrValue); // } // drawingNumber = sb2.toString(); // System.out.println("drawingNumber============"+drawingNumber); if (classFlag) { productNumber = splicValue(defaultValueList, attrList, esAttrList, objMap, markList,isNList,lovMap); drawingNumber = splicValue(defaultValueList2, attrList2, esAttrList2, objMap2, markList2,isNList2, lovMap2); System.out.println("productNumber============" + productNumber); System.out.println("drawingNumber============" + drawingNumber); if (productNumber == null || drawingNumber == null) { return; } } else { productNumber = targetItem.getStringProperty("rb3_th") + jhID; drawingNumber = targetItem.getStringProperty("rb3_th") + jhID; System.out.println("productNumber============" + productNumber); System.out.println("drawingNumber============" + drawingNumber); } TCComponentItemType itemType = (TCComponentItemType) session.getTypeComponent(item_type); TCComponentItem find = itemType.find(newID); if (find != null) { MessageBox.post("物料:" + newID + "已创建,无法创建!", "错误", MessageBox.ERROR); return; } //优化 List compList = queryObject("RBSearchLBJCPH", new String[] { "产品号" }, new String[] { productNumber }); if (compList != null) { if (compList.size() > 0) { String nID=newID.substring(0,2); for(int j=0;j proList=new ArrayList<>(); String[] split = text.split(","); TCProperty tclov = ((TCComponentItemRevision) targetItem).getTCProperty(key); TCComponentListOfValues lov = tclov.getLOV(); for(int p=0;p 0) { TCComponentItemRevision picItem = revList.get(0); TCComponent[] pics = picItem.getReferenceListProperty("TC_Is_Represented_By"); for (int i = 0; i < pics.length; i++) { itemRev.add("TC_Is_Represented_By", pics[i]); } // picItem.add("RB3_GLWL", itemRev); } else { TCComponentItemType typeComponent = (TCComponentItemType) session.getTypeComponent("RB3_CGT"); // String revID = typeComponent.getNewRev(null); // String drawID = typeComponent.getNewID(); String[] keys = new String[] { "零组件 ID" }; String[] values = new String[] { drawingNumber }; List tzList = queryObject("零组件 ID", keys, values); TCComponentItemRevision CPTRev = null; if (tzList != null) { if (tzList.size() > 0) { if (tzList.get(0) instanceof TCComponentItem) { TCComponentItem tcItem = (TCComponentItem) tzList.get(0); CPTRev = tcItem.getLatestItemRevision(); } } } else { TCComponentItem CPTItem = typeComponent.create(drawingNumber, "V1", "RB3_CGT", "", "", null); CPTRev = CPTItem.getLatestItemRevision(); if (CPTItem != null) { session.getUser().getHomeFolder().add("contents", CPTItem); session.getUser().getHomeFolder().refresh(); } } CPTRev.setStringProperty("rb3_th", drawingNumber); itemRev.add("TC_Is_Represented_By", CPTRev); // CPTRev.add("RB3_GLWL", itemRev); } } List vals = new ArrayList(); for (Map value : values) { for (Map.Entry entry : value.entrySet()) { String type = entry.getKey(); if (type.equals("JComboBox")) { JComboBox comb1 = (JComboBox) entry.getValue(); String val = (String) comb1.getSelectedItem(); vals.add(val); } else { JTextField field1 = (JTextField) entry.getValue(); String val = field1.getText(); vals.add(val); } } } Integer[] classKeys = new Integer[classList.size()]; String[] classVals = new String[classList.size()]; System.out.println("size============================" + classList.size()); for (int i = 0; i < labels1.length; i++) { String val = vals.get(i); if (val == null || val.trim() == "") { continue; } String val2 = ""; if (classList.get(i).isIslov()) { val2 = classList.get(i).getLov().get(val);// 获得真实值 System.out.println("val2================" + val2); System.out.println("val================" + val); } else { val2 = val; } classKeys[i] = classList.get(i).getId(); String attrName = classList.get(i).getName(); if ((PlmLocaleUtil.getString("RadialInternalClearance")).equals(attrName) || (PlmLocaleUtil.getString("PartNumber")).equals(attrName)) { if ("".equals(val2.trim())) { JComboBox box = boxMap.get(attrName); val2 = (String) box.getSelectedItem(); } } classVals[i] = val2; } TCTypeService typeService = session.getTypeService(); TCComponentBOMWindowType winType = (TCComponentBOMWindowType) typeService.getTypeComponent("BOMWindow"); // 创建一个新的window TCComponentBOMWindow view = winType.create(null); view.lock(); // 设置顶层的bomline TCComponentBOMLine line = view.setWindowTopLine(targetItem.getItem(), targetItem, null, null); // 添加子bomline TCComponentBOMLine childBomline = line.add(itemComp, itemRev, null, false, ""); // 保存 view.save(); // 解锁 view.unlock(); // 关闭 view.close(); sendObjToClassficationByWebService(className2, itemRev, classKeys, classVals, url);// 发送分类 MessageBox.post("物料创建成功!!!", "提醒", MessageBox.INFORMATION); setVisible(false); } catch (Exception e2) { // TODO: handle exception e2.printStackTrace(); MessageBox.post("物料创建失败!!!", "提醒", MessageBox.INFORMATION); } } /** * 遍历获得当前TreeNode的父-子名称汇总 * * @param treeNode 树节点 * @param names 名称汇总 * @return */ private String getNode(TreeNode treeNode, String names) { // TODO Auto-generated method stub if (!names.equals("")) { names = "&" + names; } names = treeNode.toString() + names; TreeNode parent = treeNode.getParent(); if (parent != null) { return getNode(parent, names); } return names; } /** * 树界面 * * @param menuBean1 * @return */ private JTree getTree(MenuBean menuBean1) { // TODO Auto-generated method stub String treenodename = menuBean1.getName(); List list = menuBean1.getList(); DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(treenodename); if (list != null && list.size() > 0) { for (int i = 0; i < list.size(); i++) { getRecursion(list.get(i), rootNode); } } JTree tree = new JTree(rootNode); tree.setShowsRootHandles(true); // tree.setEditable(true); return tree; } /** * 递归遍历菜单结构 * * @param menuBean1 * @param rootNode */ private void getRecursion(MenuBean menuBean1, DefaultMutableTreeNode rootNode) { // TODO Auto-generated method stub String treenodename = menuBean1.getName(); List list = menuBean1.getList(); DefaultMutableTreeNode node = new DefaultMutableTreeNode(treenodename); rootNode.add(node); if (list != null && list.size() > 0) { for (int i = 0; i < list.size(); i++) { getRecursion(list.get(i), node); } } } /** * 通过查询构建器查询项目对象 * * @param queryName 查询名称 * @param keys 查询条件 * @param values 查询值 * @return */ public List queryObject(String queryName, String[] keys, String[] values) { TCComponent[] components = null; try { TCComponentQueryType queryType = (TCComponentQueryType) session.getTypeComponent("ImanQuery"); TCComponentQuery query = (TCComponentQuery) queryType.find(queryName); if (query == null) { MessageBox.post("没有找到查询:" + queryName, "错误", MessageBox.ERROR); return null; } components = query.execute(keys, values); } catch (TCException e) { e.printStackTrace(); } if (components != null && components.length > 0) { List compList = Arrays.asList(components); return compList; } else { return null; } } /** * 发送分类 */ public void sendObjToClassficationByWebService(String class_id, TCComponentItemRevision rev, Integer[] keys, String[] vals, String url) { try { System.out.println("class_id-----dddddd----->" + class_id); if (!class_id.replace(" ", "").equals("")) { List propList = new ArrayList(); for (int i = 0; i < keys.length; i++) { if (keys[i] != null && vals[i] != null) { ClassProperty prop = new ClassProperty(keys[i], vals[i]);// 分类属性 propList.add(prop); } } String json = SoaServerUtil.objectToJson(propList);// 将Java对象转换为json对象 SoaServerUtil.sendToClass(rev.getUid(), class_id, json, url);// 发送到分类 SoaServerUtil.grantReadPrivilege(session, rev);// 赋予读权限 } } catch (Exception e) { e.printStackTrace(); } } public String splicValue(List defaultValueList, List attrList, List esAttrList, Map map, List markList,List isNList, Map lovMap) { List objList = new ArrayList(); List lovList = new ArrayList(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < attrList.size(); i++) { String attr = attrList.get(i); System.out.println("attr======112" + attr); String esAttr = esAttrList.get(i); if (classFlag2) { if ((PlmLocaleUtil.getString("heatTreatment")).equals(attr) || (PlmLocaleUtil.getString("heatTreatment")).equals(esAttr)) { objList.add(HeatTreatment); lovList.add("string"); continue; } } if (map.get(attr) == null && map.get(esAttr) == null) { if ((PlmLocaleUtil.getString("PartNumber")).equals(attr) || (PlmLocaleUtil.getString("PartNumber")).equals(esAttr)) { JComboBox idbox = boxMap.get(PlmLocaleUtil.getString("PartNumber")); JTextField idfield = (JTextField) idList.get(0); String fieldText = idfield.getText(); String boxText = (String) idbox.getSelectedItem(); if (!("".equals(fieldText.trim())) && !("".equals(boxText.trim()))) { MessageBox.post(PlmLocaleUtil.getString("PartNumber") + "不能同时填写两个值!!!", "提示", MessageBox.INFORMATION); return null; } // if ("".equals(fieldText.trim()) && "".equals(boxText.trim())) { // MessageBox.post(PlmLocaleUtil.getString("PartNumber") + "必须填写一个值!!!", "提示", // MessageBox.INFORMATION); // return null; // } if (!("".equals(fieldText.trim()))) { objList.add(fieldText); lovList.add("string"); } else { objList.add(boxText); lovList.add("string"); } continue; } objList.add(defaultValueList.get(i)); lovList.add("string"); continue; } if (!("".equals(attr.trim()))) { Object obj = map.get(attr); JComboBox box = null; if ((PlmLocaleUtil.getString("RadialInternalClearance")).equals(attr) || (PlmLocaleUtil.getString("RadialInternalClearance")).equals(esAttr)) { box = boxMap.get(PlmLocaleUtil.getString("RadialInternalClearance")); } if (obj == null) { obj = map.get(esAttr); if (box != null) { JTextField field = (JTextField) obj; String fieldText = field.getText(); String boxText = (String) box.getSelectedItem(); if (!("".equals(fieldText.trim())) && !("".equals(boxText.trim()))) { MessageBox.post(esAttr + "不能同时填写两个值!!!", "提示", MessageBox.INFORMATION); return null; } if ("".equals(fieldText.trim()) && "".equals(boxText.trim())) { MessageBox.post(esAttr + "必须填写一个值!!!", "提示", MessageBox.INFORMATION); return null; } if (!("".equals(fieldText.trim()))) { objList.add(field); lovList.add("no"); } else { objList.add(box); lovList.add("yes"); } } else { objList.add(obj); lovList.add(lovMap.get(esAttr)); } } else { if (box != null) { JTextField field = (JTextField) obj; String fieldText = field.getText(); String boxText = (String) box.getSelectedItem(); if (!("".equals(fieldText.trim())) && !("".equals(boxText.trim()))) { MessageBox.post(attr + "不能同时填写两个值!!!", "提示", MessageBox.INFORMATION); return null; } if ("".equals(fieldText.trim()) && "".equals(boxText.trim())) { MessageBox.post(attr + "必须填写一个值!!!", "提示", MessageBox.INFORMATION); return null; } if (!("".equals(fieldText.trim()))) { objList.add(field); lovList.add("no"); } else { objList.add(box); lovList.add("yes"); } } else { objList.add(obj); lovList.add(lovMap.get(attr)); } } } } for (int i = 0; i < objList.size(); i++) { String attrValue = ""; Object obj = objList.get(i); if (obj != null) { if ("yes".equals(lovList.get(i))) { String value = (String) ((JComboBox) obj).getSelectedItem(); System.out.println("下拉框值为:"+value); if (asList.contains(value) || esList.contains(value)) { if(isNList.get(i).trim().contains(value)) { if (value.contains(":")) { System.out.println("value============" + value); String[] values = value.split(":"); value = values[0]; } else if (value.contains(":")) { System.out.println("value============" + value); String[] values = value.split(":"); value = values[0]; } }else { value = ""; } } else { if (value.contains(":")) { System.out.println("value============" + value); String[] values = value.split(":"); value = values[0]; } else if (value.contains(":")) { System.out.println("value============" + value); String[] values = value.split(":"); value = values[0]; } } if ("成品件".equals(value) || "Finished product".equals(value)) { value = ""; } else if ("车工件".equals(value) || "Turning workpiece".equals(value)) { value = "C"; } else if ("热处理件".equals(value) || "Heat treatment parts".equals(value)) { value = "R"; } else if ("冷辗件或冷挤件".equals(value) || "Cold rolled parts or cold extrusion parts".equals(value)) { value = "D"; } else if ("锻件".equals(value) || "Forge piece".equals(value)) { value = "D"; } attrValue = value; } else if ("no".equals(lovList.get(i))) { attrValue = ((JTextField) obj).getText(); } else { attrValue = (String) obj; } if(asList.contains(attrValue) || esList.contains(attrValue)) { attrValue = ""; }else { if(attrValue.contains(":")) { System.out.println("attrValue============"+attrValue); String[] values = attrValue.split(":"); attrValue = values[0]; }else if(attrValue.contains(":")) { System.out.println("attrValue============"+attrValue); String[] values = attrValue.split(":"); attrValue = values[0]; } } String mark = markList.get(i); if (!("".equals(attrValue.trim()))) { sb.append(mark.trim()); sb.append(attrValue); } } } return sb.toString(); } }