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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package com.vci.client.workflow.editor.ui;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
 
import com.vci.client.LogonApplication;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.workflow.commom.ClientHelper;
import com.vci.client.workflow.delegate.EventConfClientDelegate;
import com.vci.client.workflow.editor.DblclickCellEditor;
import com.vci.corba.common.VCIError;
import com.vci.corba.workflow.data.PropertyInfo;
 
public class PropertyEditPanel extends JPanel {
    private static final long serialVersionUID = 1300418480939892949L;
    
    private JTable propertyTable;
    private JButton addBtn;
    private JButton deleteBtn;
    private String paramKey;
    private TaskCustomClassEditPanel customClassEditpanel;
    private TaskEventPanel eventPanel;
    
    /**
     * 记录上一次点击的事件名称 
     */
    private String oldValue ="";
    /**
     * 保存事件和参数的关系 
     */
    private Map<String, ArrayList<PropertyInfo>> propertyMap = new HashMap<String, ArrayList<PropertyInfo>>(); 
 
    public PropertyEditPanel(String paramKey,TaskCustomClassEditPanel customClassEditpanel,TaskEventPanel eventPanel) {
        this.paramKey = paramKey;
        this.customClassEditpanel = customClassEditpanel;
        this.eventPanel = eventPanel;
        initUI();
        addListener();
    }
 
