事件监听器移到init方法中

main
熊朝柱 3 months ago
parent 7241c628d8
commit 3415cbc970

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/hutool-all-5.8.25.jar"/>
<classpathentry exported="true" kind="lib" path="lib/ojdbc8.jar"/>
<classpathentry kind="lib" path="lib/mssql-jdbc-7.0.0.jre8.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>

@ -1,5 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ASMSmaliIdeaPluginConfiguration">
<asm skipDebug="true" skipFrames="true" skipCode="false" expandFrames="false" />
<groovy codeStyle="LEGACY" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" default="true" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/classes" />
</component>

@ -17,6 +17,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ClassPath: lib/ojdbc8.jar,
.,
lib/swingx-1.6.1.jar,
lib/mssql-jdbc-7.0.0.jre8.jar
lib/mssql-jdbc-7.0.0.jre8.jar,
lib/hutool-all-5.8.25.jar
Export-Package: com.connor.processAttributeModification
Import-Package: com.teamcenter.rac.kernel

@ -6,4 +6,5 @@ bin.includes = plugin.xml,\
icons/,\
lib/ojdbc8.jar,\
lib/swingx-1.6.1.jar,\
lib/mssql-jdbc-7.0.0.jre8.jar
lib/mssql-jdbc-7.0.0.jre8.jar,\
lib/hutool-all-5.8.25.jar

@ -52,4 +52,5 @@
</menu>
</menuContribution-->
</extension>
</plugin>

