diff --git a/src/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.java b/src/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.java index 7fe8f38..4abfbbb 100644 --- a/src/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.java +++ b/src/cn/net/connor/createTempDrawings/dialogs/CreateTempDrawingDialog.java @@ -1,42 +1,100 @@ package cn.net.connor.createTempDrawings.dialogs; import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; import java.awt.FlowLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +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.util.regex.Matcher; +import java.util.regex.Pattern; import javax.swing.*; import com.teamcenter.rac.aif.AbstractAIFApplication; import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPreferenceService; import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.DateButton; +import com.teamcenter.rac.util.MessageBox; import com.teamcenter.rac.util.PropertyLayout; import com.teamcenter.rac.util.UIUtilities; -public class CreateTempDrawingDialog extends AbstractAIFDialog implements ActionListener{ +public class CreateTempDrawingDialog extends JFrame implements ActionListener{ private AbstractAIFApplication application; private TCSession tcSession ; + private InterfaceAIFComponent selectComponent; private JLabel drawingObjTypeLabel;//图纸对象类型标签 private JComboBox drawingObjTypeComboBox;//图纸对象类型下拉输入框 private JButton okButton;//确认按钮 - - public CreateTempDrawingDialog(AbstractAIFApplication application) { - super(true); - this.application = application; - this.tcSession = (TCSession) this.application.getSession(); - } - - + private JButton button1;//按钮 + private JButton button2;//按钮 + private List drawingObjTypeInfos = new ArrayList();//首选项中配置的对象类型信息 + private JFrame buildFram; + private String currentChoosePropPreferenceName;//当前选中类型的 - @Override - public void run() { + + + /** + * 类构造函数 + * @param application + * @param selectComponent + */ + public CreateTempDrawingDialog(AbstractAIFApplication application, InterfaceAIFComponent selectComponent) { try { + this.application = application; + this.tcSession = (TCSession) this.application.getSession(); + this.selectComponent = selectComponent; + System.out.println("开始加载创建临时图纸面板!"); + List list1 = getPreferenceInfos("SB6_Create_LS_Design"); + if (list1.isEmpty() || list1.size() <= 0) { + MessageBox.post("获取首选项SB6_Create_LS_Design配置信息失败,请检查配置是否正确!" , "提示", MessageBox.INFORMATION); + return; + }else { + if (this.drawingObjTypeInfos != null && this.drawingObjTypeInfos.size() > 0) { + this.drawingObjTypeInfos.clear(); + } + this.drawingObjTypeInfos.addAll(list1); + } initUI(); } catch (Exception e) { + // TODO: handle exception e.printStackTrace(); } + + } + + /** + * 根据首选项名称获取首选项配置信息 + * @param preferenceName 首选项名称 + * @return List + */ + public List getPreferenceInfos(String preferenceName) { + List drawingObjPropInfosList = new ArrayList<>(); + + TCPreferenceService preferenceService = tcSession.getPreferenceService(); + String[] values = preferenceService.getStringValues(preferenceName); + if (values.length > 0) { + for (int i = 0; i < values.length; i++) { + drawingObjPropInfosList.add(values[i]); + } + }else { + System.out.println("获取首选项["+preferenceName+"]配置信息失败,请检查配置是否正确!"); + } + System.out.println("共获取到首选项["+preferenceName+"]中的["+values.length+"]条配置信息"); + return drawingObjPropInfosList; + } /** @@ -44,55 +102,391 @@ public class CreateTempDrawingDialog extends AbstractAIFDialog implements Action */ private void initUI() throws Exception { this.setTitle("请选择图纸类型"); - this.setSize(800,600); - this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); - - JPanel centerPanel = new JPanel(new PropertyLayout()); + this.setSize(800, 600); + this.setLayout(new BorderLayout()); + + JPanel centerPanel = new JPanel(new GridBagLayout()); JPanel buttomPanel = new JPanel(new FlowLayout()); - this.drawingObjTypeLabel = new JLabel("图纸对象类型 "); - String[] drawingTypes = {"类型1", "类型2", "类型3"}; - JComboBox drawingObjTypeComboBox = new JComboBox(drawingTypes); - - - - centerPanel.add("1.3.left.top",drawingObjTypeLabel); - centerPanel.add("1.4.left.top",drawingObjTypeComboBox); + this.drawingObjTypeLabel = new JLabel("图纸对象类型 "); + //获取图纸对象类型 + List typList = getDrawingObjTypeShowName(); + if (typList.isEmpty() || typList.size() <= 0) { + System.out.println("获取图纸对象类型失败,请检查相关首选项是否配置正确!"); + return; + } + String[] drawingTypes = typList.toArray(new String[0]); + this.drawingObjTypeComboBox = new JComboBox(drawingTypes); + drawingObjTypeComboBox.setPreferredSize(new Dimension(200, drawingObjTypeComboBox.getPreferredSize().height)); + drawingObjTypeComboBox.setEditable(false); + + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridx = 0; + gbc.gridy = 0; + gbc.anchor = GridBagConstraints.WEST; + gbc.insets = new Insets(0, 0, 0, 12); // 右边留出 10 像素的间距 + centerPanel.add(this.drawingObjTypeLabel, gbc); + + gbc.gridx = 1; + centerPanel.add(drawingObjTypeComboBox, gbc); this.okButton = new JButton("确认"); buttomPanel.add(okButton); - //按钮时间监听 - okButton.addActionListener(this); //构造主面板 - this.setLayout(new BorderLayout()); this.add(centerPanel, BorderLayout.CENTER); this.add(buttomPanel, BorderLayout.SOUTH); + + //按钮时间监听 + this.okButton.addActionListener(this); + + + + this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + this.setResizable(true); + this.setPreferredSize(new Dimension(800,600)); + this.pack(); // 自动调整窗口大小以适应内部组件 + //放到屏幕中央 UIUtilities.centerToScreen(this); + this.setVisible(true); } + /** + * 获取创建临时图纸对象时,选择类型界面的类型名称集合 + * @return List + */ + private List getDrawingObjTypeShowName() { + List drawingObjTypeList = new ArrayList<>(); + if (this.drawingObjTypeInfos != null && this.drawingObjTypeInfos.size() > 0){ + for (int i = 0; i < this.drawingObjTypeInfos.size(); i++) { + String drawingObjTypeInfo = this.drawingObjTypeInfos.get(i); + String[] drawingObjTypeInfoArray = drawingObjTypeInfo.split("="); + if (drawingObjTypeInfoArray.length == 3) {//配置的信息中只有两个=符号 + drawingObjTypeList.add(drawingObjTypeInfoArray[0]); + }else{ + System.out.println("配置信息:["+drawingObjTypeInfo+"]格式不正确,请检查相关首选项是否配置正确!"); + } + } + } + + return drawingObjTypeList; + } + + /** + * 获取选中的图纸类型对应的首选项名称 + * @return + */ + private String getSelectTypePreferenceName() { + String returnValue = null; + //当前选中的图纸类型 + String chooseType1 = (String) this.drawingObjTypeComboBox.getSelectedItem(); + + List drawingObjTypeList = new ArrayList<>(); + if (this.drawingObjTypeInfos != null && this.drawingObjTypeInfos.size() > 0){ + for (int i = 0; i < this.drawingObjTypeInfos.size(); i++) { + String drawingObjTypeInfo = this.drawingObjTypeInfos.get(i); + String[] drawingObjTypeInfoArray = drawingObjTypeInfo.split("="); + if (drawingObjTypeInfoArray.length == 3) {//配置的信息中只有两个=符号 + //遍历到的类型名称 + String typeName = drawingObjTypeInfoArray[0]; + if (chooseType1 != null && typeName != null){ + if (chooseType1.equals(typeName)) { + returnValue = drawingObjTypeInfoArray[2]; + break; + } + } + }else{ + System.out.println("配置信息:["+drawingObjTypeInfo+"]格式不正确,请检查相关首选项是否配置正确!"); + } + } + } + + return returnValue; + } + + + @Override public void actionPerformed(ActionEvent e) { // TODO 自动生成的方法存根 Object s = e.getSource(); try { - if (e.equals(this.okButton)) { - System.out.println("成功触发“确认”按钮!"); - - + if (s.equals(this.okButton)) { + String chooseType = (String) this.drawingObjTypeComboBox.getSelectedItem(); + System.out.println("当前选中图纸对象类型="+chooseType); + // 关闭当前窗口 + this.dispose(); + buildDrawingObjTypeFrame(); + }else if (s.equals(this.closeButton)) { + System.out.println("触发‘关闭’按钮"); + // 关闭新建窗口 + this.buildFram.dispose(); + }else if (s.equals(this.buildButton)) { + System.out.println("触发‘新建’按钮"); + // 关闭新建窗口 + this.buildFram.dispose(); + + + + } + + } catch (Exception e2) { // TODO: handle exception } } + + private JLabel idLabel; + private JTextField idTextField; + private JLabel revLabel; + private JComboBox revComboBox; + private List showPropsInfoList = new ArrayList<>(); + private JButton closeButton; + private JButton buildButton; + /** + * 绘制对象类型的创建对话框 + * @return + * @throws TCException + */ + public JFrame buildDrawingObjTypeFrame() throws TCException{ + System.out.println("创建新图纸界面!"); + // 创建新界面 + JFrame frame = new JFrame(); + frame.setTitle("临时图纸创建界面"); + this.setSize(400, 300); + this.setLayout(new BorderLayout()); + + JPanel centerPanel1 = new JPanel(new GridBagLayout()); + JPanel buttomPanel1 = new JPanel(new FlowLayout()); + + //1.属性条目区域 + this.idLabel = new JLabel("ID*"); + String idValue = getIdValue(this.selectComponent); + + if (idValue != null){ + this.idTextField = new JTextField(idValue); + } + this.revLabel = new JLabel("版本"); + String[] revs = {"S01"};//版本下拉框数组 + this.revComboBox = new JComboBox(revs); +// this.revComboBox.setEditable(true); + + +//布局 + // ID Label + GridBagConstraints gbcIdLabel = new GridBagConstraints(); + gbcIdLabel.gridx = 0; + gbcIdLabel.gridy = 0; + gbcIdLabel.anchor = GridBagConstraints.WEST; + gbcIdLabel.insets = new Insets(5, 5, 5, 5); + centerPanel1.add(this.idLabel, gbcIdLabel); + + // ID TextField + GridBagConstraints gbcIdField = new GridBagConstraints(); + gbcIdField.gridx = 1; + gbcIdField.gridy = 0; + gbcIdField.anchor = GridBagConstraints.WEST; + + // 设置自定义宽度 + Dimension textFieldSize = new Dimension(200, idTextField.getPreferredSize().height); // 将200设为所需的宽度 + idTextField.setPreferredSize(textFieldSize); + + centerPanel1.add(this.idTextField, gbcIdField); + + + // 版本 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); + String preferenceName = getSelectTypePreferenceName(); + int propIndex = 2; + if (preferenceName != null){ + List propList = getPreferenceInfos(preferenceName); + for(String propInfo : propList){//propInfo格式为:*有效期=Form.sb6_validuntil=date=Form.sb6_validuntil + String[] propConfigInfoArray= propInfo.split("="); + 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 + "*"; + } + JLabel propLabel = new JLabel(name); + GridBagConstraints gbcPropLabel = new GridBagConstraints(); + gbcPropLabel.gridx = 0; + gbcPropLabel.gridy = propIndex; + gbcPropLabel.anchor = GridBagConstraints.WEST; + gbcPropLabel.insets = new Insets(5, 5, 5, 5); + centerPanel1.add(propLabel, gbcPropLabel); + + // prop value组件 + if (type != null){ + String typeValue = type.split(":")[0]; + if (typeValue.equals("string")){ + JTextField propTextField = new JTextField(); + + GridBagConstraints gbcPropCombo = new GridBagConstraints(); + gbcPropCombo.gridx = 1; + gbcPropCombo.gridy = propIndex; + gbcPropCombo.anchor = GridBagConstraints.WEST; + + // 设置自定义宽度 + Dimension propValueSize = new Dimension(200, propTextField.getPreferredSize().height); // 将200设为所需的宽度 + propTextField.setPreferredSize(propValueSize); + + centerPanel1.add(propTextField, gbcPropCombo); + }else if (typeValue.equals("date")){ + DateButton dateButton = new DateButton(null, "yyyy-MM-dd", false, false, false); + + GridBagConstraints gbcPropCombo = new GridBagConstraints(); + gbcPropCombo.gridx = 1; + gbcPropCombo.gridy = propIndex; + gbcPropCombo.anchor = GridBagConstraints.WEST; + + // 设置自定义宽度 + Dimension propValueSize = new Dimension(200, dateButton.getPreferredSize().height); // 将200设为所需的宽度 + dateButton.setPreferredSize(propValueSize); + + centerPanel1.add(dateButton, gbcPropCombo); + } else if (typeValue.equals("lov")) { + //TODO 根据冒号后面的LOV名称获取多个lov值,封装成数组添加到propComboBox中 + //TODO 文档中的继承属性来源又是个啥??? + String[] lovs = {"lov1","lov2","lov3"};//模拟多个lov值 + JComboBox propComboBox = new JComboBox(lovs); + //TODO 根据冒号后面的LOV名称获取多个lov值,封装成数组添加到propComboBox中 + //TODO 文档中的继承属性来源又是个啥??? + String[] lovs = {"lov1","lov2","lov3"};//模拟多个lov值 + + + 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); + + } + } + + propIndex ++; + } + + + } + + }else { + System.out.println("未找到选中类型对应的首选项,请检查首选项SB6_Create_LS_Design配置是否正确!"); + } + + + + + + + //2.按钮区域 + this.closeButton = new JButton("关闭"); + buttomPanel1.add(closeButton); + this.buildButton = new JButton("新建"); + buttomPanel1.add(buildButton); + + //按钮事件监听 + this.closeButton.addActionListener(this); + this.buildButton.addActionListener(this); + + frame.add(centerPanel1, BorderLayout.CENTER); + frame.add(buttomPanel1, BorderLayout.SOUTH); + + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + frame.setResizable(true); + frame.setPreferredSize(new Dimension(800,600)); + frame.pack(); // 自动调整窗口大小以适应内部组件 + + //放到屏幕中央 + UIUtilities.centerToScreen(this); + + frame.setVisible(true); + + this.buildFram = frame; + + return frame; + + } + + /** + * 根据选中对象(业务逻辑)获取ID输入框中的默认值 + * @param selectComponent2 选中对象 + * @return ID输入框中的默认值 + * @throws TCException + */ + private String getIdValue(InterfaceAIFComponent selectComponent2) throws TCException { +// String idValue = ""; + + if(selectComponent2 instanceof TCComponentItemRevision){ + System.out.println("当前选中对象是版本对象,开始获取创建界面的ID属性值"); + TCComponentItemRevision itemRevision = (TCComponentItemRevision) selectComponent2; + String idValue = itemRevision.getStringProperty("item_id"); + if (idValue != null && !idValue.equals("")){ + return idValue.replace("_",""); + }else {{ + return null;//获取版本对象的ID失败 + }} + }else if (selectComponent instanceof TCComponentFolder) { + System.out.println("当前选中对象是文件夹对象,创建界面的ID属性值置空"); + return ""; + }else { + return null; + } + } + + /** + * 只提取字符串中的中文字符 + */ + public String extractChinese(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(); + } + } diff --git a/src/cn/net/connor/createTempDrawings/handlers/CreateTempDrawingHandler.java b/src/cn/net/connor/createTempDrawings/handlers/CreateTempDrawingHandler.java index b8e6655..94d7b33 100644 --- a/src/cn/net/connor/createTempDrawings/handlers/CreateTempDrawingHandler.java +++ b/src/cn/net/connor/createTempDrawings/handlers/CreateTempDrawingHandler.java @@ -22,6 +22,10 @@ public class CreateTempDrawingHandler extends AbstractHandler { AbstractAIFApplication application = AIFUtility.getCurrentApplication(); //1.判断选中对象是否符合要求 InterfaceAIFComponent selectComponent = application.getTargetContext().getComponent(); + if (selectComponent == null) { + MessageBox.post("请选中对象再操作!" , "提示", MessageBox.INFORMATION); + return null; + } System.out.println("当前选中对象类型为:"+selectComponent.getType()); try { @@ -37,9 +41,9 @@ public class CreateTempDrawingHandler extends AbstractHandler { } if (flag != 0) { - CreateTempDrawingDialog dialog = new CreateTempDrawingDialog(application); + CreateTempDrawingDialog dialog = new CreateTempDrawingDialog(application, selectComponent); - new Thread(dialog).start(); +// new Thread(dialog).start(); }else { MessageBox.post("请选择文件夹或试制联系单版本或临时问题处理通知单版本后执行创建临时图纸功能!" , "提示", MessageBox.INFORMATION);