Compare commits

...

10 Commits

Author SHA1 Message Date
熊朝柱 2765245a0e feat(CreateTempDrawingDialog): 优化临时图纸创建界面并添加滚动条
2 weeks ago
熊朝柱 9444e41148 refactor(CreateTempDrawingDialog):优化属性列表循环逻辑
1 month ago
熊朝柱 ad1933016c feat(create-temp-drawings):优化属性配置和 LOV 处理逻辑
1 month ago
熊朝柱 6bede265c8 refactor(createTempDrawings):优化 LovProperty 类的属性注释
1 month ago
熊朝柱 a2f038d091 feat(create-temp-drawings):支持动态 LOV 类型属性
1 month ago
熊朝柱 e72dbea79b feat(JTreeComboBox): 优化下拉框显示内容及选中项处理
1 month ago
熊朝柱 7a602bcb7f refactor(dialog): 优化 CreateTempDrawingDialog 类
1 month ago
熊朝柱 82985f1ff1 refactor(dialog): 优化 CreateTempDrawingDialog 类
1 month ago
熊朝柱 f2841be489 0
1 month ago
熊朝柱 2403900a30 feat(CreateTempDrawingDialog): 实现 LOV 属性的递归加载和展示
1 month ago

@ -11,11 +11,5 @@
<menuContribution locationURI="menu:custWJ?after=projectCust">
<command commandId="CreateTempDrawing" id="cn.net.connor.createTempDrawing.menu.createTempDrawing" mnemonic="S"/>
</menuContribution>
<!--<menuContribution locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu label="测试" mnemonic="M" id="DesignToPartCommand">
<command commandId="cn.net.connor.designtopart.commands.DesignToPartCommand" id="cn.net.connor.designtopart.menu.designtopart"/>
</menu>
</menuContribution>-->
</extension>
</plugin>

