diff --git a/bin/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.class b/bin/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.class index 1087ebf..c87d6e4 100644 Binary files a/bin/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.class and b/bin/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.class differ diff --git a/src/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.java b/src/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.java index c964781..9da893c 100644 --- a/src/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.java +++ b/src/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.java @@ -43,10 +43,15 @@ import com.teamcenter.rac.util.PropertyLayout; import com.teamcenter.rac.util.UIUtilities; import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException; import com.teamcenter.services.rac.core.DataManagementService; +import com.teamcenter.services.rac.core.LOVService; import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateIn; import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateInput; import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateOut; import com.teamcenter.services.rac.core._2008_06.DataManagement.CreateResponse; +import com.teamcenter.services.rac.core._2013_05.LOV.InitialLovData; +import com.teamcenter.services.rac.core._2013_05.LOV.LOVSearchResults; +import com.teamcenter.services.rac.core._2013_05.LOV.LOVValueRow; +import com.teamcenter.services.rac.core._2013_05.LOV.LovFilterData; import com.teamcenter.soaictstubs.BooleanHolder; import com.teamcenter.soaictstubs.ICCTItem; import com.teamcenter.soaictstubs.StringHolder; @@ -361,6 +366,7 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{ itemDef.data.dateProps.put(trueName, calendar); }else if (typeString.split(":")[0].equals("lov")) { String trueValue = getLovTrueValue(trueName,value,this.lovPropertyList); + System.out.println("属性:"+propName+",最终赋值:"+trueValue); itemDef.data.stringProps.put(trueName, trueValue); } }else if (location.equals("Rev")) { @@ -374,6 +380,7 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{ itemRevisionDef.dateProps.put(trueName, calendar); }else if (typeString.split(":")[0].equals("lov")) { String trueValue = getLovTrueValue(trueName,value,this.lovPropertyList); + System.out.println("属性:"+propName+",最终赋值:"+trueValue); itemRevisionDef.stringProps.put(trueName, trueValue); } }else if (location.equals("Form")) { @@ -747,23 +754,25 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{ System.out.println("JTextField"); return ((JTextField) component).getText(); } else if (component instanceof JComboBox) { - String returnValue = null; +// String returnValue = null; + String chooseDisplay= null; if (component instanceof JTreeComboBox){ System.out.println("JTreeComboBox"); JTreeComboBox treeComboBox = (JTreeComboBox) component; DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) treeComboBox.getSelectedItem(); + if (selectedNode != null) { Object userObject = selectedNode.getUserObject(); - returnValue = userObject.toString(); + chooseDisplay = userObject.toString(); }else { System.out.println("选中节点selectedNode = null"); } } else { System.out.println("JComboBox"); JComboBox comboBox = (JComboBox) component; - returnValue = (String)comboBox.getSelectedItem(); + chooseDisplay = (String)comboBox.getSelectedItem(); } - return returnValue; + return chooseDisplay; }else if (component instanceof DateButton) { System.out.println("DateButton"); DateButton dateButton = (DateButton) component; @@ -784,9 +793,9 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{ /** * 绘制对象类型的创建对话框 * @return - * @throws TCException + * @throws Exception */ - public JFrame buildDrawingObjTypeFrame() throws TCException{ + public JFrame buildDrawingObjTypeFrame() throws Exception{ System.out.println("创建新图纸界面!"); this.propComponentMap.clear(); this.lovPropertyList.clear(); @@ -943,47 +952,73 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{ System.out.println("未获取到属性["+name+"]配置的lov名称,请检查配置!"); return null; } + LovProperty lovProperty = new LovProperty();//自定义的lov类型的属性类:存放lov类型的属性信息 + TCComponentListOfValues unitLov = TCLOVUtil.findLOVByName(tcSession, lovName); + String lovType = null; + if(unitLov != null){ + lovType = unitLov.getType(); + if (lovType != null && lovType.equals("ListOfValuesString")) {//传统lov:key-value + rMap.clear(); + Map lovMap = getLOVDisplay_value(tcSession, lovName); + lovProperty.setLovMap(lovMap); + lovProperty.setLovType("LOV"); + } else if (lovType != null && lovType.equals("Fnd0ListOfValuesDynamic")) {//动态lov:数组 + String[] dynamicLOV = getDynamicLOV(unitLov); + lovProperty.setLovType("DLOV"); + List dlovList = new ArrayList<>(); + for (int i = 0; i < dynamicLOV.length; i++) { + dlovList.add(dynamicLOV[i]); + } + lovProperty.setDlovList(dlovList); + } + }else { + continue; + } - rMap.clear(); - Map lovMap = getLOVDisplay_value(tcSession, lovName); -// System.out.println("开始打印第一层lov:"); -// for (String displayValue : lovMap.keySet()){ -// System.out.println(" lovMap:"+displayValue+"--"+lovMap.get(displayValue)); -// } -// printRMap(); - -// String[] displayLovName = lovMap.keySet().toArray(new String[0]);//lov显示值 - LovProperty lovProperty = new LovProperty();//自定义的lov类型的属性类 lovProperty.setPropName(name); lovProperty.setPropTrueName(trueName); lovProperty.setLov(true); - lovProperty.setLovMap(lovMap); + this.lovPropertyList.add(lovProperty); -// JComboBox propComboBox = new JComboBox(displayLovName); - DefaultMutableTreeNode root = generateLovTreeNode(lovMap,rMap); - JTreeComboBox propComboBox = null; - if(root != null) { - propComboBox = new JTreeComboBox(root); + //根据lov的类型,渲染不同的lov组件 + if (lovType.equals("ListOfValuesString")) { + DefaultMutableTreeNode root = generateLovTreeNode(lovProperty.getLovMap(),rMap); + JTreeComboBox propComboBox = null; + if(root != null) { + propComboBox = new JTreeComboBox(root); + GridBagConstraints gbcPropCombo = new GridBagConstraints(); + gbcPropCombo.gridx = 1; + gbcPropCombo.gridy = propIndex; + gbcPropCombo.anchor = GridBagConstraints.WEST; + + // 设置自定义宽度 + Dimension propValueSize = new Dimension(200, propComboBox.getPreferredSize().height); // 将200设为所需的宽度 + propComboBox.setPreferredSize(propValueSize); + + centerPanel1.add(propComboBox, gbcPropCombo); + propComponentMap.put(validPropName, propComboBox); + }else { + System.out.println("绘制多层lov失败!"); + continue; + } }else { - System.out.println("绘制多层lov失败!"); - return null; + String[] dlov = (String[]) lovProperty.getDlovList().toArray(); + JComboBox jComboBox = new JComboBox(dlov); + + GridBagConstraints gbcPropCombo = new GridBagConstraints(); + gbcPropCombo.gridx = 1; + gbcPropCombo.gridy = propIndex; + gbcPropCombo.anchor = GridBagConstraints.WEST; + + // 设置自定义宽度 + Dimension propValueSize = new Dimension(200, jComboBox.getPreferredSize().height); // 将200设为所需的宽度 + jComboBox.setPreferredSize(propValueSize); + + centerPanel1.add(jComboBox, gbcPropCombo); + propComponentMap.put(validPropName, jComboBox); } - - - GridBagConstraints gbcPropCombo = new GridBagConstraints(); - gbcPropCombo.gridx = 1; - gbcPropCombo.gridy = propIndex; - gbcPropCombo.anchor = GridBagConstraints.WEST; - - // 设置自定义宽度 - Dimension propValueSize = new Dimension(200, propComboBox.getPreferredSize().height); // 将200设为所需的宽度 - propComboBox.setPreferredSize(propValueSize); - - centerPanel1.add(propComboBox, gbcPropCombo); - propComponentMap.put(validPropName, propComboBox); - } }else { System.out.println("首选项中配置的属性["+name+"]信息中,未正确配置属性类型!"); @@ -1068,6 +1103,39 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{ return node; } + + /** + * 获取动态LOV值 + * @param lov LOV对象 + * @return LOV选项数组 + */ + public String[] getDynamicLOV(TCComponentListOfValues lov) throws Exception { + Vector lovDisplayValueList = new Vector<>(); +// lovDisplayValueList.add(""); +// Vector lovValueList = new Vector<>(); + com.teamcenter.services.rac.core.LOVService lovService = LOVService.getService(tcSession); + InitialLovData input = new InitialLovData(); + LovFilterData filter = new LovFilterData(); + filter.sortPropertyName = "object_name"; + filter.order = 1; + filter.numberToReturn = 100; + filter.maxResults = 100; + + input.lov = lov; + input.filterData = filter; + LOVSearchResults result = lovService.getInitialLOVValues(input); + for (LOVValueRow row : result.lovValues) { + Map map = row.propDisplayValues; +// Map realmap = row.propInternalValues; + for (String key : map.keySet()) { + lovDisplayValueList.add(map.get(key)[0]); +// lovValueList.add(realmap.get(key)[0]); + } + } + return lovDisplayValueList.toArray(new String[lovDisplayValueList.size()]); + } + + /** * 根据选中对象(业务逻辑)获取ID输入框中的默认值 @@ -1117,7 +1185,6 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{ */ public static Map getLOVDisplay_value(TCSession seesion,String lovProp) throws TCException { -// System.out.println("getLOVDisplay_value方法入参:lov名称="+lovProp); Map Display_values = new HashMap(); TCComponentListOfValues unitLov = TCLOVUtil.findLOVByName(seesion, lovProp); diff --git a/src/cn/net/connor/createTempDrawings/pojo/LovProperty.java b/src/cn/net/connor/createTempDrawings/pojo/LovProperty.java index 6b1b5b9..032d50f 100644 --- a/src/cn/net/connor/createTempDrawings/pojo/LovProperty.java +++ b/src/cn/net/connor/createTempDrawings/pojo/LovProperty.java @@ -1,5 +1,6 @@ package cn.net.connor.createTempDrawings.pojo; +import java.util.List; import java.util.Map; /** * LOV属性对象 @@ -13,10 +14,46 @@ public class LovProperty { //属性值 private String propValue; private boolean isLov; + + /** + * DLOV:动态lov 数组 + * LOV:传统lov key-value + */ + private String lovType; + /** + * @return lovType + */ + public String getLovType() { + return lovType; + } + + /** + * @param lovType 要设置的 lovType + */ + public void setLovType(String lovType) { + this.lovType = lovType; + } + /** * lov类型属性的“显示值-真实值”集合 */ private Map lovMap; + + /** + * @return dlovList + */ + public List getDlovList() { + return dlovList; + } + + /** + * @param dlovList 要设置的 dlovList + */ + public void setDlovList(List dlovList) { + this.dlovList = dlovList; + } + + private List dlovList; public String getPropName() { return propName; diff --git a/src/cn/net/connor/createTempDrawings/utils/JTreeComboBox.java b/src/cn/net/connor/createTempDrawings/utils/JTreeComboBox.java index 426130d..a425cbf 100644 --- a/src/cn/net/connor/createTempDrawings/utils/JTreeComboBox.java +++ b/src/cn/net/connor/createTempDrawings/utils/JTreeComboBox.java @@ -44,9 +44,17 @@ public class JTreeComboBox extends JComboBox { System.out.println("更新选中项!"); DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (selectedNode != null) { + System.out.println("选中的节点:" + selectedNode.getUserObject()); setSelectedItem(selectedNode); hidePopup(); } + DefaultMutableTreeNode ss1 = (DefaultMutableTreeNode)getSelectedItem(); + if (ss1 == null) { + System.out.println("ss1 = null"); + }else { + System.out.println("ss1 != null"); + } + } } }); @@ -111,6 +119,16 @@ public class JTreeComboBox extends JComboBox { } + @Override + public Object getSelectedItem() { +// Object selected = super.getSelectedItem(); + DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); +// System.out.println("重写的getSelectedItem方法返回值: " + selected); + return selectedNode; + } + + + @Override public void setSelectedItem(Object anObject) { System.out.println("设置选中项: " + anObject); @@ -176,8 +194,8 @@ public class JTreeComboBox extends JComboBox { // 设置弹出框大小 Dimension preferredSize = tree.getPreferredSize(); - preferredSize.width = Math.max(preferredSize.width, comboBox.getWidth()); - preferredSize.height = Math.min(preferredSize.height, 200); + preferredSize.width = Math.max(preferredSize.width, 200); + preferredSize.height = Math.min(preferredSize.height, 800); setPreferredSize(preferredSize); }