feat(create-temp-drawings):优化属性配置和 LOV 处理逻辑

- 改进属性配置加载逻辑,支持动态 LOV 和静态 LOV 的处理
- 优化版本号下拉框的显示和处理
- 调整 JTreeComboBox 的弹出框大小
- 重构部分代码以提高可维护性和可扩展性
mian
熊朝柱 1 month ago
parent 6bede265c8
commit ad1933016c

@ -300,9 +300,9 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
for (Map.Entry<String, JComponent> entry : this.propComponentMap.entrySet()) {
String key = entry.getKey();
if (key.equals("ID*")){
item_id = getComponentValue(entry.getValue());
item_id = getComponentValue(key,entry.getValue());
} else if (key.equals("版本")) {
item_revision_id = getComponentValue(entry.getValue());//item_revision_id
item_revision_id = getComponentValue(key,entry.getValue());//item_revision_id
}
}
@ -473,15 +473,22 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
}
String trueNameString = null;
//通过lov属性集合遍历获取lov真实值
//1.先根据普通一层lov和动态lov分别获取lov真实值
for (LovProperty lovProperty : lovPropertyList2) {
String propName = lovProperty.getPropTrueName();
String lovType = lovProperty.getLovType();
if (configName.equals(propName)) {//属性真实名称与lov属性集合匹配
Map<String, String> lovMap = lovProperty.getLovMap();
trueNameString = lovMap.get(lovShowName);
if (lovType.equals("LOV")){//普通单层lov取值
Map<String, String> lovMap = lovProperty.getLovMap();
trueNameString = lovMap.get(lovShowName);
}else if (lovType.equals("DLOV")){//动态lov取值获取lov下拉框的显示值即可不存在key-value结构
trueNameString = lovShowName;
}
break;
}
}
//通过lov子项集合遍历获取lov真实值
//2.如果未获取成功,则通过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子项《显示值-真实值》集合
@ -491,6 +498,7 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
String realValueString = entry1.getValue();
if (lovShowName.equals(showValueString)) {
trueNameString = realValueString;
break;
}
}
@ -726,7 +734,7 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
if (propComponentMap.size()>0) {
for (Map.Entry<String, JComponent> entry : propComponentMap.entrySet()) {
String key = entry.getKey();
Object value = getComponentValue(entry.getValue());
Object value = getComponentValue(key,entry.getValue());
// System.out.println("开始校验属性:"+key);
if (key.contains("*")) {
// System.out.println("属性【"+key+"】包含必选项!");
@ -760,7 +768,7 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
String lovType = null;
for (LovProperty lovProperty : this.lovPropertyList) {
if (lovProperty.getPropName().equals(propShowName)) {
lovType = lovProperty.getlovType();
lovType = lovProperty.getLovType();
break;
}
@ -828,13 +836,7 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
if (idValue != null){
this.idTextField = new JTextField(idValue);
}
this.revLabel = new JLabel("版本");
String[] revs = {"DX01"};//版本下拉框数组
// //todo 参考编码器获取新的版本
// String newRev = tccomponentitemtype.getNewRev(null);
// String[] revs = {newRev};
this.revComboBox = new JComboBox<String>(revs);
// this.revComboBox.setEditable(true);
//布局
// ID Label
@ -858,31 +860,8 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
centerPanel1.add(this.idTextField, gbcIdField);
propComponentMap.put("ID*", idTextField);
// 版本 Label
GridBagConstraints gbcRevLabel = new GridBagConstraints();
gbcRevLabel.gridx = 0;
gbcRevLabel.gridy = 1;
gbcRevLabel.anchor = GridBagConstraints.WEST;
gbcRevLabel.insets = new Insets(5, 5, 5, 5);
centerPanel1.add(this.revLabel, gbcRevLabel);
// 版本 ComboBox
GridBagConstraints gbcRevCombo = new GridBagConstraints();
gbcRevCombo.gridx = 1;
gbcRevCombo.gridy = 1;
gbcRevCombo.anchor = GridBagConstraints.WEST;
// 设置自定义宽度
Dimension comboBoxSize = new Dimension(200, revComboBox.getPreferredSize().height); // 将200设为所需的宽度
revComboBox.setPreferredSize(comboBoxSize);
centerPanel1.add(this.revComboBox, gbcRevCombo);
propComponentMap.put("版本", revComboBox);
String preferenceName = getSelectTypePreferenceName();
int propIndex = 2;
int propIndex = 1;
if (preferenceName != null){
List<String> preferenceInfoList = getPreferenceInfos(preferenceName);
if (preferenceInfoList != null && preferenceInfoList.size()>0) {
@ -894,7 +873,40 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
}
System.out.println("配置的属性数量 = "+this.preferencePropList.size());
for(String propInfo : this.preferencePropList){//propInfo格式为*名称=Item.object_name=string
// for(String propInfo : this.preferencePropList){//propInfo格式为*名称=Item.object_name=string
String[] revIDs = this.preferencePropList.get(0).split(";");//版本下拉框的数组
if (revIDs != null && revIDs.length > 0) {
this.revLabel = new JLabel("版本");
this.revComboBox = new JComboBox<String>(revIDs);
// 版本 Label
GridBagConstraints gbcRevLabel = new GridBagConstraints();
gbcRevLabel.gridx = 0;
gbcRevLabel.gridy = 1;
gbcRevLabel.anchor = GridBagConstraints.WEST;
gbcRevLabel.insets = new Insets(5, 5, 5, 5);
centerPanel1.add(this.revLabel, gbcRevLabel);
// 版本 ComboBox
GridBagConstraints gbcRevCombo = new GridBagConstraints();
gbcRevCombo.gridx = 1;
gbcRevCombo.gridy = 1;
gbcRevCombo.anchor = GridBagConstraints.WEST;
// 设置自定义宽度
Dimension comboBoxSize = new Dimension(200, revComboBox.getPreferredSize().height); // 将200设为所需的宽度
revComboBox.setPreferredSize(comboBoxSize);
centerPanel1.add(this.revComboBox, gbcRevCombo);
propComponentMap.put("版本", revComboBox);
propIndex ++;
}
// 首选项中配置的preferencePropList中第一个是版本号数组所以从第二个配置信息开始逐个渲染组件和属性
for (int i = 1; i < this.preferencePropList.size(); i++) {
String propInfo = this.preferencePropList.get(i);//propInfo格式为*名称=Item.object_name=string
System.out.println("开始处理首选项配置的属性信息:"+propInfo);
String[] propConfigInfoArray= propInfo.split("=");
String validPropName = null;//属性条目(除去符号*后)的有效值
@ -969,18 +981,22 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
if(unitLov != null){
lovType = unitLov.getType();
if (lovType != null && lovType.equals("ListOfValuesString")) {//传统lovkey-value
System.out.println("获取属性["+name+"]的LOV类型为traditional LOV");
rMap.clear();
Map<String, String> lovMap = getLOVDisplay_value(tcSession, lovName);
lovProperty.setLovMap(lovMap);
lovProperty.setLovType("LOV");
} else if (lovType != null && lovType.equals("Fnd0ListOfValuesDynamic")) {//动态lov数组
System.out.println("获取属性["+name+"]的LOV类型为dynamic 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]);
for (int i1 = 0; i1 < dynamicLOV.length; i1++) {
dlovList.add(dynamicLOV[i1]);
}
lovProperty.setDlovList(dlovList);
}else {
System.out.println("获取属性["+name+"]的LOV类型为未知类型");
}
}else {
continue;
@ -1014,7 +1030,8 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
continue;
}
}else {
String[] dlov = (String[]) lovProperty.getDlovList().toArray();
String[] dlov = lovProperty.getDlovList().toArray(new String[0]);
JComboBox<String> jComboBox = new JComboBox<String>(dlov);
GridBagConstraints gbcPropCombo = new GridBagConstraints();
@ -1031,10 +1048,10 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
}
}
propIndex ++;
}else {
System.out.println("首选项中配置的属性["+name+"]信息中,未正确配置属性类型!");
}
propIndex ++;
}else {
System.out.println("首选项["+preferenceName+"]配置格式不正确,请检查!");
}

@ -27,6 +27,15 @@ public class LovProperty {
public String getLovType() {
return lovType;
}
/**
* lov-lov
*/
private Map<String, String> lovMap;
//专门用于存放动态lov的list集合
private List<String> dlovList;
/**
* @param lovType lovType
@ -35,10 +44,7 @@ public class LovProperty {
this.lovType = lovType;
}
/**
* lov-
*/
private Map<String, String> lovMap;
/**
* @return dlovList
@ -54,7 +60,7 @@ public class LovProperty {
this.dlovList = dlovList;
}
private List<String> dlovList;
public String getPropName() {
return propName;

@ -195,7 +195,8 @@ public class JTreeComboBox extends JComboBox<Object> {
// 设置弹出框大小
Dimension preferredSize = tree.getPreferredSize();
preferredSize.width = Math.max(preferredSize.width, 200);
preferredSize.height = Math.min(preferredSize.height, 800);
preferredSize.height = Math.min(preferredSize.height, 200);
preferredSize.height = 150;
setPreferredSize(preferredSize);
}

Loading…
Cancel
Save