@ -8,12 +8,15 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -26,6 +29,7 @@ import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
@ -62,13 +66,15 @@ import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PropertyLayout;
import cn.hutool.core.util.ArrayUtil;
public class ProcessAttriChangeDialog extends JDialog {
private static final long serialVersionUID = 1L;
private TCSession session;
private TCComponent[] modelsF;
private TCComponentTask taskF;
private LinkedHashMap<String, String[]> ruleOpsMapF;
private LinkedHashMap<String, String[]> ruleOpsMapF = new LinkedHashMap<>();
private int[] colsF;
private JButton remarkBtn;
private JButton exportBtn;
@ -99,13 +105,13 @@ public class ProcessAttriChangeDialog extends JDialog {
/**
* table
*/
private TCComponentItemRevision targetRevision = null;
private List<TCComponentItemRevision> targetRevision = new ArrayList<TCComponentItemRevision>();
private JPanel topPanel = null;
/**
*
*
*/
private int chooseRow = -1;
private List<Integer> chooseRows = new ArrayList<Integer> ();
/**
*
@ -123,24 +129,125 @@ public class ProcessAttriChangeDialog extends JDialog {
this.modelsF = models;
this.taskF = task;
this.ruleOpsMapF = ruleOpsMap;
System.out.println("开始遍历存放首选项Jd_Standard_UI_Process_Attribute的信息的构造函数入参ruleOpsMap");
for (String key : ruleOpsMap.keySet()){
System.out.println(key+":"+Arrays.toString(ruleOpsMap.get(key)));
}
this.colsF = cols;
this.argMap = getHandlerArgs(task);
initUi( modelsF, taskF, ruleOpsMapF, colsF);
initUi( modelsF, taskF, ruleOpsMapF, colsF,null);
}
/**
*
*
* @param session
* @param models
* @param task
* @param ruleOpsMap key()valueString[]String["item/rev","object_name"]
* @param ruleOpsMapI key()valueString[]String["item/rev","object_name"]
* @param cols
* @param chooseRows
* @throws Exception
*/
private void initUi(TCComponent[] models, TCComponentTask task, LinkedHashMap<String, String[]> ruleOpsMap, int[] cols) throws Exception {
private void initUi(TCComponent[] models, TCComponentTask task, LinkedHashMap<String, String[]> ruleOpsMapI, int[] cols, List<Integer> chooseRows2) throws Exception {
// this.chooseRows.addAll(chooseRows2);
if (chooseRows2 != null && chooseRows2.size()>0) {
System.out.println("当前选中行="+Arrays.toString(chooseRows2.toArray()));
}else {
System.out.println("initUi-当前加载组件时未选中任何行!");
}
System.out.println("开始初始化/刷新面板···");
setTitle("编辑节点属性");
remarkBtn = new JButton("修改属性");
remarkBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {//修改属性按钮
System.out.println("触发修改属性事件~");
try {
// chooseRow = impTable.getSelectedRow();
System.out.println("当前选中行:" + impTable.getSelectedRow());
for (int i = 0; i < chooseRows.size(); i++) {
System.out.println("修改属性-选中行:" + chooseRows.get(i));
}
if(chooseRows.size() <= 0) {
MessageBox.post(ProcessAttriChangeDialog.this, "请选择要编辑的行!", "ERROR", MessageBox.ERROR);
return;
}
for (String key : textAreaMap.keySet()){
// String text = textAreaMap.get(key).getText();//获取输入框中的值
//
Object component = textAreaMap.get(key);
String text = getValueByAreaType(component);
if (text == null){
System.out.println("info获取输入框组件值异常");
}
String showAttr = argMap.get(key);//获取流程参数的value
if(text.getBytes().length > 1024) {
MessageBox.post(ProcessAttriChangeDialog.this, showAttr+"属性填写长度过长,无法修改!", "ERROR", MessageBox.ERROR);
return;
}else {
//获取列数
for (int t = 0; t < tableHeaderList.size(); t++){
if (tableHeaderList.get(t).equals(showAttr)){
for (int i = 0; i < chooseRows.size(); i++) {
impTable.setValueAt(text, chooseRows.get(i), t);
}
break;
}
}
}
}
for (int i = 0; i < chooseRows.size(); i++) {
TCComponentItemRevision rev = revlist.get(chooseRows.get(i));
TCComponentItem item = rev.getItem();
if(mark[0].equals("item") && item.isCheckedOut()) {
MessageBox.post(ProcessAttriChangeDialog.this, item+" 已签出,无法修改!", "ERROR", MessageBox.ERROR);
return;
}else if(mark[0].equals("rev") && rev.isCheckedOut()) {
MessageBox.post(ProcessAttriChangeDialog.this, rev+" 已签出,无法修改!", "E RROR", MessageBox.ERROR);
return;
}
MethodUtil.openByPass(session);
if(mark[0].equals("item")) {
for (String key : textAreaMap.keySet()){
// String value = textAreaMap.get(key).getText();
Object component = textAreaMap.get(key);
String inputValue = getValueByAreaType(component);
if (inputValue == null){
System.out.println("info获取输入框组件值异常");
}
item.setProperty(key, inputValue);
}
}else if(mark[0].equals("rev")) {
for (String key : textAreaMap.keySet()){
// String value = textAreaMap.get(key).getText();
Object component = textAreaMap.get(key);
String inputValue = getValueByAreaType(component);
if (inputValue == null){
System.out.println("info获取输入框组件值异常");
}
rev.setProperty(key, inputValue);
}
}
}
MethodUtil.closeByPass(session);
}catch(Exception e1) {
e1.printStackTrace();
MessageBox.post(ProcessAttriChangeDialog.this, "错误:"+e1.getMessage(), "ERROR", MessageBox.ERROR);
}finally {
try {
MethodUtil.closeByPass(session);
}catch(Exception e1) {
e1.printStackTrace();
}
}
}
});
exportBtn = new JButton("导出Excel");
closeBtn = new JButton("关闭");
JPanel btnPanel = new JPanel(new FlowLayout());
@ -173,19 +280,25 @@ public class ProcessAttriChangeDialog extends JDialog {
propertyPanel.add(labLocation,new JLabel(value));
//TODO 逻辑重构:根据不同属性类型,渲染不同的输入框
String[] attrs = ruleOpsMap.get(value);
String[] attrs = ruleOpsMapI.get(value);
if (attrs == null || attrs.length == 0){
System.out.println("info根据属性显示字段【"+value+"】获取属性信息失败,请检查相关首选项配置!");
}
String currentAttributeValue = null;//当前属性的值,用于渲染到看板输入框中
if (this.targetRevision != null){
System.out.println("====================================================================");
if (this.targetRevision != null && this.targetRevision.size() > 0){
System.out.println("info已选中对象开始根据选中对象的属性类型渲染组件···");
TCComponentItem targetItem = this.targetRevision.getItem();
//当选中多个对象时,默认将当前选中的第一个对象属性作为默认值渲染到属性编辑看板上
TCComponentItem targetItem = this.targetRevision.get(0).getItem();
//根据属性名称获取属性所属对象类型item/rev
String itemType = attrs[0];//item/rev
String propertyName = attrs[1];//属性名称
String propertyName = attrs[1];//属性真实名称
if (itemType.equals("item")){
currentAttributeValue = targetItem.getProperty(propertyName);//获取当前属性的值
}else {
currentAttributeValue = targetRevision.getProperty(propertyName);//获取当前属性的值
currentAttributeValue = targetRevision.get(0).getProperty(propertyName);//获取当前属性的值
}
//
@ -243,15 +356,12 @@ public class ProcessAttriChangeDialog extends JDialog {
topPanel.revalidate();
topPanel.repaint();
String[] tableHeader = new String[ruleOpsMap.size() + 1];
String[] tableHeader = new String[ruleOpsMapI.size() + 1];
tableHeader[0] = "序号";
int h = 1;
for (String s : ruleOpsMap.keySet()) {
for (String s : ruleOpsMapI.keySet()) {
tableHeader[h] = s;
// if(s.equals("标准化备注")) {
mark = ruleOpsMap.get(s);
// mrow = h;
// }
mark = ruleOpsMapI.get(s);
h++;
}
//将标题行添加到列表中
@ -271,14 +381,70 @@ public class ProcessAttriChangeDialog extends JDialog {
impTable.setEnabled(true);
impTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
impTable.setModel(impModel);
impTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
impTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {//单机鼠标
System.out.println("触发单击选中事件~");
try {
// chooseRow= impTable.getSelectedRows();
int[] selectedRows = impTable.getSelectedRows();
if(selectedRows.length <= 0) {
System.out.println("当前未选中任何对象 ");
return;
}
//选中行
// List<Integer> chooseRowTemp = new ArrayList<Integer>();
chooseRows.clear();//放入新的选中行前,清空选中行集合
targetRevision.clear();
System.out.println("当前选中行:");
for (int i = 0; i < selectedRows.length; i++) {
//选中行序号之一
int selectPartRowNum = selectedRows[i];
System.out.println("=>"+selectPartRowNum+" ;");
if (revlist != null && revlist.size() > 0) {
TCComponentItemRevision selectRevision = revlist.get(selectPartRowNum);//根据选中行的序号从revlist中获取该行对应的版本对象
if (selectRevision != null) {
targetRevision.add(selectRevision);
chooseRows.add(selectPartRowNum);
}
}else {
System.out.println("版本list为空");
}
}
if (targetRevision != null && targetRevision.size() > 0) {
System.out.println("二次渲染前的选中行:"+Arrays.toString(chooseRows.toArray()));
initUi(modelsF, taskF, ruleOpsMapF, colsF, chooseRows);
System.out.println("二次渲染后的选中行:"+Arrays.toString(chooseRows.toArray()));
}
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(ProcessAttriChangeDialog.this, "错误:" + e1.getMessage(), "ERROR", MessageBox.ERROR);
}
}
});
for (int i = 1; i < impModel.getColumnCount(); i++) {
TableColumn col = impTable.getColumnModel().getColumn(i);
col.setCellRenderer(new TextAreaRenderer());
col.setPreferredWidth(150);
}
setDatas(task, (TCComponentDataset) models[0], ruleOpsMap);
addActionListener(models, cols);
setDatas(task, (TCComponentDataset) models[0], ruleOpsMapI);
// // 移除旧的监听器
// for (MouseListener listener : impTable.getMouseListeners()) {
// impTable.removeMouseListener(listener);
// }
// addActionListener(models, cols);
setLayout(new BorderLayout());
topPanel.setPreferredSize(new Dimension(260, getHeight())); // 设置宽度
@ -291,6 +457,19 @@ public class ProcessAttriChangeDialog extends JDialog {
setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2);
setAlwaysOnTop(true);
setVisible(true);
//如果有选中行设置table的选中对应行状态
if (chooseRows != null && chooseRows.size() > 0) {
System.out.println("重新加载组件完成当前已选中行开始设置table选中状态");
List<Integer> uniqueRows = new ArrayList<>(new HashSet<>(chooseRows2)); // 去重
Collections.sort(uniqueRows); // 排序
for (int row : uniqueRows) {
impTable.addRowSelectionInterval(row, row);
}
}else{
System.out.println("当前未选中任何行重新加载组件后无需设置table选中状态");
}
}
/**
@ -452,61 +631,79 @@ public class ProcessAttriChangeDialog extends JDialog {
}
System.out.println("row:"+Arrays.toString(row));
impModel.addRow(row);
System.out.println("kumarev");
revlist.add(rev);
break;
}
}
}
/**
*
* @param models
* @param cols
*/
private void addActionListener(TCComponent[] models, int[] cols) {
impTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {//单机鼠标
System.out.println("触发单击选中事件~");
try {
chooseRow= impTable.getSelectedRow();
System.out.println("当前选中行:"+chooseRow);
if(chooseRow < 0) {
// chooseRow= impTable.getSelectedRows();
int[] selectedRows = impTable.getSelectedRows();
if(selectedRows.length <= 0) {
System.out.println("当前未选中任何对象 ");
return;
}
targetRevision = revlist.get(chooseRow);
if (targetRevision != null) {
initUi(modelsF, taskF, ruleOpsMapF, colsF);
//选中行
// List<Integer> chooseRowTemp = new ArrayList<Integer>();
chooseRows.clear();//放入新的选中行前,清空选中行集合
targetRevision.clear();
System.out.println("当前选中行:");
for (int i = 0; i < selectedRows.length; i++) {
//选中行序号之一
int selectPartRowNum = selectedRows[i];
System.out.println("=>"+selectPartRowNum+" ;");
if (revlist != null && revlist.size() > 0) {
TCComponentItemRevision selectRevision = revlist.get(selectPartRowNum);//根据选中行的序号从revlist中获取该行对应的版本对象
if (selectRevision != null) {
targetRevision.add(selectRevision);
chooseRows.add(selectPartRowNum);
}
}else {
System.out.println("版本list为空");
}
}
if (targetRevision != null && targetRevision.size() > 0) {
System.out.println("二次渲染前的选中行:"+Arrays.toString(chooseRows.toArray()));
initUi(modelsF, taskF, ruleOpsMapF, colsF, chooseRows);
System.out.println("二次渲染后的选中行:"+Arrays.toString(chooseRows.toArray()));
}
// for (String key : textAreaMap.keySet()){
// String showAttr = argMap.get(key);//显示在右边看板上的待编辑的属性名称
// //获取列数
// for (int t = 0; t < tableHeaderList.size(); t++){
// //为右侧编辑框赋值
// if (tableHeaderList.get(t).equals(showAttr)){
//// textAreaMap.get(key).setText(""+impTable.getValueAt(row, t));
// //TODO
// String setValue = "" + impTable.getValueAt(row, t);
// setModelValue(textAreaMap.get(key), setValue);
//
//
// break;
// }
// }
// }
} catch (Exception e1) {
e1.printStackTrace();
MessageBox.post(ProcessAttriChangeDialog.this, "错误:" + e1.getMessage(), "ERROR", MessageBox.ERROR);
}
}
});
remarkBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {//修改属性按钮
System.out.println("触发修改属性事件~");
try {
// int row = impTable.getSelectedRow();
chooseRow = impTable.getSelectedRow();
System.out.println("当前选中行:"+chooseRow);
if(chooseRow < 0) {
// chooseRow = impTable.getSelectedRow();
System.out.println("当前选中行:" + impTable.getSelectedRow());
for (int i = 0; i < chooseRows.size(); i++) {
System.out.println("修改属性-选中行:" + chooseRows.get(i));
}
if(chooseRows.size() <= 0) {
MessageBox.post(ProcessAttriChangeDialog.this, "请选择要编辑的行!", "ERROR", MessageBox.ERROR);
return;
}
@ -518,7 +715,7 @@ public class ProcessAttriChangeDialog extends JDialog {
if (text == null){
System.out.println("info获取输入框组件值异常");
}
String showAttr = argMap.get(key);//获取流程参数的value
if(text.getBytes().length > 1024) {
MessageBox.post(ProcessAttriChangeDialog.this, showAttr+"属性填写长度过长,无法修改!", "ERROR", MessageBox.ERROR);
@ -527,46 +724,51 @@ public class ProcessAttriChangeDialog extends JDialog {
//获取列数
for (int t = 0; t < tableHeaderList.size(); t++){
if (tableHeaderList.get(t).equals(showAttr)){
impTable.setValueAt(text, chooseRow, t);
for (int i = 0; i < chooseRows.size(); i++) {
impTable.setValueAt(text, chooseRows.get(i), t);
}
break;
}
}
}
}
TCComponentItemRevision rev = revlist.get(chooseRow);
TCComponentItem item = rev.getItem();
if(mark[0].equals("item") && item.isCheckedOut()) {
MessageBox.post(ProcessAttriChangeDialog.this, item+" 已签出,无法修改!", "ERROR", MessageBox.ERROR);
return;
}else if(mark[0].equals("rev") && rev.isCheckedOut()) {
MessageBox.post(ProcessAttriChangeDialog.this, rev+" 已签出,无法修改!", "E RROR", MessageBox.ERROR);
return;
}
}
MethodUtil.openByPass(session);
if(mark[0].equals("item")) {
for (String key : textAreaMap.keySet()){
// String value = textAreaMap.get(key).getText();
Object component = textAreaMap.get(key);
String inputValue = getValueByAreaType(component);
if (inputValue == null){
System.out.println("info获取输入框组件值异常");
}
item.setProperty(key, inputValue);
for (int i = 0; i < chooseRows.size(); i++) {
TCComponentItemRevision rev = revlist.get(chooseRows.get(i));
TCComponentItem item = rev.getItem();
if(mark[0].equals("item") && item.isCheckedOut()) {
MessageBox.post(ProcessAttriChangeDialog.this, item+" 已签出,无法修改!", "ERROR", MessageBox.ERROR);
return;
}else if(mark[0].equals("rev") && rev.isCheckedOut()) {
MessageBox.post(ProcessAttriChangeDialog.this, rev+" 已签出,无法修改!", "E RROR", MessageBox.ERROR);
return;
}
}else if(mark[0].equals("rev")) {
for (String key : textAreaMap.keySet()){
// String value = textAreaMap.get(key).getText();
Object component = textAreaMap.get(key);
String inputValue = getValueByAreaType(component);
if (inputValue == null){
System.out.println("info获取输入框组件值异常");
MethodUtil.openByPass(session);
if(mark[0].equals("item")) {
for (String key : textAreaMap.keySet()){
// String value = textAreaMap.get(key).getText();
Object component = textAreaMap.get(key);
String inputValue = getValueByAreaType(component);
if (inputValue == null){
System.out.println("info获取输入框组件值异常");
}
item.setProperty(key, inputValue);
}
}else if(mark[0].equals("rev")) {
for (String key : textAreaMap.keySet()){
// String value = textAreaMap.get(key).getText();
Object component = textAreaMap.get(key);
String inputValue = getValueByAreaType(component);
if (inputValue == null){
System.out.println("info获取输入框组件值异常");
}
rev.setProperty(key, inputValue);
}
rev.setProperty(key, inputValue);
}
}
MethodUtil.closeByPass(session);
}catch(Exception e1) {
e1.printStackTrace();
@ -640,7 +842,7 @@ public class ProcessAttriChangeDialog extends JDialog {
}
}
});
closeBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {

Loading…
Cancel
Save