@ -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;
@ -41,18 +43,21 @@ 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.DataManagementService;
//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.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;
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,11 +81,13 @@ 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");
/**
*
* *=Item.object_name=string
* ;
*/
private List<String> preferencePropList = new ArrayList<>();
@ -94,7 +101,26 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
* lov
*/
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>>();
public static void printRMap() {
// System.out.println("begin 打印rMap集合");
for (Map.Entry<String, Map<String, String>> outerEntry : rMap.entrySet()) {
String key = outerEntry.getKey();
Map<String, String> innerMap = outerEntry.getValue();
// System.out.println("Key: " + key);
for (Map.Entry<String, String> innerEntry : innerMap.entrySet()) {
// System.out.println(">>> Inner Key: " + innerEntry.getKey() + ", Value: " + innerEntry.getValue());
}
}
}
/**
*
@ -122,7 +148,6 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
}
initUI();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
@ -276,9 +301,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
}
}
@ -297,13 +322,14 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
}
System.out.println("已有属性条目-组件数量="+this.propComponentMap.size());
// System.out.println("已有属性条目-组件数量="+this.propComponentMap.size());
for (Map.Entry<String, JComponent> entry : this.propComponentMap.entrySet()) {
String key = entry.getKey();//编辑的属性条目名称
String value = getComponentValue(entry.getValue());//根据组件获取选中、输入的值
String value = getComponentValue(key,entry.getValue());//根据组件获取选中、输入的值
int tag = 0;
//遍历首选项配置,获取属性真实值和位置、类型等信息
for (String prop : preferencePropList){
for (int i = 1; i < preferencePropList.size(); i++){
String prop = preferencePropList.get(i);
String[] split = prop.split("=");
if (split != null && split.length > 0) {
String propName = split[0];
@ -342,6 +368,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")) {
@ -355,9 +382,9 @@ 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);
}
// itemRevisionDef.stringProps.put(trueName, value);
}else if (location.equals("Form")) {
//此处对表单属性暂时不做赋值先暂存到一个Map集合中
// itemRevisionDef.stringProps.put(trueName, value);
@ -417,60 +444,80 @@ 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();
}
}
else if (obj instanceof TCComponentForm) {
form = (TCComponentForm) obj;
/*
* form.lock(); try { if (formList.size()>0) { System.out.println("开始处理表单数据");
* for (String[] forms : formList) { if (forms.length == 3) { String tNameString
* = forms[0]; String tValueString = forms[1]; String tTypeString = forms[2];
*
* setTCPropertyValue(form,tNameString,tValueString); } } } } catch (Exception
* e) { System.out.println("表单处理异常:"); e.printStackTrace(); }finally {
* form.save(); form.unlock(); }
*/
}
}
}
MessageBox.post("对象【"+item_id+"】创建完成!" , "提示", MessageBox.INFORMATION);
}else {
MessageBox.post("对象【"+item_id+"】创建失败!" , "提示", MessageBox.ERROR);
}
}
/**
* 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) {
//判断入参是否有效
if (configName == null || lovShowName == null || lovPropertyList2 == null){
System.out.println("getLovTrueValue入参无效");
return null;
}
String trueNameString = null;
//通过lov属性集合遍历获取lov真实值
//1.先根据普通一层lov和动态lov分别获取lov真实值
for (LovProperty lovProperty : lovPropertyList2) {
String propName = lovProperty.getPropTrueName();
if (configName.equals(propName)) {
Map<String, String> lovMap = lovProperty.getLovMap();
return lovMap.get(lovShowName);
String lovType = lovProperty.getLovType();
if (configName.equals(propName)) {//属性真实名称与lov属性集合匹配
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;
}
}
System.out.println("未获取到lov-["+lovShowName+"]的真实值");
return null;
//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子项《显示值-真实值》集合
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
@ -494,9 +541,11 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
finalPropValue = tValueString;
}
System.out.println("设置表单属性["+tNameString+"]="+finalPropValue);
setTCPropertyValue(form,tNameString,finalPropValue);
if (finalPropValue != null) {
System.out.println("设置表单属性["+tNameString+"]="+finalPropValue);
setTCPropertyValue(form,tNameString,finalPropValue);
}
}
}
System.out.println("表单属性赋值完成!");
@ -512,7 +561,6 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
form.unlock();
}
} catch (TCException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
@ -534,6 +582,9 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
* @throws
*/
public static void setTCPropertyValue(TCComponent item, String propertyName, Object value) {
if (item == null || propertyName == null || value == null) {
return;
}
try {
String type2 = item.getType();
TCProperty tcProperty = item.getTCProperty(propertyName);
@ -576,7 +627,6 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@ -639,7 +689,6 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
Object s = e.getSource();
try {
if (s.equals(this.okButton)) {
@ -650,7 +699,6 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
try {
buildDrawingObjTypeFrame();
} catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
}
@ -669,7 +717,6 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
try {
createItem();
} catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
}
@ -680,22 +727,24 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
} catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
}
}
/**
*
* @return
*/
private boolean checkRequiredProp() {
System.out.println("propComponentMap.size="+propComponentMap.size());
// System.out.println("propComponentMap.size="+propComponentMap.size());
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+"】包含必选项!");
@ -713,20 +762,47 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
}
/**
* @
* @param component
*
*
* @param propShowName
* @param component
* @return
*/
public String getComponentValue(JComponent component) {
public String getComponentValue(String propShowName, JComponent component) {
System.out.println("开始根据不同类型的组件取值");
if (component instanceof JTextField) {
System.out.println("JTextField");
return ((JTextField) component).getText();
} else if (component instanceof JComboBox) {
System.out.println("JComboBox");
JComboBox<String> comboBox = (JComboBox<String>) component;
return (String)comboBox.getSelectedItem();
} else if (component instanceof DateButton) {
//通过显示名称判断该属性是否是lov
String lovType = null;
for (LovProperty lovProperty : this.lovPropertyList) {
if (lovProperty.getPropName().equals(propShowName)) {
lovType = lovProperty.getLovType();
break;
}
}
System.out.println("属性"+propShowName+"的lovtype="+(lovType == null ? "非lov属性" : lovType));
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();
chooseDisplay = userObject.toString();
}else {
System.out.println("选中节点selectedNode = null");
}
} else {
System.out.println("JComboBox");
JComboBox<String> comboBox = (JComboBox<String>) component;
chooseDisplay = (String)comboBox.getSelectedItem();
}
return chooseDisplay;
}else if (component instanceof DateButton) {
System.out.println("DateButton");
DateButton dateButton = (DateButton) component;
Date date = dateButton.getDate();
@ -746,9 +822,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();
@ -759,8 +835,19 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
frame.setTitle("临时图纸创建界面");
this.setSize(400, 500);
this.setLayout(new BorderLayout());
// 创建滚动面板
JScrollPane scrollPane = new JScrollPane();
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); // 垂直滚动条始终显示
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); // 禁用水平滚动条
JPanel centerPanel1 = new JPanel(new GridBagLayout());
// 设置内容面板的最小高度(确保滚动条生效)
centerPanel1.setMinimumSize(new Dimension(380, 800)); // 根据实际内容调整高度
scrollPane.setViewportView(centerPanel1); // 将内容面板放入滚动面板
JPanel buttomPanel1 = new JPanel(new FlowLayout());
//1.属性条目区域
@ -770,10 +857,7 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
if (idValue != null){
this.idTextField = new JTextField(idValue);
}
this.revLabel = new JLabel("版本");
String[] revs = {"S01"};//版本下拉框数组
this.revComboBox = new JComboBox<String>(revs);
// this.revComboBox.setEditable(true);
//布局
// ID Label
@ -797,31 +881,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) {
@ -833,10 +894,42 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
}
System.out.println("配置的属性数量 = "+this.preferencePropList.size());
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;
String validPropName = null;//属性条目(除去符号*后)的有效值
if (propConfigInfoArray.length >= 3){
String name = propConfigInfoArray[0];//“图纸类型”
System.out.println("开始获取首选项配置属性["+name+"]的信息");
@ -897,40 +990,88 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
centerPanel1.add(dateButton, gbcPropCombo);
propComponentMap.put(validPropName, dateButton);
} else if (typeValue.equals("lov")) {
//TODO 根据冒号后面的LOV名称获取多个lov值封装成数组添加到propComboBox中
// 根据冒号后面的LOV名称获取多个lov值封装成数组添加到propComboBox中
if (lovName == null) {
System.out.println("未获取到属性["+name+"]配置的lov名称请检查配置!");
return null;
}
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类型的属性类存放lov类型的属性信息
TCComponentListOfValues unitLov = TCLOVUtil.findLOVByName(tcSession, lovName);
String lovType = null;
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 i1 = 0; i1 < dynamicLOV.length; i1++) {
dlovList.add(dynamicLOV[i1]);
}
lovProperty.setDlovList(dlovList);
}else {
System.out.println("获取属性["+name+"]的LOV类型为未知类型");
}
}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);
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);
//根据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 {
String[] dlov = lovProperty.getDlovList().toArray(new String[0]);
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);
}
}
propIndex ++;
}else {
System.out.println("首选项中配置的属性["+name+"]信息中,未正确配置属性类型!");
}
propIndex ++;
}else {
System.out.println("首选项["+preferenceName+"]配置格式不正确,请检查!");
}
@ -949,7 +1090,8 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
this.closeButton.addActionListener(this);
this.buildButton.addActionListener(this);
frame.add(centerPanel1, BorderLayout.CENTER);
// 将滚动面板添加到框架中央
frame.add(scrollPane, BorderLayout.CENTER);
frame.add(buttomPanel1, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
@ -970,6 +1112,80 @@ 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;
}
/**
* 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
@ -1007,28 +1223,39 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
// 替换掉所有的 * 符号
return str.replaceAll("\\*", "");
}
/**
* TC LOV-
* @param seesion
* @return
* @param lovProp lov /
* @return lov<->
* @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)
{
ListOfValuesInfo listOfValues = unitLov.getListOfValues();
String[] realval = listOfValues.getStringListOfValues();
if(unitLov != null){
String[] realval = unitLov.getListOfValues().getStringListOfValues();
String value="";
boolean flag = false;
for (int i = 0; i < realval.length; i++) {
String disval = listOfValues.getDisplayableValue(realval[i]);
Display_values.put(disval, 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]);
}
}else {
// System.out.println("未找到LOV名称=["+lovProp+"]的lov对象");
}
if (!Display_values.isEmpty()){
rMap.put(lovProp, Display_values);
}
return Display_values;
}

@ -1,5 +1,6 @@
package cn.net.connor.createTempDrawings.pojo;
import java.util.List;
import java.util.Map;
/**
* LOV
@ -7,17 +8,60 @@ import java.util.Map;
*
*/
public class LovProperty {
//属性名称
//看板上属性条目的最终显示名称
private String propName;
//看板上属性条目对应属性的真实名称
private String propTrueName;
//属性
//属性
private String propValue;
private boolean isLov;
/**
* DLOVlov
* LOVlov key-value
*/
private String lovType;
/**
* @return lovType
*/
public String getLovType() {
return lovType;
}
/**
* lov-
* lov-lov
*/
private Map<String, String> lovMap;
//专门用于存放动态lov的list集合
private List<String> dlovList;
/**
* @param lovType lovType
*/
public void setLovType(String lovType) {
this.lovType = lovType;
}
/**
* @return dlovList
*/
public List<String> getDlovList() {
return dlovList;
}
/**
* @param dlovList dlovList
*/
public void setDlovList(List<String> dlovList) {
this.dlovList = dlovList;
}
public String getPropName() {
return propName;
}

@ -0,0 +1,226 @@
package cn.net.connor.createTempDrawings.utils;
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.plaf.basic.BasicComboBoxUI;
import javax.swing.plaf.basic.BasicComboPopup;
import javax.swing.plaf.basic.ComboPopup;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.*;
public class JTreeComboBox extends JComboBox<Object> {
private JTree tree;
private DefaultTreeModel treeModel;
private boolean suppressEvents = false;
public JTreeComboBox(DefaultMutableTreeNode root) {
System.out.println("JTreeComboBox构造函数被调用root是否为null: " + (root == null));
// 初始化树模型
treeModel = new DefaultTreeModel(root);
tree = new JTree(treeModel);
System.out.println("树对象已初始化: " + (tree != null));
// 设置自定义UI
setUI(new TreeComboBoxUI());
System.out.println("自定义UI已设置");
// 设置树属性
tree.setRootVisible(true);
tree.setShowsRootHandles(true);
tree.setCellRenderer(new TreeCellRenderer());
// 添加选择监听器
tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (!suppressEvents) {
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");
}
}
}
});
// 处理鼠标点击事件
tree.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
TreePath path = tree.getPathForLocation(e.getX(), e.getY());
if (path != null) {
tree.setSelectionPath(path);
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
if (node != null) {
if (tree.isExpanded(path)) {
tree.collapsePath(path);
} else {
tree.expandPath(path);
}
}
}
}
});
// 处理键盘事件
tree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE || e.getKeyCode() == KeyEvent.VK_ENTER) {
TreePath selectionPath = tree.getSelectionPath();
if (selectionPath != null) {
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
if (selectedNode != null) {
setSelectedItem(selectedNode);
hidePopup();
e.consume();
}
}
} else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
hidePopup();
e.consume();
}
}
});
// 设置整个 JComboBox 的 renderer
this.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
value = node.getUserObject(); // 使用节点的用户对象作为显示内容
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
// 初始选择根节点
setSelectedItem(root);
System.out.println("JTreeComboBox初始化完成");
}
@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);
suppressEvents = true;
super.setSelectedItem(anObject);
suppressEvents = false;
// 更新树的选择状态
System.out.println("选中项类型 = "+anObject.getClass().getTypeName());
if (anObject instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) anObject;
TreePath path = new TreePath(node.getPath());
tree.setSelectionPath(path);
}else {
System.out.println("选中项:"+anObject+"不是DefaultMutableTreeNode类型设置选中项失败");
}
revalidate(); // 触发布局更新
repaint(); // 触发重绘
}
public JTree getTree() {
return tree;
}
private class TreeComboBoxUI extends BasicComboBoxUI {
@Override
protected ComboPopup createPopup() {
System.out.println("创建弹出框树对象是否为null: " + (tree == null));
return new TreeComboPopup(comboBox, tree);
}
@Override
protected ListCellRenderer<Object> createRenderer() {
return new ListCellRenderer<Object>() {
private final DefaultListCellRenderer renderer = new DefaultListCellRenderer();
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
value = node.getUserObject();
}
return renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
};
}
}
private static class TreeComboPopup extends BasicComboPopup {
private JTree tree;
public TreeComboPopup(JComboBox<?> comboBox, JTree tree) {
super(comboBox);
this.tree = tree;
System.out.println("TreeComboPopup构造函数被调用树对象是否为null: " + (tree == null));
removeAll();
setLayout(new BorderLayout());
// 添加滚动面板包含树
JScrollPane scrollPane = new JScrollPane(tree);
scrollPane.setBorder(null);
add(scrollPane, BorderLayout.CENTER);
// 设置弹出框大小
Dimension preferredSize = tree.getPreferredSize();
preferredSize.width = Math.max(preferredSize.width, 200);
preferredSize.height = Math.min(preferredSize.height, 200);
preferredSize.height = 150;
setPreferredSize(preferredSize);
}
@Override
protected void configureList() {
// 不使用默认的列表
}
@Override
public void show() {
super.show();
// 展开根节点
tree.expandPath(new TreePath(((DefaultMutableTreeNode) tree.getModel().getRoot()).getPath()));
}
}
private static class TreeCellRenderer extends DefaultTreeCellRenderer {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
value = node.getUserObject();
}
return super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
}
}
}
Loading…
Cancel
Save