feat(create-temp-drawings):支持动态 LOV 类型属性

- 新增动态 LOV值获取方法
- 扩展 LovProperty 类,支持动态 LOV 类型
- 修改创建对话框逻辑,支持动态 LOV组件渲染
- 优化 JTreeComboBox 组件,支持动态 LOV 选择
mian
熊朝柱 1 month ago
parent e72dbea79b
commit a2f038d091

@ -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<String> comboBox = (JComboBox<String>) 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,35 +952,41 @@ 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")) {//传统lovkey-value
rMap.clear();
Map<String, String> 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.setLovMap(lovMap);
lovProperty.setLovType("LOV");
} else if (lovType != null && lovType.equals("Fnd0ListOfValuesDynamic")) {//动态lov数组
String[] dynamicLOV = getDynamicLOV(unitLov);
lovProperty.setLovType("DLOV");
List<String> dlovList = new ArrayList<>();
for (int i = 0; i < dynamicLOV.length; i++) {
dlovList.add(dynamicLOV[i]);
}
lovProperty.setDlovList(dlovList);
}
}else {
continue;
}
lovProperty.setPropName(name);
lovProperty.setPropTrueName(trueName);
lovProperty.setLov(true);
lovProperty.setLovMap(lovMap);
this.lovPropertyList.add(lovProperty);
// JComboBox<String> propComboBox = new JComboBox<String>(displayLovName);
DefaultMutableTreeNode root = generateLovTreeNode(lovMap,rMap);
//根据lov的类型渲染不同的lov组件
if (lovType.equals("ListOfValuesString")) {
DefaultMutableTreeNode root = generateLovTreeNode(lovProperty.getLovMap(),rMap);
JTreeComboBox propComboBox = null;
if(root != null) {
propComboBox = new JTreeComboBox(root);
}else {
System.out.println("绘制多层lov失败");
return null;
}
GridBagConstraints gbcPropCombo = new GridBagConstraints();
gbcPropCombo.gridx = 1;
gbcPropCombo.gridy = propIndex;
@ -983,6 +998,26 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
centerPanel1.add(propComboBox, gbcPropCombo);
propComponentMap.put(validPropName, propComboBox);
}else {
System.out.println("绘制多层lov失败");
continue;
}
}else {
String[] dlov = (String[]) lovProperty.getDlovList().toArray();
JComboBox<String> jComboBox = new JComboBox<String>(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);
}
}
}else {
@ -1069,6 +1104,39 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
return node;
}
/**
* LOV
* @param lov LOV
* @return LOV
*/
public String[] getDynamicLOV(TCComponentListOfValues lov) throws Exception {
Vector<String> lovDisplayValueList = new Vector<>();
// lovDisplayValueList.add("");
// Vector<String> 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<String, String[]> map = row.propDisplayValues;
// Map<String, String[]> 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
* @param selectComponent2
@ -1117,7 +1185,6 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
*/
public static Map<String, String> getLOVDisplay_value(TCSession seesion,String lovProp) throws TCException
{
// System.out.println("getLOVDisplay_value方法入参lov名称="+lovProp);
Map<String, String> Display_values = new HashMap<String, String>();
TCComponentListOfValues unitLov = TCLOVUtil.findLOVByName(seesion, lovProp);

@ -1,5 +1,6 @@
package cn.net.connor.createTempDrawings.pojo;
import java.util.List;
import java.util.Map;
/**
* LOV
@ -13,11 +14,47 @@ public class LovProperty {
//属性值
private String propValue;
private boolean isLov;
/**
* DLOVlov
* LOVlov 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<String, String> lovMap;
/**
* @return dlovList
*/
public List<String> getDlovList() {
return dlovList;
}
/**
* @param dlovList dlovList
*/
public void setDlovList(List<String> dlovList) {
this.dlovList = dlovList;
}
private List<String> dlovList;
public String getPropName() {
return propName;
}

@ -44,9 +44,17 @@ public class JTreeComboBox extends JComboBox<Object> {
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<Object> {
}
@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<Object> {
// 设置弹出框大小
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);
}

Loading…
Cancel
Save