田源
2024-03-07 4b4083fd73dc27ece42f4835483565eef0e4f608
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
package com.vci.client.workflow.editor.ui;
 
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.ArrayList;
import java.util.List;
 
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
 
import org.dom4j.Attribute;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
 
import com.mxgraph.view.mxGraph;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.workflow.delegate.EventConfClientDelegate;
import com.vci.client.workflow.editor.FlowConstants;
import com.vci.corba.common.VCIError;
import com.vci.corba.workflow.data.ProcessTaskInfo;
import com.vci.corba.workflow.data.PropertyInfo;
 
 
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class FlowInfoPanel extends JPanel implements IProcessProperty {
    private static final long serialVersionUID = 2861859622276207719L;
    
    private mxGraph graph;
    
    private JTextField nameField;
    private JTextField keyField;
//    private JTextField versionField;
 
    private EventPanel transitionInitEventPropertyPanel;
    private EventPanel transitionEndEventPropertyPanel;
    
    private ProcessPropertyEditPanel propertyEditPanel;
    
    public FlowInfoPanel(mxGraph graph) {
        this.graph = graph;
        
        GridBagLayout gridBagLayout = new GridBagLayout();
        gridBagLayout.columnWidths = new int[] {48, 0, 48};
        gridBagLayout.rowHeights = new int[]{0, 0, 0, 0};
        gridBagLayout.columnWeights = new double[] {0.0, 1.0, 0.0};
        gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
        this.setLayout(gridBagLayout);
        
        JLabel lblName = new JLabel("name:");
        GridBagConstraints gbc_lblName = new GridBagConstraints();
        gbc_lblName.insets = new Insets(0, 0, 5, 5);
        gbc_lblName.anchor = GridBagConstraints.EAST;
        gbc_lblName.gridx = 0;
        gbc_lblName.gridy = 0;
        add(lblName, gbc_lblName);
        
        nameField = new JTextField();
        GridBagConstraints gbc_textField = new GridBagConstraints();
        gbc_textField.insets = new Insets(0, 0, 5, 0);
        gbc_textField.fill = GridBagConstraints.HORIZONTAL;
        gbc_textField.gridx = 1;
        gbc_textField.gridy = 0;
        add(nameField, gbc_textField);
        
        JLabel lblKey = new JLabel("key:");
        GridBagConstraints gbc_lblKey = new GridBagConstraints();
        gbc_lblKey.anchor = GridBagConstraints.EAST;
        gbc_lblKey.insets = new Insets(0, 0, 5, 5);
        gbc_lblKey.gridx = 2;
        gbc_lblKey.gridy = 0;
//        this.add(lblKey, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        
        keyField = new JTextField();
        GridBagConstraints gbc_textField_1 = new GridBagConstraints();
        gbc_textField_1.insets = new Insets(0, 0, 5, 0);
        gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
        gbc_textField_1.gridx = 3;
        gbc_textField_1.gridy = 0;
//        add(keyField, gbc_textField_1);
        
        GridBagConstraints gbc_eventPanel = new GridBagConstraints();
        gbc_eventPanel.fill = GridBagConstraints.HORIZONTAL;
        gbc_eventPanel.gridx = 0;
        gbc_eventPanel.gridy = 1;
        gbc_eventPanel.weightx = 1;
        gbc_eventPanel.weighty = 3;
        gbc_eventPanel.gridwidth = 2;
        gbc_eventPanel.gridheight =3;
        this.add(getEventPanel(), new GridBagConstraints(0, 1, 2, 3, 1.0, 3.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        
        GridBagConstraints gbc_propertyPanel = new GridBagConstraints();
        gbc_propertyPanel.fill = GridBagConstraints.BOTH;
        gbc_propertyPanel.gridx = 2;
        gbc_propertyPanel.gridy = 1;
        gbc_propertyPanel.weightx = 1;
        gbc_propertyPanel.weighty = 3;
        gbc_propertyPanel.gridwidth = 2;
        gbc_propertyPanel.gridheight =3;
        this.add(getPropertyEditPanel(), new GridBagConstraints(2, 2, 2, 3, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));        
/*        
        JLabel lblVersion = new JLabel("version:");
        GridBagConstraints gbc_lblVersion = new GridBagConstraints();
        gbc_lblVersion.anchor = GridBagConstraints.EAST;
        gbc_lblVersion.insets = new Insets(0, 0, 0, 5);
        gbc_lblVersion.gridx = 0;
        gbc_lblVersion.gridy = 2;
        add(lblVersion, gbc_lblVersion);
        
        versionField = new JTextField();
        GridBagConstraints gbc_textField_2 = new GridBagConstraints();
        gbc_textField_2.fill = GridBagConstraints.HORIZONTAL;
        gbc_textField_2.gridx = 1;
        gbc_textField_2.gridy = 2;
        add(versionField, gbc_textField_2);
        versionField.setColumns(10);*/
 
        DocumentListener documentListener = new DocumentListener() {
            public void removeUpdate(DocumentEvent e) {
                updateFlow();
            }
            public void insertUpdate(DocumentEvent e) {
                updateFlow();
            }
            public void changedUpdate(DocumentEvent e) {
                updateFlow();
            }
        };
        nameField.getDocument().addDocumentListener(documentListener);
    }
 
    public void createAttribute(Element owner) {
        Attribute attributeName = DocumentHelper.createAttribute(owner, FlowConstants.XMLNAME, nameField.getText().trim());
        owner.add(attributeName);
        
//        String key = keyField.getText().trim();
        String key = nameField.getText().trim();
        if(key.trim().length() > 0){
            Attribute attributeKey = DocumentHelper.createAttribute(owner, FlowConstants.XMLKEY, key);
            owner.add(attributeKey);
        }
        
        Element onElement = owner.addElement(FlowConstants.GLOBAL);
        
        PropertyInfo[] propertyInfos = propertyEditPanel.getPropertyInfos();
        if(propertyInfos.length > 0){
            for (int k = 0; k < propertyInfos.length; k++) {
                Element fieldElement = onElement.addElement(FlowConstants.EVENT_FIELD);
                Attribute nameAttribute = DocumentHelper.createAttribute(owner, FlowConstants.XMLNAME, propertyInfos[k].property);
                fieldElement.add(nameAttribute);
 
                Element stringElement = fieldElement.addElement(FlowConstants.EVENT_STRING);
                Attribute valueAttribute = DocumentHelper.createAttribute(owner, FlowConstants.EVENT_VALUE, propertyInfos[k].value);
                stringElement.add(valueAttribute);
            }
        }
        //添加属性值到global中
        getTrainsitionXml(owner, transitionInitEventPropertyPanel, FlowConstants.XMLSTART, propertyInfos);
        getTrainsitionXml(owner, transitionEndEventPropertyPanel, FlowConstants.XMLEND, propertyInfos);    
        
        
/*        
        String version = versionField.getText().trim();
        if(version.trim().length() > 0){
            Attribute attributeVersion = DocumentHelper.createAttribute(owner, FlowConstants.XMLVERSION, version);
            owner.add(attributeVersion);
        }*/
    }
 
    public void setValue(String text) {
        nameField.setText(text);
    }
 
    public void setKey(String text) {
//        keyField.setText(text);
        nameField.setText(text);
    }
 
    public String getNodeType() {
        return "root";
    }
 
    protected void updateFlow() {
        graph.refresh();
    }
    
    @Override
    public String toString() {
        return nameField.getText().trim()+","+keyField.getText();
    }
 
    private JComponent getEventPanel() {
        JTabbedPane eventPanel = new JTabbedPane();
        transitionInitEventPropertyPanel = new EventPanel("事件", getEventTypes(FlowConstants.XMLSTART),FlowConstants.XMLSTART);
        transitionEndEventPropertyPanel = new EventPanel("事件", getEventTypes(FlowConstants.XMLEND),FlowConstants.XMLEND);
        eventPanel.add("初始事件", transitionInitEventPropertyPanel);
        eventPanel.add("完成事件", transitionEndEventPropertyPanel);
        return eventPanel;
    }
    private JComponent getPropertyEditPanel() {
        propertyEditPanel = new ProcessPropertyEditPanel();
        return propertyEditPanel;
    }
    
    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]);
    }
    
    private String getI18nForEvent(String key){
        return LocaleDisplay.getI18nString(key, "RMIPWorkflow", getLocale());
    }
    
    private void getTrainsitionXml(Element owner, EventPanel eventPanel, String eventType, PropertyInfo[] propertyInfos) {
        PropertyInfo[] customClassInfo = eventPanel.getCustomInfos();
        if (customClassInfo.length > 0) {
            Element onElement = owner.addElement(FlowConstants.EVENT_ON);
            Attribute startAttribute = DocumentHelper.createAttribute(owner,
                    FlowConstants.EVENT, eventType);
            onElement.add(startAttribute);
            if(customClassInfo.length>0){
                String result = "";
                for (int i = 0; i < customClassInfo.length; i++) {
                    for(int j =0;j<getEventTypes(eventType).length;j++){
                        String className = customClassInfo[i].property;
                        String classValue = "";
                        if(getEventTypes(eventType)[j].getValue().equals(className)){
                            classValue = getEventTypes(eventType)[j].getProperty();
                            /*String initEventClass = EventProperties.getStringProperty("workflow.event.type." + classValue
                                    + ".class");*/
                            //add by caill start 2016.4.8 通过corba连接服务端
                            String initEventClass = null;
                            try {
                                 initEventClass = new EventConfClientDelegate().getStringProperty("workflow.event.type." + classValue
                                        + ".class");
                            } catch (VCIError e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            //add by caill end
                            Element listenerElement = onElement.addElement(FlowConstants.EVENT_LISTENER);
                            Attribute classAttribute = DocumentHelper.createAttribute(owner,
                                    FlowConstants.EVENT_CLASS,initEventClass);
                            listenerElement.add(classAttribute);
                            if(propertyInfos.length > 0){
                                for (int k = 0; k < propertyInfos.length; k++) {
                                    Element fieldElement = listenerElement.addElement(FlowConstants.EVENT_FIELD);
                                    Attribute nameAttribute = DocumentHelper.createAttribute(owner, FlowConstants.XMLNAME, propertyInfos[k].property);
                                    fieldElement.add(nameAttribute);
 
                                    Element stringElement = fieldElement.addElement(FlowConstants.EVENT_STRING);
                                    Attribute valueAttribute = DocumentHelper.createAttribute(owner, FlowConstants.EVENT_VALUE, propertyInfos[k].value);
                                    stringElement.add(valueAttribute);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    public void setEventInfo(ProcessTaskInfo processTaskInfo, String eventType) {
        updateTransitionType(processTaskInfo);
        if(eventType.equals("start")) {
            transitionInitEventPropertyPanel.setProcessTaskInfo(processTaskInfo);
        } else if(eventType.equals("end")) {
            transitionEndEventPropertyPanel.setProcessTaskInfo(processTaskInfo);
        }
    }
    public void setCustomClassInfo( String eventType,PropertyInfo[] customInfos){
        int length = getEventTypes(eventType).length;
        PropertyInfo[] res = new PropertyInfo[customInfos.length];
        for(int j = 0;j<customInfos.length;j++){
            for(int i=0;i<length;i++){
                PropertyObject propertyObject = getEventTypes(eventType)[i];
                PropertyInfo propertyInfo = new PropertyInfo();
                /*String eventClass = EventProperties.getStringProperty("workflow.event.type."
                        + propertyObject.getProperty() + ".class");*/
                //add by caill start 2016.4.8 通过corba连接服务端
                String eventClass = null;
                try {
                     eventClass = new EventConfClientDelegate().getStringProperty("workflow.event.type."
                            + propertyObject.getProperty() + ".class");
                } catch (VCIError e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //add by caill end
                if(eventClass.equals(customInfos[j].property)){
                    propertyInfo.property = propertyObject.getValue();
                    res[j] = propertyInfo;
                }
            }
        }
        if (eventType.equals("start")) {
            transitionInitEventPropertyPanel.setCustomInfos(res);
        } else if (eventType.equals("end")) {
            transitionEndEventPropertyPanel.setCustomInfos(res);
        }
    }
    
    public void setPropertyInfo(PropertyInfo[] customInfos){
        List<PropertyInfo> data = new ArrayList<PropertyInfo>();
        for(int i =0;i <customInfos.length;i++){
            data.add(customInfos[i]);
        }
        propertyEditPanel.setData(data);
    }
    private void updateTransitionType(ProcessTaskInfo processTaskInfo) {
        /*String[] types = EventProperties.getStringProperty("workflow.event.type").split(",");*/
        //add by caill start 2016.4.8 通过corba连接服务端
        String[] types = null;
        try {
             types = new EventConfClientDelegate().getStringProperty("workflow.event.type").split(",");
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //add by caill end
        for (int i = 0; i < types.length; i++) {
            /*String eventClass = EventProperties.getStringProperty("workflow.event.type." + types[i] + ".class");*/
            //add by caill start 2016.4.8 通过corba连接服务端
            String eventClass = null;
            try {
                 eventClass = new EventConfClientDelegate().getStringProperty("workflow.event.type." + types[i] + ".class");
            } catch (VCIError e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            //add by caill end
            if(processTaskInfo.taskType.equals(eventClass)){
                processTaskInfo.taskType = types[i];
                return;
            }
        }
        
    }
}