feat(CreateTempDrawingDialog): 实现 LOV 属性的递归加载和展示

- 新增递归加载 LOV 子项的功能,将 LOV 属性的显示值和真实值映射保存在 rMap 中
- 重构 getLovTrueValue 方法,支持通过 LOV 子项集合获取真实值- 使用 JTreeComboBox 替代 JComboBox 展示 LOV 属性,支持多级 LOV 的展示
- 优化 LOV 属性的获取和处理逻辑,提高代码可维护性和性能
mian
熊朝柱 1 month ago
parent e21bc8cc17
commit 2403900a30

@ -17,6 +17,7 @@ import java.util.regex.Pattern;
import javax.mail.Folder;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
@ -30,6 +31,7 @@ import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentForm;
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.TCException;
import com.teamcenter.rac.kernel.TCPreferenceService;
@ -51,8 +53,12 @@ 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.soaictstubs.BooleanHolder;
import com.teamcenter.soaictstubs.ICCTItem;
import com.teamcenter.soaictstubs.StringHolder;
import cn.net.connor.createTempDrawings.pojo.LovProperty;
import cn.net.connor.createTempDrawings.utils.JTreeComboBox;
import cn.net.connor.createTempDrawings.utils.TCLOVUtil;
public class CreateTempDrawingDialog extends JFrame implements ActionListener{
@ -76,6 +82,7 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
private List<String> showPropsInfoList = new ArrayList<>();
private JButton closeButton;
private JButton buildButton;
private TCComponentItemType tccomponentitemtype;
// 添加日期格式化工具
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
/**
@ -95,6 +102,13 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
*/
private List<LovProperty> lovPropertyList = new ArrayList<>();
/**
* lovmap
* @key:lovlov
* @Value:lov-
*/
private static Map<String, Map<String, String>> rMap = new HashMap<String, Map<String,String>>();
/**
*
@ -357,7 +371,6 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
String trueValue = getLovTrueValue(trueName,value,this.lovPropertyList);
itemRevisionDef.stringProps.put(trueName, trueValue);
}
// itemRevisionDef.stringProps.put(trueName, value);
}else if (location.equals("Form")) {
//此处对表单属性暂时不做赋值先暂存到一个Map集合中
// itemRevisionDef.stringProps.put(trueName, value);
@ -417,19 +430,21 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
}
else if (obj instanceof TCComponentItemRevision) {
itemRev = (TCComponentItemRevision) obj;
String[] formPropInfos = {"sb6_ifls","是","lov"};
formList.add(formPropInfos);
if (!setFormProperty(itemRev,formList)) {
System.out.println("表单属性设置失败!");
}
itemRev.lock();
try {
itemRev.setStringProperty("sb6_ifls", "是");
} catch (Exception e) {
System.out.println("itemRev处理异常");
e.printStackTrace();
}finally {
itemRev.save();
itemRev.unlock();
}
// itemRev.lock();
// try {
// itemRev.setStringProperty("sb6_ifls", "是");
// } catch (Exception e) {
// System.out.println("itemRev处理异常");
// e.printStackTrace();
// }finally {
// itemRev.save();
// itemRev.unlock();
// }
}
else if (obj instanceof TCComponentForm) {
form = (TCComponentForm) obj;
@ -450,27 +465,47 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
}
/**
* lovgetlovlovlov
* @param configName
* lovgetlov - lovlov
* @param configName
* @param lovShowName lov
* @param lovPropertyList2 lov
* @return lov
*/
private String getLovTrueValue(String configName, String lovShowName, List<LovProperty> lovPropertyList2) {
String trueNameString = null;
//通过lov属性集合遍历获取lov真实值
for (LovProperty lovProperty : lovPropertyList2) {
String propName = lovProperty.getPropTrueName();
if (configName.equals(propName)) {
if (configName.equals(propName)) {//属性真实名称与lov属性集合匹配
Map<String, String> lovMap = lovProperty.getLovMap();
return lovMap.get(lovShowName);
trueNameString = lovMap.get(lovShowName);
break;
}
}
System.out.println("未获取到lov-["+lovShowName+"]的真实值");
return null;
//通过lov子项集合遍历获取lov真实值
if (trueNameString == null && rMap != null && rMap.size()>0){
for (Map.Entry<String, Map<String, String>> entry : rMap.entrySet()){
Map<String, String> childLovMaps = entry.getValue();//获取lov子项《显示值-真实值》集合
if (childLovMaps != null && childLovMaps.size()>0){
for (Map.Entry<String, String> entry1 : childLovMaps.entrySet()){
String showValueString = entry1.getKey();
String realValueString = entry1.getValue();
if (lovShowName.equals(showValueString)) {
trueNameString = realValueString;
break;
}
}
}
}
}
if (trueNameString == null) {
System.out.println("未获取到lov-[" + lovShowName + "]的真实值");
}
return trueNameString;
}
/**
*
*
* @param component
* @param formList
* @return
@ -686,6 +721,8 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
}
/**
*
* @return
@ -771,7 +808,10 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
this.idTextField = new JTextField(idValue);
}
this.revLabel = new JLabel("版本");
String[] revs = {"S01"};//版本下拉框数组
// String[] revs = {"S01"};//版本下拉框数组
//参考编码器获取新的版本
String newRev = tccomponentitemtype.getNewRev(null);
String[] revs = {newRev};
this.revComboBox = new JComboBox<String>(revs);
// this.revComboBox.setEditable(true);
@ -902,16 +942,21 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
System.out.println("未获取到属性["+name+"]配置的lov名称请检查配置!");
return null;
}
rMap.clear();
Map<String, String> lovMap = getLOVDisplay_value(tcSession, lovName);
String[] displayLovName = lovMap.keySet().toArray(new String[0]);//lov显示值
LovProperty lovProperty = new LovProperty();
LovProperty lovProperty = new LovProperty();//自定义的lov类型的属性类
lovProperty.setPropName(name);
lovProperty.setPropTrueName(trueName);
lovProperty.setLov(true);
lovProperty.setLovMap(lovMap);
this.lovPropertyList.add(lovProperty);
JComboBox<String> propComboBox = new JComboBox<String>(displayLovName);
// JComboBox<String> propComboBox = new JComboBox<String>(displayLovName);
DefaultMutableTreeNode root = generateLovTreeNode(lovMap,rMap);
JTreeComboBox propComboBox = new JTreeComboBox(root);
GridBagConstraints gbcPropCombo = new GridBagConstraints();
@ -970,6 +1015,47 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
}
/**
*
* @param lovMap lov<->Map
* @param rMap2 lov<>lov
* @return
*/
private DefaultMutableTreeNode generateLovTreeNode(Map<String, String> lovMap, Map<String, Map<String, String>> rMap2) {
// 创建树的根节点
DefaultMutableTreeNode root = new DefaultMutableTreeNode(" ");
// 为每个顶层LOV创建子树
for (Map.Entry<String, String> entry : lovMap.entrySet()) {
DefaultMutableTreeNode subTree = createLovSubTree(entry.getKey(), entry.getValue(), rMap2);
root.add(subTree);
}
return root;
}
/**
* LOV
*/
private DefaultMutableTreeNode createLovSubTree(String displayValue, String realValue, Map<String, Map<String, String>> rMap2) {
// 创建当前节点
DefaultMutableTreeNode node = new DefaultMutableTreeNode(displayValue);
// 获取当前节点的子节点
Map<String, String> childLovMap = rMap2.get(realValue);
if (childLovMap != null && !childLovMap.isEmpty()) {
// 为每个子节点递归创建子树
for (Map.Entry<String, String> childEntry : childLovMap.entrySet()) {
DefaultMutableTreeNode childNode = createLovSubTree(childEntry.getKey(), childEntry.getValue(), rMap2);
node.add(childNode);
}
}
return node;
}
/**
* ()ID
* @param selectComponent2
@ -1008,27 +1094,34 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
return str.replaceAll("\\*", "");
}
/**
* TC LOV-
* @param seesion
* @param lovProp lov /
* @return
* @throws TCException
*/
public static Map<String, String> getLOVDisplay_value(TCSession seesion,String lovProp) throws TCException
{
Map<String, String> Display_values = new HashMap<String, String>();
TCComponentListOfValues unitLov = TCLOVUtil.findLOVByName(seesion, lovProp);
if(unitLov !=null)
if(unitLov != null)
{
ListOfValuesInfo listOfValues = unitLov.getListOfValues();
String[] realval = listOfValues.getStringListOfValues();
String[] realval = unitLov.getListOfValues().getStringListOfValues();
String value="";
boolean flag = false;
for (int i = 0; i < realval.length; i++) {
String disval = listOfValues.getDisplayableValue(realval[i]);
String disval = unitLov.getListOfValues().getDisplayableValue(realval[i]);
Display_values.put(disval, realval[i]);
//递归传入lov真实值作为lov名称获取lov的显示值-真实值集合
Map<String, String> lovDisplay_value = getLOVDisplay_value(seesion, realval[i]);
}
}
rMap.put(lovProp, Display_values);
return Display_values;
}

Loading…
Cancel
Save