yuxc
2025-01-15 c09f81131e8b7c83937206d7cf76f34d2020be75
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.vci.client.workflow.editor.ui;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
 
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
 
import com.vci.client.LogonApplication;
import com.vci.client.ui.swing.components.VCIJDialog;
import com.vci.client.workflow.commom.ClientHelper;
import com.vci.corba.workflow.data.CustomInfo;
import com.vci.corba.workflow.data.PropertyInfo;
 
public class CustomClassEditDialog extends VCIJDialog {
    private static final long serialVersionUID = 1300418480939892949L;
    
    private JTable customTable;
    private JButton addBtn;
    private JButton deleteBtn;
    
    private JButton okBtn;
    private JButton cancelBtn;
    
    private EventPanel eventPanel;
    public CustomClassEditDialog(EventPanel eventPanel) {
        super(LogonApplication.frame,true);
        this.eventPanel = eventPanel;
        this.setTitle("自定义事件页面");
        initUI();
        addListener();
        this.setSize(600, 400);
        dispalyCenter();
    }
 
    private void dispalyCenter(){
           Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            Dimension frameSize = this.getSize();
            if (frameSize.height > screenSize.height) {
                frameSize.height = screenSize.height;
            }
            if (frameSize.width > screenSize.width) {
                frameSize.width = screenSize.width;
            }
            this.setLocation((screenSize.width - frameSize.width) / 2,
                           (screenSize.height - frameSize.height) / 2);
    }
    
    private void addListener() {
        addBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                CustomClassTableModel model = (CustomClassTableModel)customTable.getModel();
                model.addRow();
            }
        });
        
        deleteBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int[] selectedRows = customTable.getSelectedRows();
                CustomClassTableModel model = (CustomClassTableModel)customTable.getModel();
                model.deleteRow(selectedRows);
            }
        });
        okBtn.addActionListener(new ActionListener() {
            
            public void actionPerformed(ActionEvent arg0) {
//                eventPanel.setCustomInfos(getCustomUserInfos());
                dispose();
            }
        });
        cancelBtn.addActionListener(new ActionListener() {
            
            public void actionPerformed(ActionEvent e) {
//                eventPanel.setCustomInfos(new CustomInfo[0]);
                dispose();
            }
        });
    }
 
    private void initUI() {
        setLayout(new BorderLayout());
        add(new JScrollPane(getCustomProperty()), BorderLayout.CENTER);
        
        JPanel BtnPanel = new JPanel();
        add(BtnPanel, BorderLayout.EAST);
        BtnPanel.setLayout(new BoxLayout(BtnPanel, BoxLayout.Y_AXIS));
        
        addBtn = new JButton("添加");
        BtnPanel.add(addBtn);
        
        deleteBtn = new JButton("删除");
        BtnPanel.add(deleteBtn);
        
        okBtn = new JButton("确定");
        cancelBtn = new JButton("取消");
        JPanel botmPanel = new JPanel();
        botmPanel.add(okBtn);
        botmPanel.add(cancelBtn);
        add(botmPanel, BorderLayout.SOUTH);
    }
    
    private JTable getCustomProperty() {
        if(customTable == null) {
            customTable = new JTable(new CustomClassTableModel());
            customTable.setRowHeight(20);
 
            Dimension size = customTable.getTableHeader().getPreferredSize();
            size.height = 22;
            customTable.getTableHeader().setPreferredSize(size);
            
        }
        return customTable;
    }
    
    public CustomInfo[] getCustomUserInfos(){
        List<PropertyInfo> result = new ArrayList<PropertyInfo>();
        CustomClassTableModel model = (CustomClassTableModel)customTable.getModel();
        List<PropertyInfo> data = model.getData();
        if(data != null && data.size() > 0){
            for (PropertyInfo customInfo : data) {
                if(customInfo.property.trim().length() > 0 
//                        && customInfo.value.trim().length() > 0
                        ){
                    result.add(customInfo);
                }
            }
        }
        return result.toArray(new CustomInfo[0]);
    }
    
    public void setData(List<PropertyInfo> data){
        CustomClassTableModel model = (CustomClassTableModel)customTable.getModel();
        model.setData(data);
    }
 
    private String getI18nString(String spCode) {
        return ClientHelper.getI18nStringForWorkflow(this.getClass().getName() + "." + spCode, this.getLocale());
    }
 
}