feat(create-temp-drawings): 新增图纸属性校验功能

- 添加了图纸属性校验功能,确保必填项不为空
- 新增日期格式化工具,用于处理日期类型的属性
- 优化了用户界面布局,调整了窗口大小
- 重构了部分代码,提高了可维护性
mian
熊朝柱 1 month ago
parent d805cab0c8
commit b2f3ca79aa

@ -10,8 +10,8 @@ import java.awt.Insets;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -42,7 +42,20 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
private List<String> drawingObjTypeInfos = new ArrayList<String>();//首选项中配置的对象类型信息
private JFrame buildFram;
private String currentChoosePropPreferenceName;//当前选中类型的
private JLabel idLabel;
private JTextField idTextField;
private JLabel revLabel;
private JComboBox<String> revComboBox;
private List<String> showPropsInfoList = new ArrayList<>();
private JButton closeButton;
private JButton buildButton;
// 添加日期格式化工具
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
/**
*
*/
private Map<String,JComponent> propComponentMap = new HashMap<>();
/**
@ -102,7 +115,7 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
*/
private void initUI() throws Exception {
this.setTitle("请选择图纸类型");
this.setSize(800, 600);
this.setSize(400, 500);
this.setLayout(new BorderLayout());
JPanel centerPanel = new JPanel(new GridBagLayout());
@ -228,12 +241,18 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
this.buildFram.dispose();
}else if (s.equals(this.buildButton)) {
System.out.println("触发‘新建’按钮");
// 关闭新建窗口
this.buildFram.dispose();
// 校验必填项
if(!checkRequiredProp()){
System.out.println("校验未通过!");
return ;
}
// 关闭新建窗口
this.buildFram.dispose();
}
@ -244,15 +263,52 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
}
/**
*
* @return
*/
private boolean checkRequiredProp() {
if (propComponentMap.size()>0) {
for (Map.Entry<String, JComponent> entry : propComponentMap.entrySet()) {
String key = entry.getKey();
Object value = getComponentValue(entry.getValue());
System.out.println("开始校验属性:"+key);
if (key.contains("*")) {
System.out.println("属性【"+key+"】包含必选项!");
if (value == null || value.equals("")) {
MessageBox.post("必填项属性【"+key+"】不可为空!" , "提示", MessageBox.INFORMATION);
return false;
}
}
System.out.println(key + ": " + value);
}
}
return true;
}
/**
*
* @param component
* @return
*/
public String getComponentValue(JComponent component) {
if (component instanceof JTextField) {
return ((JTextField) component).getText();
} else if (component instanceof JComboBox) {
JComboBox<String> comboBox = (JComboBox<String>) component;
return (String)comboBox.getSelectedItem();
} else if (component instanceof DateButton) {
DateButton dateButton = (DateButton) component;
Date date = dateButton.getDate();
String dateInput = dateFormat.format(date).replaceAll("(\\d{4})-0(\\d)-", "$1-$2-") + " 00:00";
return dateInput;
}
return null;
}
private JLabel idLabel;
private JTextField idTextField;
private JLabel revLabel;
private JComboBox<String> revComboBox;
private List<String> showPropsInfoList = new ArrayList<>();
private JButton closeButton;
private JButton buildButton;
/**
*
* @return
@ -260,10 +316,12 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
*/
public JFrame buildDrawingObjTypeFrame() throws TCException{
System.out.println("创建新图纸界面!");
this.propComponentMap.clear();
// 创建新界面
JFrame frame = new JFrame();
frame.setTitle("临时图纸创建界面");
this.setSize(400, 300);
this.setSize(400, 500);
this.setLayout(new BorderLayout());
JPanel centerPanel1 = new JPanel(new GridBagLayout());
@ -302,6 +360,7 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
idTextField.setPreferredSize(textFieldSize);
centerPanel1.add(this.idTextField, gbcIdField);
propComponentMap.put("ID*", idTextField);
// 版本 Label
@ -323,21 +382,28 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
revComboBox.setPreferredSize(comboBoxSize);
centerPanel1.add(this.revComboBox, gbcRevCombo);
propComponentMap.put("版本", revComboBox);
String preferenceName = getSelectTypePreferenceName();
int propIndex = 2;
if (preferenceName != null){
List<String> propList = getPreferenceInfos(preferenceName);
for(String propInfo : propList){//propInfo格式为*有效期=Form.sb6_validuntil=date=Form.sb6_validuntil
String[] propConfigInfoArray= propInfo.split("=");
String validPropName = null;
if (propConfigInfoArray.length >= 3){
String name = propConfigInfoArray[0];
String type = propConfigInfoArray[2];
// prop Label
if (name != null && name.contains("*")){
String chinese = extractChinese(name);
name = chinese + "*";
validPropName = removeAsterisk(name);
name = validPropName + "*";
}
validPropName = name;
JLabel propLabel = new JLabel(name);
GridBagConstraints gbcPropLabel = new GridBagConstraints();
gbcPropLabel.gridx = 0;
@ -362,6 +428,7 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
propTextField.setPreferredSize(propValueSize);
centerPanel1.add(propTextField, gbcPropCombo);
propComponentMap.put(validPropName, propTextField);
}else if (typeValue.equals("date")){
DateButton dateButton = new DateButton(null, "yyyy-MM-dd", false, false, false);
@ -375,14 +442,12 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
dateButton.setPreferredSize(propValueSize);
centerPanel1.add(dateButton, gbcPropCombo);
propComponentMap.put(validPropName, dateButton);
} else if (typeValue.equals("lov")) {
//TODO 根据冒号后面的LOV名称获取多个lov值封装成数组添加到propComboBox中
//TODO 文档中的继承属性来源又是个啥???
String[] lovs = {"lov1","lov2","lov3"};//模拟多个lov值
JComboBox<String> propComboBox = new JComboBox<String>(lovs);
//TODO 根据冒号后面的LOV名称获取多个lov值封装成数组添加到propComboBox中
//TODO 文档中的继承属性来源又是个啥???
String[] lovs = {"lov1","lov2","lov3"};//模拟多个lov值
GridBagConstraints gbcPropCombo = new GridBagConstraints();
@ -395,25 +460,17 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
propComboBox.setPreferredSize(propValueSize);
centerPanel1.add(propComboBox, gbcPropCombo);
propComponentMap.put(validPropName, propComboBox);
}
}
propIndex ++;
}
}
}else {
System.out.println("未找到选中类型对应的首选项请检查首选项SB6_Create_LS_Design配置是否正确");
}
//2.按钮区域
this.closeButton = new JButton("关闭");
buttomPanel1.add(closeButton);
@ -470,22 +527,15 @@ public class CreateTempDrawingDialog extends JFrame implements ActionListener{
}
/**
*
* *
*/
public String extractChinese(String str) {
public String removeAsterisk(String str) {
if (str == null || str.isEmpty()) {
return "";
}
// 使用正则表达式匹配中文字符
Pattern pattern = Pattern.compile("[\\u4e00-\\u9fa5]+");
Matcher matcher = pattern.matcher(str);
StringBuilder sb = new StringBuilder();
while (matcher.find()) {
sb.append(matcher.group());
}
return sb.toString();
// 替换掉所有的 * 符号
return str.replaceAll("\\*", "");
}

Loading…
Cancel
Save