    private void addListener() {
        addBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                PropertyTableModel model = (PropertyTableModel)propertyTable.getModel();
                model.addRow();
            }
        });
        
        deleteBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int[] selectedRows = propertyTable.getSelectedRows();
                PropertyTableModel model = (PropertyTableModel)propertyTable.getModel();
                model.deleteRow(selectedRows);
                if(customClassEditpanel ==null){
                    return;
                }
                JTable customTable = customClassEditpanel.getCustomTable();
                int selectedRow = customTable.getSelectedRow();
                String valueAt = (String) customTable.getValueAt(selectedRow, 0);
                PropertyObject[] eventTypes = getEventTypes(eventPanel.getEventType());
                String value = "";
                for(int i=0;i<eventTypes.length;i++){
                    if(valueAt.equals(eventTypes[i].getValue())){
                        /*value = EventProperties.getStringProperty("workflow.event.type." + eventTypes[i].getProperty()+".class");*/
                        //add by caill start 2016.4.8 通过corba连接服务端
                        try {
                            value = new EventConfClientDelegate().getStringProperty("workflow.event.type." + eventTypes[i].getProperty()+".class");
                        } catch (VCIError en) {
                            // TODO Auto-generated catch block
                            en.printStackTrace();
                        }
                        //add by caill end
                        paramKey = eventTypes[i].getProperty();
                    }
                }
                
                ArrayList<PropertyInfo> result = new ArrayList<PropertyInfo>();
                ArrayList<PropertyInfo> data = (ArrayList<PropertyInfo>) model.getData();
                for (PropertyInfo propertyInfo : data) {
                    if(propertyInfo.property.trim().length() > 0 
                            && propertyInfo.value.trim().length() > 0){
                        result.add(propertyInfo);
                    }
                }
                eventPanel.getTaskeventMap().put(value,result);
            }
        });
        
    }
 
    private void initUI() {
        setLayout(new BorderLayout());
        add(new JScrollPane(getPropertyTable()), 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);
    }
    
    private JTable getPropertyTable() {
        if(propertyTable == null) {
            propertyTable = new JTable(new PropertyTableModel());
            propertyTable.setRowHeight(20);
 
            Dimension size = propertyTable.getTableHeader().getPreferredSize();
            size.height = 22;
            propertyTable.getTableHeader().setPreferredSize(size);
            JComboBox c = new JComboBox(getParamTypes(paramKey));//在下拉列表中选择phase 
            propertyTable.getColumnModel().getColumn(0).setCellEditor(new DblclickCellEditor(c,propertyTable));
            
            propertyTable.getColumnModel().getColumn(1).addPropertyChangeListener(new PropertyChangeListener() {
                
                public void propertyChange(PropertyChangeEvent arg0) {
                    if(customClassEditpanel ==null){
                        return;
                    }
                    JTable customTable = customClassEditpanel.getCustomTable();
                    int selectedRow = customTable.getSelectedRow();
                    int rowCount = customTable.getRowCount();
//                    for(int k=0;k<rowCount;k++){
                        String valueAt = (String) customTable.getValueAt(selectedRow, 0);
                        PropertyObject[] eventTypes = getEventTypes(eventPanel.getEventType());
                        String value = "";
                        for(int i=0;i<eventTypes.length;i++){
                            if(valueAt.equals(eventTypes[i].getValue())){
                                /*value = EventProperties.getStringProperty("workflow.event.type." + eventTypes[i].getProperty()+".class");*/
                                //add by caill start 2016.4.8 通过corba连接服务端
                                try {
                                    value = new EventConfClientDelegate().getStringProperty("workflow.event.type." + eventTypes[i].getProperty()+".class");
                                } catch (VCIError e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                                //add by caill end
                                paramKey = eventTypes[i].getProperty();
                            }
                        }
                        oldValue = value;
//                    }
                    
                }
            });
            propertyTable.addKeyListener(new KeyListener() {
                
                public void keyTyped(KeyEvent arg0) {
                    // TODO Auto-generated method stub
                    
                }
                
                public void keyReleased(KeyEvent e) {
                    // TODO Auto-generated method stub
                    if(e.getKeyCode()==KeyEvent.VK_ENTER){
                        setPropertyMap();
                    }
                }
                
                public void keyPressed(KeyEvent arg0) {
                    // TODO Auto-generated method stub
                    
                }
            });
            
            propertyTable.addFocusListener(new FocusListener() {
                
                public void focusLost(FocusEvent arg0) {
                    setPropertyMap();
                }
 
                
                
                public void focusGained(FocusEvent arg0) {
                    
                }
            });
//            JComboBox cType = new JComboBox();//在下拉列表中选择类型 
//            cType.addItem(""); 
//            cType.addItem("String"); 
//            cType.addItem("Map"); 
//            propertyTable.getColumnModel().getColumn(1).setCellEditor(new DblclickCellEditor(cType,propertyTable));
        }
        return propertyTable;
    }
    /**
     * 设置事件与参数之间的关系
     */
    private void setPropertyMap() {
        if(customClassEditpanel ==null){
            return;
        }
        JTable customTable = customClassEditpanel.getCustomTable();
        int selectedRow = customTable.getSelectedRow();
        String valueAt = (String) customTable.getValueAt(selectedRow, 0);
        PropertyObject[] eventTypes = getEventTypes(eventPanel.getEventType());
        String value = "";
        for(int i=0;i<eventTypes.length;i++){
            if(valueAt.equals(eventTypes[i].getValue())){
                /*value = EventProperties.getStringProperty("workflow.event.type." + eventTypes[i].getProperty()+".class");*/
                //add by caill start 2016.4.8 通过corba连接服务端
                try {
                    value = new EventConfClientDelegate().getStringProperty("workflow.event.type." + eventTypes[i].getProperty()+".class");
                } catch (VCIError e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //add by caill end
                paramKey = eventTypes[i].getProperty();
            }
        }
        PropertyInfo[] propertyInfos = customClassEditpanel.getPropertyEditPanel().getPropertyInfos();
        int length = propertyInfos.length;
        ArrayList<PropertyInfo> taskeventPropertylist = new ArrayList<PropertyInfo>();
        if(length>0){
            for(int i =0;i<length;i++){
                taskeventPropertylist.add(propertyInfos[i]);
            }
        }
        if(oldValue != value){
            return;
        }
        eventPanel.getTaskeventMap().put(value,taskeventPropertylist);
    }
    /**
     * 参数列表
     * @param param
     * @return
     */
    private String[] getParamTypes(String param) {
        /*String[] types = EventProperties.getStringProperty("workflow.event.type."+param+".field").split(",");*/
        //add by caill start 2016.4.8 通过corba连接服务端
        String[] types = null;
        try {
             types = new EventConfClientDelegate().getStringProperty("workflow.event.type."+param+".field").split(",");
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //add by caill end
        List<String> taskTypes = new ArrayList<String>();
        taskTypes.add("");
        for (int i = 0; i < types.length; i++) {
//            taskTypes.add(new PropertyObject(types[i],
//                    getI18nForEvent("workflow.event.type." + types[i]+".field")));
            taskTypes.add(types[i]);
        }
        if (param != null && !"".equals(param)) {
            System.out.println("+++++流程事件下选中事件为:" + param);
            for (int i = 0; i < taskTypes.size(); i++) {
                System.out.println("=====流程事件下选中事件" + param + "的第" + i + "个参数名称为" +taskTypes.get(i));
            }
            
        }
        return taskTypes.toArray(new String[0]);
    }
    private String getI18nForEvent(String key) {
        return LocaleDisplay.getI18nString(key, "RMIPWorkflow", getLocale());
    }
    public PropertyInfo[] getPropertyInfos(){
        List<PropertyInfo> result = new ArrayList<PropertyInfo>();
        PropertyTableModel model = (PropertyTableModel)propertyTable.getModel();
        List<PropertyInfo> data = model.getData();
        if(data != null && data.size() > 0){
            for (PropertyInfo propertyInfo : data) {
                if(propertyInfo.property.trim().length() > 0 
                        && propertyInfo.value.trim().length() > 0){
                    result.add(propertyInfo);
                }
            }
        }
        return result.toArray(new PropertyInfo[0]);
    }
    
    public void setData(List<PropertyInfo> data){
        PropertyTableModel model = (PropertyTableModel)propertyTable.getModel();
        model.setData(data);
    }
 
    private String getI18nString(String spCode) {
        return ClientHelper.getI18nStringForWorkflow(this.getClass().getName() + "." + spCode, this.getLocale());
    }
    /**
     * 直接取得table中cell的值
     * @param table
     */
    public void cursorLeave(JTable table) {
        try {
            if (table == null) {
                return;
            }
            if (table.isEditing()) {
                table.getCellEditor(table.getEditingRow(), table.getEditingColumn()).stopCellEditing();
           }
        } catch (Exception e) {
            e.printStackTrace();
        }
     }
    
    private PropertyObject[] getEventTypes(String eventType) {
        /*String[] types = EventProperties.getStringProperty("workflow.event.type."+eventType).split(",");*/
        //add by caill start 2016.4.8 通过corba连接服务端
        String[] types = null;
        try {
            types = new EventConfClientDelegate().getStringProperty("workflow.event.type."+eventType).split(",");
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //add by caill end
        List<PropertyObject> taskTypes = new ArrayList<PropertyObject>();
        taskTypes.add(new PropertyObject("", ""));
        for (int i = 0; i < types.length; i++) {
            /*taskTypes.add(new PropertyObject(types[i],
                    EventProperties.getStringProperty("workflow.event.type." + types[i])));*/
            //add by caill start 2016.4.8 通过corba连接服务端
            try {
                taskTypes.add(new PropertyObject(types[i],
                        new EventConfClientDelegate().getStringProperty("workflow.event.type." + types[i])));
            } catch (VCIError e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            //add by caill end
        }
        return taskTypes.toArray(new PropertyObject[0]);
    }
 
}