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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
package com.vci.client.workflow.editor.ui;
 
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;
 
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
 
import org.apache.commons.lang3.StringUtils;
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.uif.actions.client.UIFUtils;
import com.vci.client.workflow.delegate.EventConfClientDelegate;
import com.vci.client.workflow.editor.FlowConstants;
import com.vci.client.workflow.editor.FlowNode;
import com.vci.client.workflow.editor.user.CustomObject;
import com.vci.client.workflow.editor.user.CustomUserPanel;
import com.vci.client.workflow.editor.user.DefaultUserComponent;
import com.vci.client.workflow.editor.user.IUserComponent;
import com.vci.common.resource.CommonProperties;
import com.vci.corba.common.VCIError;
import com.vci.corba.workflow.data.CustomInfo;
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 TaskNewPanel extends JTabbedPane implements IProcessProperty, Serializable {
    
    private static final long serialVersionUID = 4691917636318432525L;
    
    private IUserComponent userComponent;
    //委托人
    private IUserComponent constituentComponent;
    private IUserComponent CCComponent;
 
    private mxGraph graph;
    private FlowNode node;
 
    private JTextField nameField;
    private JTextArea taskDesArea;
 
    private TaskEventPanel taskTypePropertyPanel;
    private TaskEventPanel taskInitEventPropertyPanel;
    private TaskEventPanel taskEndEventPropertyPanel;
    private EventPanel taskRevokeEventPropertyPanel;
    
    private PropertyEditPanel propertyEditPanel;
    
    private TaskDescPanel taskDescPanel;
    private TaskTreatmentPanel taskTreatmentPanel;
    private MailPanel mailPanel;
    private JPanel propertypanel;
    /**
     * 自定义用户面板
     */
    private CustomUserPanel customUserPanel;
    private Map<String,ArrayList<PropertyInfo>> taskeventMap ;
    private Map<String ,Map<String,ArrayList<PropertyInfo>>> resultMap ;
    public void setTaskTreatmentPanel(long flag) {
        taskTreatmentPanel.setFlag(flag);
        if(flag==1){
            taskTreatmentPanel.getRadio2().setSelected(true);
//            taskTreatmentPanel.setAttribute("com.vci.rmip.workflow.server.event.AssignTask");
            taskTreatmentPanel.setAttribute(taskTreatmentPanel.string);
            taskTreatmentPanel.setFlag(1);
        }else{
            taskTreatmentPanel.getRadio1().setSelected(true);
            taskTreatmentPanel.setAttribute("");
            taskTreatmentPanel.setFlag(0);
        }
    }
    
    /**
     * 设置会签比例
     * @param votePercent 会签比例
     */
    public void setVotePercent(String votePercent){
        taskTreatmentPanel.getRadio3().setSelected(true);
        taskTreatmentPanel.getText().setText(votePercent);
    }
 
    /**
     * @param taskDesc
     */
    public void setTaskDescPanel(String taskDesc,String urlTextArea) {
        taskDescPanel.setTaskDesArea(taskDesc);
        taskDescPanel.setUrlTextArea(urlTextArea);
    }
 
    public TaskNewPanel(mxGraph graph, FlowNode node) throws VCIError {
        super(JTabbedPane.LEFT);
        this.graph = graph;
        this.node = node;
        initUI();
    }
    
    //初始化UI
    private void initUI() throws VCIError {
        addTab("基本属性", getGeneralPanel());
        addTab("事件", getEventPanel());
        addTab("责任人", getOwnerPanel());
        addTab("委托人", getConstituentPanel());
        addTab("业务功能", getTaskDesPanel());
        addTab("控制策略", getTaskTreatmentPanel());
 
        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);
    }
 
    private JComponent getGeneralPanel() {
        JPanel generalPanel = new JPanel(new GridBagLayout());
        GridBagConstraints g = new GridBagConstraints();
        g.insets = new Insets(2, 2, 2, 2);
        g.anchor = GridBagConstraints.EAST;
        g.gridx = 0;
        g.gridy = 0;
        generalPanel.add(new JLabel("名称:"), g);
        g.fill = GridBagConstraints.HORIZONTAL;
        g.weightx = 1;
        g.gridx = 1;
        nameField = new JTextField();
        nameField.setText(node.getName());
        generalPanel.add(nameField, g);
        
        JPanel resultPanel = new JPanel(new BorderLayout());
        resultPanel.add(generalPanel, BorderLayout.NORTH);
        taskTypePropertyPanel = new TaskEventPanel("类型", getTaskTypes(),"");
//        resultPanel.add(taskTypePropertyPanel, BorderLayout.CENTER);
        return resultPanel;
    }
    
    private PropertyObject[] getTaskTypes() {
        /*String[] types = EventProperties.getStringProperty("workflow.task.type").split(",");*/
        //add by caill start 2016.4.8 通过corba连接服务端
        String[] types =  null;
        try {
             types = new EventConfClientDelegate().getStringProperty("workflow.task.type").split(",");
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //add by caill end
        List<PropertyObject> taskTypes = new ArrayList<PropertyObject>();
        for (int i = 0; i < types.length; i++) {
            /*taskTypes.add(new PropertyObject(types[i], EventProperties.getStringProperty("workflow.task.type." + types[i])));*/
            //add by caill start 2016.4.8 通过corba连接服务端
            try {
                taskTypes.add(new PropertyObject(types[i], new EventConfClientDelegate().getStringProperty("workflow.task.type." + types[i])));
            } catch (VCIError e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            //add by caill end
        }
        return taskTypes.toArray(new PropertyObject[0]);
    }
    
    private JComponent getEventPanel() {
        JTabbedPane eventPanel = new JTabbedPane();
        taskInitEventPropertyPanel = new TaskEventPanel("事件", getEventTypes("start"),"start");
        taskEndEventPropertyPanel = new TaskEventPanel("事件", getEventTypes("end"),"end");
        taskRevokeEventPropertyPanel = new EventPanel("事件", getEventTypes("revoke"),"revoke");
        eventPanel.add("初始事件", taskInitEventPropertyPanel);
        eventPanel.add("完成事件", taskEndEventPropertyPanel);
        
        eventPanel.add("收回事件", taskRevokeEventPropertyPanel);
        
        return eventPanel;
    }
 
    //初始化用户
    private JPanel getOwnerPanel() {
        JPanel ownerPanel = new JPanel(new BorderLayout());
        customUserPanel = new CustomUserPanel();
        userComponent = new DefaultUserComponent(customUserPanel);
//        CCComponent = new DefaultUserComponent(customUserPanel);
        
        Properties properties = new Properties();
        try {
            ClassLoader cl = TaskNewPanel.class.getClassLoader();
            InputStream in = cl.getResourceAsStream("flow-custom.properties");
            properties.load(in);
            Object userProperty = properties.get("com.vci.rmip.workflow.usercomponent");
            Class userComponentClass = Class.forName(userProperty.toString());
            userComponent = (IUserComponent)userComponentClass.newInstance();
            
//            Object CCProperty = properties.get("com.vci.rmip.workflow.CCcomponent");
//            Class CCComponentClass = Class.forName(CCProperty.toString());
//            CCComponent = (IUserComponent)CCComponentClass.newInstance();
        } catch (Exception ex) {
            userComponent = new DefaultUserComponent(customUserPanel);
        }
        ownerPanel.add(userComponent.getUserComponent(customUserPanel.getCustomEditPanel()), BorderLayout.CENTER);
//        ownerPanel.add(CCComponent.getUserComponent(customUserPanel.getCustomEditPanel()), BorderLayout.EAST);
        return ownerPanel;
    }
    //委托人panel
    private JPanel getConstituentPanel() {
        JPanel ownerPanel = new JPanel(new BorderLayout());
        customUserPanel = new CustomUserPanel();
        constituentComponent = new DefaultUserComponent(customUserPanel);
//        CCComponent = new DefaultUserComponent(customUserPanel);
        
        Properties properties = new Properties();
        try {
            ClassLoader cl = TaskNewPanel.class.getClassLoader();
            InputStream in = cl.getResourceAsStream("flow-custom.properties");
            properties.load(in);
            Object userProperty = properties.get("com.vci.rmip.workflow.constituentComponent");
            Class userComponentClass = Class.forName(userProperty.toString());
            constituentComponent = (IUserComponent)userComponentClass.newInstance();
            
//            Object CCProperty = properties.get("com.vci.rmip.workflow.CCcomponent");
//            Class CCComponentClass = Class.forName(CCProperty.toString());
//            CCComponent = (IUserComponent)CCComponentClass.newInstance();
        } catch (Exception ex) {
            constituentComponent = new DefaultUserComponent(customUserPanel);
        }
        ownerPanel.add(constituentComponent.getUserComponent(customUserPanel.getCustomEditPanel()), BorderLayout.CENTER);
//        ownerPanel.add(CCComponent.getUserComponent(customUserPanel.getCustomEditPanel()), BorderLayout.EAST);
        return ownerPanel;
    }
    private JPanel getTaskDesPanel() throws VCIError {
        taskDescPanel = new TaskDescPanel();
        return taskDescPanel;
    }
    private JPanel getTaskTreatmentPanel() {
        taskTreatmentPanel = new TaskTreatmentPanel();
        return taskTreatmentPanel;
    }
 
    protected void updateFlow() {
        graph.refresh();
    }
    
    @Override
    public String toString() {
        return nameField.getText().trim();
    }
 
    public String getNodeType() {
        return node.getType();
    }
 
    public void setValue(String text) {
        nameField.setText(text);
    }
 
    public void createAttribute(Element owner) {
        Attribute attributeName = DocumentHelper.createAttribute(owner, FlowConstants.XMLNAME, nameField.getText().trim());
        owner.add(attributeName);
        
        //事件
        getTreatmentEventXml(owner);
        getCustomUserClassXmlForRMCode(owner, customUserPanel,
                FlowConstants.XMLSTART);
        setAssginTaskUser(owner);
        setConstituent(owner);
        getTaskEventXml(owner, taskInitEventPropertyPanel, FlowConstants.XMLSTART);
        getTaskEventXml(owner, taskEndEventPropertyPanel, FlowConstants.XMLEND);
        String urlText = taskDescPanel.getUrlTextArea().getText().trim();
        if(urlText!=null&&!"".equals(urlText)){
            Attribute attributeKey = DocumentHelper.createAttribute(owner, FlowConstants.URL_PATH, urlText);
            owner.add(attributeKey);
        }
        
    }
 
    public Map<String, ArrayList<PropertyInfo>> getTaskeventMap() {
        return taskeventMap;
    }
 
    public void setTaskeventMap(Map<String, ArrayList<PropertyInfo>> taskeventMap) {
        this.taskeventMap = taskeventMap;
    }
 
    public Map<String, Map<String, ArrayList<PropertyInfo>>> getResultMap() {
        return resultMap;
    }
 
    public void setResultMap(String eventType,
            Map<String, Map<String, ArrayList<PropertyInfo>>> resultMap) {
        this.resultMap = resultMap;
        if(FlowConstants.XMLSTART.equals(eventType)){
            taskInitEventPropertyPanel.setTaskeventMap(resultMap.get(FlowConstants.XMLSTART));
        }
        if(FlowConstants.XMLEND.equals(eventType)){
            taskEndEventPropertyPanel.setTaskeventMap(resultMap.get(FlowConstants.XMLEND));
        }
    }
 
    private void getTaskEventXml(Element owner, TaskEventPanel eventPanel, String eventType) {
//        String event = eventPanel.getEvent();
        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);
            
            resultMap = eventPanel.getResultMap();
            if(customClassInfo!=null){
                if(customClassInfo.length>0){
                    for (int i = 0; i < customClassInfo.length; i++) {
                        for(int j =0;j<getEventTypes(eventType).length;j++){
                            String className = customClassInfo[i].property;
                            Map<String, ArrayList<PropertyInfo>> eventAndParamMap = resultMap.get(eventType);
                            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
                                ArrayList<PropertyInfo> paramList = new ArrayList<PropertyInfo>();
                                if(eventAndParamMap!=null){
                                    paramList = eventAndParamMap.get(initEventClass);
                                }
                                Element listenerElement = onElement.addElement(FlowConstants.EVENT_LISTENER);
                                Attribute classAttribute = DocumentHelper.createAttribute(owner,
                                        FlowConstants.EVENT_CLASS,initEventClass);
                                listenerElement.add(classAttribute);
                                if(paramList!=null){
                                    for (int k = 0; k < paramList.size(); k++) {
                                        Element fieldElement = listenerElement.addElement(FlowConstants.EVENT_FIELD);
                                        Attribute nameAttribute = DocumentHelper.createAttribute(owner, FlowConstants.XMLNAME, paramList.get(k).property);
                                        fieldElement.add(nameAttribute);
                    
                                        Element stringElement = fieldElement.addElement(FlowConstants.EVENT_STRING);
                                        Attribute valueAttribute = DocumentHelper.createAttribute(owner, FlowConstants.EVENT_VALUE,  paramList.get(k).value);
                                        stringElement.add(valueAttribute);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    /**
     * 编码专用
     * @param owner
     * @param customUserPanel
     * @param eventType
     */
    private void getCustomUserClassXmlForRMCode(Element owner, CustomUserPanel customUserPanel,
            String eventType) {
//        String event = eventPanel.getEvent();
        CustomInfo[] customClassInfo = customUserPanel.getCustomUserInfos();
//        if (event.trim().length() > 0) {
        if (customClassInfo.length > 0) {
            Element onElement = owner.addElement(FlowConstants.EVENT_ON);
            Attribute startAttribute = DocumentHelper.createAttribute(owner,
                    FlowConstants.EVENT, eventType);
            onElement.add(startAttribute);
            
            
            if(customClassInfo!=null){
                if(customClassInfo.length>0){
                    String result = "";
                    for (int i = 0; i < customClassInfo.length; i++) {
                        for(int j =0;j<getCustomClassInfo("customUser").length;j++){
                            String className = customClassInfo[i].className;
//                            String classValue = customClassInfo[i].value;
                            if(getCustomClassInfo("customUser")[j].getValue().equals(className)){
                                className = getCustomClassInfo("customUser")[j].getClassName();
                                /*String initEventClass = EventProperties.getStringProperty("workflow.event.type.customUser." + className
                                        + ".class");*/
                                //add by caill start 2016.4.8 通过corba连接服务端
                                String initEventClass = null;
                                try {
                                     initEventClass = new EventConfClientDelegate().getStringProperty("workflow.event.type.customUser." + className
                                            + ".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);
                                Attribute flagbute = DocumentHelper.createAttribute(owner,
                                        FlowConstants.CUSTOMUSERCLASS_flag,FlowConstants.CUSTOMUSERCLASS);
                                listenerElement.add(flagbute);
                                
                                Element fieldElement = listenerElement
                                .addElement(FlowConstants.EVENT_FIELD);
                                Attribute nameAttribute = DocumentHelper.createAttribute(
                                        owner, FlowConstants.XMLNAME,
                                        "param");
                                fieldElement.add(nameAttribute);
            
                                Element stringElement = fieldElement
                                        .addElement(FlowConstants.EVENT_STRING);
                                Attribute valueAttribute = DocumentHelper.createAttribute(
                                        owner, FlowConstants.EVENT_VALUE,
                                        customClassInfo[i].value);
                                stringElement.add(valueAttribute);
                            }
                        }
                    }
                }
            }
 
        }
    }
    
    /**
     * 获取自定义用户类列表
     * @param eventType
     * @return
     */
    public CustomObject[] getCustomClassInfo(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<CustomObject> taskTypes = new ArrayList<CustomObject>();
        taskTypes.add(new CustomObject("", ""));
        for (int i = 0; i < types.length; i++) {
            if("".equals(types[i].trim())) continue;
            /*taskTypes.add(new CustomObject(types[i],
                    EventProperties.getStringProperty("workflow.event.type.customUser." + types[i])));*/
            //add by caill start 2016.4.8 通过corba连接服务端
            try {
                taskTypes.add(new CustomObject(types[i],
                        new EventConfClientDelegate().getStringProperty("workflow.event.type.customUser." + types[i])));
            } catch (VCIError e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            //add by caill end
        }
        return taskTypes.toArray(new CustomObject[0]);
    }
    
    private void getCustomUserClassXml(Element owner, CustomUserPanel customUserPanel,
            String eventType) {
//        String event = eventPanel.getEvent();
        CustomInfo[] customClassInfo = customUserPanel.getCustomUserInfos();
//        String initEventClass = getI18nForEvent("workflow.event.type." + event
//                + ".class");
//        if (event.trim().length() > 0) {
        if(customClassInfo!=null){
            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++) {
                            String className = customClassInfo[i].className;
                                Element listenerElement = onElement.addElement(FlowConstants.EVENT_LISTENER);
                                Attribute classAttribute = DocumentHelper.createAttribute(owner,
                                        FlowConstants.EVENT_CLASS,className);
                                listenerElement.add(classAttribute);
                                Attribute flagbute = DocumentHelper.createAttribute(owner,
                                        FlowConstants.CUSTOMUSERCLASS_flag,FlowConstants.CUSTOMUSERCLASS);
                                listenerElement.add(flagbute);
                                
                                Element fieldElement = listenerElement
                                .addElement(FlowConstants.EVENT_FIELD);
                                Attribute nameAttribute = DocumentHelper.createAttribute(
                                        owner, FlowConstants.XMLNAME,
                                        "param");
                                fieldElement.add(nameAttribute);
            
                                Element stringElement = fieldElement
                                        .addElement(FlowConstants.EVENT_STRING);
                                Attribute valueAttribute = DocumentHelper.createAttribute(
                                        owner, FlowConstants.EVENT_VALUE,
                                        customClassInfo[i].value);
                                stringElement.add(valueAttribute);
                    }
                }
 
        }
    }
    /**
     * 控制策略
     * @param owner
     */
    private void getTreatmentEventXml(Element owner){
        String attribute = taskTreatmentPanel.getAttribute();
        if(attribute!=null&&!"".equals(attribute)){
            Element handlerElement = owner.addElement(FlowConstants.ASSIFNMENT_HANDLER);
            Attribute classAttribute = DocumentHelper.createAttribute(handlerElement, FlowConstants.EVENT_CLASS, attribute);
            handlerElement.add(classAttribute);
        }
        if(taskTreatmentPanel.getRadio3().isSelected()){
            //会签的
            String votePercent = taskTreatmentPanel.getText().getText();
            if(StringUtils.isBlank(votePercent)){
                UIFUtils.showErrorMessage(null, new Exception("您选择的控制策略为会签,请输入会签通过的比例"));
            }
            Attribute classAttribute = DocumentHelper.createAttribute(owner, FlowConstants.SIGN_VOTE_PRCENT, votePercent);
            owner.add(classAttribute);
        }
    }
    /**
     * 自定义获取用户
     * @param owner
     */
    private void setAssginTaskUser(Element owner){
        String cuts = userComponent.getSelectedCust();
        
        List<String> userDepartment = userComponent.getSelectedUserDepartment();
        List<String> userRole = userComponent.getSelectedUserRole();
        List<String> userOrg = userComponent.getSelectedUserOrg();
        List<String> userLine = userComponent.getSelectedUserLine();
        List<String> deptAndUser = userComponent.getSelectedDeptAddUser();
        
        StringBuilder userDepartmentsb = new StringBuilder();
        StringBuilder userRolesb = new StringBuilder();
        StringBuilder userOrgsb = new StringBuilder();
        StringBuilder userLinesb = new StringBuilder();
        StringBuilder deptAndUsersb = new StringBuilder();
        
        String attribute = "";
        String userDialogControl = CommonProperties.getStringProperty("workflow.UserDialog");
        if(userDialogControl!=null&&!"".equals(userDialogControl)){
            if(userDepartment!=null&&userDepartment.size()==0){
                Attribute attributeKey = DocumentHelper.createAttribute(owner,
                        FlowConstants.XMLUSER, FlowConstants.PROCESS_APPLICANT);
                owner.add(attributeKey);
            }else{
                attribute = "com.vci.rmip.workflow.server.event.AssginTaskForExpression";
                Element handlerElement = owner.addElement(FlowConstants.ASSIFNMENT_HANDLER);
                Attribute classAttribute = DocumentHelper.createAttribute(handlerElement, FlowConstants.EVENT_CLASS, attribute);
                handlerElement.add(classAttribute);
                List<String> selectedUsers = userComponent.getSelectedUsers();
                String[] array = selectedUsers.toArray(new String[0]);
                String userSt = Arrays.toString(array);
                Element fieldElement = handlerElement
                .addElement(FlowConstants.EVENT_FIELD);
                Attribute nameAttribute = DocumentHelper.createAttribute(
                        owner, FlowConstants.XMLNAME,
                "assignee");
                fieldElement.add(nameAttribute);
                
                Element stringElement = fieldElement
                .addElement(FlowConstants.EVENT_STRING);
                Attribute valueAttribute = DocumentHelper.createAttribute(
                        owner, FlowConstants.EVENT_VALUE,
                        userSt.substring(1,userSt.length()-1));
                stringElement.add(valueAttribute);
            }
        }else{
            if (userDepartment != null) {
                for (int i = 0; i < userDepartment.size(); i++) {
                    userDepartmentsb.append(userDepartment.get(i));
                    if (i != userDepartment.size() - 1) {
                        userDepartmentsb.append(",");
                    }
                }
                userDepartmentsb.append(";");
            }
            if (userRole != null) {
                for (int i = 0; i < userRole.size(); i++) {
                    userRolesb.append(userRole.get(i));
                    if (i != userRole.size() - 1) {
                        userRolesb.append(",");
                    }
                }
                userRolesb.append(";");
            }
            if (userOrg != null) {
                for (int i = 0; i < userOrg.size(); i++) {
                    userOrgsb.append(userOrg.get(i));
                    if (i != userOrg.size() - 1) {
                        userOrgsb.append(",");
                    }
                }
                userOrgsb.append(";");
            }
            if (userLine != null) {
                for (int i = 0; i < userLine.size(); i++) {
                    userLinesb.append(userLine.get(i));
                    if (i != userLine.size() - 1) {
                        userLinesb.append(",");
                    }
                }
                userLinesb.append(";");
            }
            if (deptAndUser != null) {
                for (int i = 0; i < deptAndUser.size(); i++) {
                    deptAndUsersb.append(deptAndUser.get(i));
                    if (i != deptAndUser.size() - 1) {
                        deptAndUsersb.append(",");
                    }
                }
                deptAndUsersb.append(";");
            }
            // 上面每个数据都已添加;
            String result = userDepartmentsb.toString() + userRolesb.toString()
                    + userOrgsb.toString() + userLinesb.toString() + deptAndUsersb.toString();
            // 值不为;;;才是有效的候选人定义
            if (!"".equals(result) && result.length() != 2) {
                // 如果自定义用户不为空,则直接设置为自定义用户
                if (cuts != null && !"".equals(cuts)) {
                    Attribute attributeKey = DocumentHelper.createAttribute(owner,
                            FlowConstants.XMLUSER, cuts);
                    owner.add(attributeKey);
                } else {
                    Attribute attributeKey = DocumentHelper.createAttribute(owner,
                            FlowConstants.XMLUSERS, result);
                    owner.add(attributeKey);
                }
            } else {
                // 如果自定义用户不为空,则直接设置为自定义用户
                if (cuts != null && !"".equals(cuts)) {
                    Attribute attributeKey = DocumentHelper.createAttribute(owner,
                            FlowConstants.XMLUSER, cuts);
                    owner.add(attributeKey);
                } else {
                    Attribute attributeKey = DocumentHelper.createAttribute(owner,
                            FlowConstants.XMLUSER, FlowConstants.PROCESS_APPLICANT);
                    owner.add(attributeKey);
                }
            }
        }
    }
    /**
     * 委托人
     * @param owner
     */
    private void setConstituent(Element owner){
        List<String> users = constituentComponent.getSelectedUsers();
        List<String> roles = constituentComponent.getSelectedRoles();
        List<String> depts = constituentComponent.getSelectedDepts();
        String cuts = constituentComponent.getSelectedCust();
        
        StringBuilder usersb = new StringBuilder();
        StringBuilder rolesb = new StringBuilder();
        StringBuilder deptsb = new StringBuilder();
        
        if (users != null) {
            for (int i = 0; i < users.size(); i++) {
                usersb.append(users.get(i));
                if (i != users.size() - 1) {
                    usersb.append(",");
                }
            }
        }
        String result = usersb.toString();
        Attribute attributeKey = DocumentHelper.createAttribute(owner,
                FlowConstants.XMLCONSTITUENT, result);
        owner.add(attributeKey);
    }
    public ProcessTaskInfo getProcessTaskInfo(){
        ProcessTaskInfo info = new ProcessTaskInfo();
        info.taskName = nameField.getText().trim();
        info.taskType = taskTypePropertyPanel.getEvent();
        info.taskDesc = taskDescPanel.getTaskDesArea() ;
        info.pltreatment = taskTreatmentPanel.getFlag();
        info.taskTypeProperties = taskTypePropertyPanel.getTypePropertyInfos();
//        info.taskCCInfos = getTaskInfos();
        info.popUserDialog = taskTreatmentPanel.getPopUserDialogONOFF()==null?FlowConstants.POPUSERDIALOG_OFF:taskTreatmentPanel.getPopUserDialogONOFF();
        info.customUserInfos = customUserPanel.getCustomUserInfos();
        
        info.revoke = taskTreatmentPanel.getRevokeONOFF()==null?FlowConstants.REVOKE_OFF:taskTreatmentPanel.getRevokeONOFF();
        info.revokeInfos = getTaskrevoke(taskRevokeEventPropertyPanel, "revoke");
        return info;
    }
    private PropertyInfo[] getTaskrevoke(EventPanel eventPanel,
            String eventType){
        PropertyInfo[] customClassInfo = taskRevokeEventPropertyPanel.getCustomInfos();
        for (int i = 0; i < customClassInfo.length; i++) {
            PropertyInfo info = new PropertyInfo();
            for(int j =0;j<getEventTypes(eventType).length;j++){
                String className = customClassInfo[i].property;
                String classValue = "";
                String initEventClass = "";
                if(getEventTypes(eventType)[j].getValue().equals(className)){
                    classValue = getEventTypes(eventType)[j].getProperty();
                    /*initEventClass = EventProperties.getStringProperty("workflow.event.type." + classValue
                            + ".class");*/
                    //add by caill start 2016.4.8 通过corba连接服务端
                    try {
                        initEventClass = new EventConfClientDelegate().getStringProperty("workflow.event.type." + classValue
                                + ".class");
                    } catch (VCIError e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    //add by caill end
                }
                info.property = className;
                info.value = initEventClass;
            }
            customClassInfo[i] = info;
        }
        return customClassInfo;
    }
    
    private String getI18nForEvent(String key){
        return LocaleDisplay.getI18nString(key, "RMIPWorkflow", getLocale());
    }
 
    public void setProcessTaskInfo(ProcessTaskInfo processTaskInfo) {
        taskTypePropertyPanel.setProcessTaskInfo(processTaskInfo);
    }
 
    public void setEventInfo(ProcessTaskInfo processTaskInfo, String eventType) {
        updateTaskType(processTaskInfo,eventType);
        if(eventType.equals("start")) {
            taskInitEventPropertyPanel.setProcessTaskInfo(processTaskInfo);
        } else if(eventType.equals("end")) {
            taskEndEventPropertyPanel.setProcessTaskInfo(processTaskInfo);
        }else if (eventType.equals("revoke")) {
            taskRevokeEventPropertyPanel.setProcessTaskInfo(processTaskInfo);
        }
    }
    
    private void updateTaskType(ProcessTaskInfo processTaskInfo,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
        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;
            }
        }
 
    }
 
    public void setTaskCCs(List<String> users) {
        CCComponent.setSelectedUsers(users);
    }
    public void setconstituents(List<String> users) {
        constituentComponent.setSelectedUsers(users);
    }
    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")) {
            taskInitEventPropertyPanel.setCustomInfos(res);
        } else if (eventType.equals("end")) {
            taskEndEventPropertyPanel.setCustomInfos(res);
        }
    }
    public void setCustomInfo(CustomInfo[] customInfo) {
        customUserPanel.setCustomInfo(customInfo);
    }
    /**
     * 自定义用户
     * 
     * @param depts
     */
    public void setTaskCustOwners(String cust) {
        userComponent.setSelectedCust(cust);
    }
    public void setTaskUserDepartment(List<String> depts) {
        userComponent.setSelectedUserDepartment(depts);
    }
    public void setTaskUserRole(List<String> depts) {
        userComponent.setSelectedUserRole(depts);
    }
    public void setTaskUserDept(List<String> depts) {
        userComponent.setSelectedUserDept(depts);
    }
    public void setTaskUserLine(List<String> depts) {
        userComponent.setSelectedUserLine(depts);
    }
    public void setTaskDeptAndUser(List<String> depts) {
        userComponent.setSelectedDeptAndUser(depts);
    }
    public void setPopUserDialog(String flag){
        boolean popuserflag = flag.equals(FlowConstants.POPUSERDIALOG_ON);
        taskTreatmentPanel.getPopUserDialogCb().setSelected(popuserflag);
        if(popuserflag){
            taskTreatmentPanel.setPopUserDialogONOFF(FlowConstants.POPUSERDIALOG_ON);
        }else{
            taskTreatmentPanel.setPopUserDialogONOFF(FlowConstants.POPUSERDIALOG_OFF);    
        }
    }
    public void setRevoke(String flag){
        boolean revokeFlag = flag.equals(FlowConstants.REVOKE_ON);
        taskTreatmentPanel.getRevokeCb().setSelected(revokeFlag);
        if(revokeFlag){
            taskTreatmentPanel.setRevokeONOFF(FlowConstants.REVOKE_ON);
        }else{
            taskTreatmentPanel.setRevokeONOFF(FlowConstants.REVOKE_OFF);    
        }
    }
    public void setRevokeInfos(String eventType,PropertyInfo[] revokeInfos){
        taskRevokeEventPropertyPanel.setCustomInfos(revokeInfos);
    }
    public 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++) {
            if("".equals(types[i].trim())) continue;
            /*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]);
    }
}