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
package com.vci.client.uif.engine.client.controls;
 
import java.awt.Color;
import java.awt.Component;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
 
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
 
import com.vci.client.bof.AttributeChecker;
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.omd.btm.ui.BtmClient;
import com.vci.client.omd.provider.ApProvider;
import com.vci.client.omd.provider.EnumProvider;
import com.vci.client.portal.utility.DataModelFactory;
import com.vci.client.portal.utility.PRMItem;
import com.vci.client.ui.swing.components.VCIJComboBox;
import com.vci.client.ui.swing.components.VCIJLabel;
import com.vci.client.ui.swing.components.VCIJPasswordField;
import com.vci.client.ui.swing.components.VCIJRadioButton;
import com.vci.client.ui.swing.components.VCIJRealTextField;
import com.vci.client.ui.swing.components.VCIJTextArea;
import com.vci.client.ui.swing.components.VCIJTextField;
import com.vci.client.ui.swing.components.table.AbstractVCIJTableDataProvider;
import com.vci.client.ui.swing.components.table.VCIJTableDataProvider;
import com.vci.client.ui.swing.components.table.VCIJTableNode;
import com.vci.client.ui.swing.components.table.VCIJTablePanel;
import com.vci.client.ui.swing.event.VciKeyListener;
import com.vci.client.uif.actions.client.UIFUtils;
import com.vci.client.uif.engine.client.combobox.IComboBoxDataProvider;
import com.vci.common.portal.enums.ControlType;
import com.vci.common.resource.CommonProperties;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.atm.AttribItem;
import com.vci.corba.omd.btm.BtmItem;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.omd.etm.EnumChild;
import com.vci.corba.omd.etm.EnumItem;
import com.vci.corba.omd.lcm.LifeCycle;
import com.vci.corba.omd.lcm.TransitionVO;
 
public class ControlFactory {
    
    /**
     * 返回用于显示ClientBusinessObject的TablePanel
     * @param fieldToNameMap field to name map key:field value:属性名称
     * @param cbos ClientBusinessObject 对象列表
     * @return 加载了数据的TablePanel
     */
    public VCIJTablePanel<ClientBusinessObject> getClientBusinessObjectDataPanel(
            HashMap<String, String> fieldToNameMap, ClientBusinessObject[] cbos){
        final HashMap<String, String> map = fieldToNameMap;
        final ClientBusinessObject[] objs = cbos;
        VCIJTableDataProvider<ClientBusinessObject> dataProvider = new AbstractVCIJTableDataProvider<ClientBusinessObject>() {
            String[] specialColumns = new String[0];
            LinkedList<String> nameList = new LinkedList<String>();
            LinkedList<String> fieldList = new LinkedList<String>();
            {
                Iterator<String> its = map.keySet().iterator();
                while(its.hasNext()){
                    String field = its.next();
                    String name = map.get(field);
                    fieldList.add(field);
                    nameList.add(name);
                }
                specialColumns = nameList.toArray(new String[]{});
            }
            @Override
            public String[] getSpecialColumns() {
                return specialColumns;
            }
 
            @Override
            public int getTotal() {
                return objs.length;
            }
 
            @Override
            public VCIJTableNode<ClientBusinessObject> getNewRowNode(
                    ClientBusinessObject dataObj) {
                VCIJTableNode<ClientBusinessObject> node = new VCIJTableNode<ClientBusinessObject>(dataObj);
                for(int i = 0; i < nameList.size(); i++){
                    String field = fieldList.get(i);
                    String name = nameList.get(i);
                    node.setPropertyValue(name, dataObj.getAttributeValue(field));
                }
                return node;
            }
 
            @Override
            public ClientBusinessObject[] getDatas(int pageIndex, int pageSize) {
                return objs;
            }
        };
        VCIJTablePanel<ClientBusinessObject> pal = new VCIJTablePanel<ClientBusinessObject>(dataProvider);
        pal.buildTablePanel();
        pal.refreshTableData();
        return pal;
    }
    
    private static   AttributeChecker curAttrChecker = null;
    
    private static Component createBooleanTypeControl(PRMItem item){
        Component compt = null;
        String field = item.getItemField();
        int index = field.lastIndexOf(".");
        if(index > 0){
            field = field.substring(index + 1);
        }
        if (curAttrChecker == null) {
            curAttrChecker = new AttributeChecker();
            curAttrChecker.getAllAttribute();
        }
        AttribItem ai = curAttrChecker.attrItemMap.get(field);
        if(ai != null){
            if(ai.vtDataType.equals("VTBoolean")){
                VCIJComboBox cbx = new VCIJComboBox();
                DefaultComboBoxModel aModel = new DefaultComboBoxModel();
                aModel.addElement(new VCIJComboBoxModelValueObject("false", "否"));
                aModel.addElement(new VCIJComboBoxModelValueObject("true", "是"));
                cbx.setModel(aModel);
                int selectedIndex = 0;
                if(item.getItemValue() != null){
                    if(item.getItemValue().equals("false")){
                        selectedIndex = 0;
                    }else {
                        selectedIndex = 1;
                    }
                    cbx.setSelectedIndex(selectedIndex);;
                }
                compt = cbx;
            }
        }
        return compt;
    }
 
    /**
     * 判断UI表单的属性是否是必填的
     * @param item UI表单定义的单个属性元素
     * @return true:可以编辑  false:不可以编辑
     */
    public static boolean isRequired(PRMItem item){
        // 1:必填  0:非必填
        return item.getItemIsRequired().equals("1")?true:false;
    }
    /**
     * 判断UI表单的属性是否是可编辑的 
     * @param item UI表单定义的单个属性元素
     * @return true:可以编辑  false:不可以编辑
     */
    public static boolean isEditable(PRMItem item){
        // 1:只读 0:非只读
        return item.getItemIsEditable().equals("1")?false:true;
    }
    
    //modify by weidayong@2017/12/14  
    //因为在查询区域中如果有多行文本的时候,界面会不停地往右边撑大也页面,因此在此场景中,把多行文本处理成单行文本
    
    /**
     * 用于查询区域部分的创建
     * @param item
     * @return
     */
    public static Component createControlForSearch(PRMItem item){
        return createControl(item,true);
    }
    
    
    public static Component createControl(PRMItem item){
        return createControl(item,false);
    }
    
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static Component createControl(PRMItem item,boolean isUseToSearchArea){
        Component compt = null;
        String itemType = item.getItemType().toLowerCase();
        
        System.out.println("====itemType = " + itemType);
        
        ControlType ctrlType = ControlType.Parse(itemType);
        if (ctrlType == null)
            return null;
        
        System.out.println("====ctrlType = " + ctrlType.name());
 
        String itemListTable = item.getItemListTable();
        String itemListValue = item.getItemListVal();
        boolean required = isRequired(item);
        boolean editable = isEditable(item);
        
        compt = createBooleanTypeControl(item);
        if(compt != null) {
            return compt;
        }
        
        if(itemListTable != null && !"".equals(itemListTable) && 
                itemListValue != null && !"".equals(itemListValue)){
            //自定义类
            String refClass = CommonProperties.getStringProperty("engin.refObjectChoose");
            if(refClass!=null&&!"".equals(refClass)){
                try {
                    Class c = Class.forName(refClass);
                    compt = (Component) c.getConstructor(PRMItem.class).newInstance(item);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                } catch (SecurityException e) {
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                } catch (NoSuchMethodException e) {
                    e.printStackTrace();
                }
            }else{
                compt = createRefObjChooseControl(item);
            }
        } else if(ctrlType == ControlType.Checkbox) { //itemType.equals(ControlType.Checkbox.name().toLowerCase())){
            compt = createCheckBoxControl(item, required, editable);
        } else if(ctrlType == ControlType.Text) { //itemType.equals(ControlType.Text.name().toLowerCase())){
            compt = createText(item, required, editable);
        } else if(ctrlType == ControlType.TextBtn) { //itemType.equals(ControlType.TextBtn.name().toLowerCase())){
            compt = createTextBtn(item, required, editable);
        } else if(ctrlType == ControlType.TextArea) { //itemType.equals(ControlType.TextArea.name().toLowerCase())){
            if(isUseToSearchArea){//weidy主要修改的此处
                compt = createText(item, required, editable);
            }else{
                compt = createTextArea(item, required, editable);
            }
        } else if(ctrlType == ControlType.Number) { //itemType.equals(ControlType.Number.name().toLowerCase())){
            compt = createNumber(item, required, editable);
        } else if(ctrlType == ControlType.Password) { //itemType.equals(ControlType.Password.name().toLowerCase())){
            compt = createPassword(item, required, editable);
        } else if(ctrlType == ControlType.Radio) { //itemType.equals(ControlType.Radio.name().toLowerCase())){
            compt = createRadion(item, required, editable);
        } else if(ctrlType == ControlType.Select) { //itemType.equals(ControlType.Select.name().toLowerCase())){
            compt = createSelect(item, required, editable);
        }  else if(ctrlType == ControlType.WebEditor) { //itemType.equals(ControlType.WebEditor.name().toLowerCase())){
            //WebEditor
            compt = createNotimplement(item, required, editable, ControlType.WebEditor.name());
        } else if(ctrlType == ControlType.Date) { //itemType.equals(ControlType.Date.name().toLowerCase())){
            compt = createDate(item, required, editable);
        } else if(ctrlType == ControlType.Time) { //itemType.equals(ControlType.Time.name().toLowerCase())){
            compt = createTime(item, required, editable);
        } else if(ctrlType == ControlType.Datetime) { //itemType.equals(ControlType.Datetime.name().toLowerCase())){
            compt = createDateTime(item, required, editable);
        } else if(ctrlType == ControlType.Customform) { //itemType.equals(ControlType.Customform.name().toLowerCase())){
            //TODO Customform
            compt = createNotimplement(item, required, editable, ControlType.Customform.name());
        } else if(ctrlType == ControlType.File) { //itemType.equals(ControlType.File.name().toLowerCase())){
            compt = createFile(item, required, editable);
        } else if(ctrlType == ControlType.MultiFile) { //itemType.equals(ControlType.MultiFile.name().toLowerCase())){
            compt = createMultiFile(item, required, editable);
        } else if(ctrlType == ControlType.Custom) { //itemType.equals(ControlType.Custom.name().toLowerCase())){
            compt = getCustomControl(item);
        } else if(ctrlType == ControlType.UserChoose) { //itemType.equals(ControlType.UserChoose.name().toLowerCase())){
            compt = createUserChooseControl(item, required, editable);
        }
        return compt;
    }
    
    //end weidy@2017/12/14
    
    private static Component getCustomControl(PRMItem item){
        Component res = null;
        try {
            String className = item.getItemCustomClass();
            
            if (className == null || "".equals(className))
                return null;
            
            Class<?> c1 = Class.forName(className);
            //if (!c1.isAssignableFrom(ICustomControl.class) && !c1.isAssignableFrom(Component.class)) {
            //    return null;
            //}
            
            ICustomControl ctrl = null;
            //Object obj = c1.getConstructor(PRMItem.class).newInstance(item);
 
            Object obj = null;
            try {
                Constructor<?>  con  = c1.getConstructor(PRMItem.class);
                if (con != null)
                    obj = con.newInstance(item);
            } catch (Exception ex){
                Constructor<?> con = c1.getConstructor();
                obj = con.newInstance();
            }
            
            if (obj instanceof ICustomControl) {
                ctrl = (ICustomControl) obj;
                ctrl.setPRMItem(item);
            }
            
            if (obj instanceof Component) {
                res = (Component) obj;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return res;
    }
    
    private static RefObjChooseControl createRefObjChooseControl(PRMItem item){
        RefObjChooseControl res = new RefObjChooseControl(item);
        res.setObj(item);
        return res;
    }
    
    private static VCIJLabel createNotimplement(PRMItem item, boolean required, boolean editable, String text){
        VCIJLabel res = new VCIJLabel(text + " not implement ");
        res.setObj(item);
        res.setForeground(Color.red);
        return res;
    }
 
    private static CheckBoxControl createCheckBoxControl(PRMItem item, boolean required, boolean editable){
        CheckBoxControl res = new CheckBoxControl(item, required, editable);
        res.setObj(item);
        return res;
    }
    
    private static VCIJTextField createText(PRMItem item, boolean required, boolean editable){
        String extParameterStr = item.getItemStyle();
        String[] extParameterArray = extParameterStr.split(";");
        String key = "keyListener";
        String value = "";
        String rightClickKey = "rightClickEvent";
        String rightClickVal = "";
        for (int i = 0; i < extParameterArray.length; i++) {
            String extParameter = extParameterArray[i];
            if (extParameter == null) {
                continue;
            }
            String[] parameters = extParameter.split("=");
            if (parameters == null || parameters.length != 2) {
                continue;
            }
            if (parameters[0].equalsIgnoreCase(key)) {
                value = parameters[1];
            } else if (parameters[0].equalsIgnoreCase(rightClickKey)) {
                rightClickVal = parameters[1];
            }
        }
        boolean isSupportRightClick = true;
        if (rightClickVal != null && rightClickVal.equalsIgnoreCase("false")) {
            isSupportRightClick = false;
        }
        VCIJTextField res = new VCIJTextField("", isSupportRightClick);
        res.setRequired(required);
        res.setEditable(editable);
        res.setObj(item);
        if (value != null && !value.trim().equals("")) {
            try {
                Class<?> cls;
                cls = Class.forName(value);
                VciKeyListener keyListener = (VciKeyListener)cls.getConstructor(Object.class).newInstance(item);
                res.addKeyListener(keyListener);
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
        return res;
    }
    
    
    private static VCIJTextField createTextBtn(PRMItem item, boolean required, boolean editable){
        String extParameterStr = item.getItemStyle();
        String[] extParameterArray = extParameterStr.split(";");
        String key = "keyListener";
        String value = "";
        String rightClickKey = "rightClickEvent";
        String rightClickVal = "";
        for (int i = 0; i < extParameterArray.length; i++) {
            String extParameter = extParameterArray[i];
            if (extParameter == null) {
                continue;
            }
            String[] parameters = extParameter.split("=");
            if (parameters == null || parameters.length != 2) {
                continue;
            }
            if (parameters[0].equalsIgnoreCase(key)) {
                value = parameters[1];
            } else if (parameters[0].equalsIgnoreCase(rightClickKey)) {
                rightClickVal = parameters[1];
            }
        }
        boolean isSupportRightClick = true;
        if (rightClickVal != null && rightClickVal.equalsIgnoreCase("false")) {
            isSupportRightClick = false;
        }
        VCIJTextField res = new VCIJTextField("", isSupportRightClick);
        res.setRequired(required);
        res.setEditable(editable);
        res.setObj(item);
        if (value != null && !value.trim().equals("")) {
            try {
                Class<?> cls;
                cls = Class.forName(value);
                VciKeyListener keyListener = (VciKeyListener)cls.getConstructor(Object.class).newInstance(item);
                res.addKeyListener(keyListener);
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
        return res;
    }
    
    private static VCIJTextArea createTextArea(PRMItem item, boolean required, boolean editable){
        VCIJTextArea res = new VCIJTextArea("");
        res.setBorder(null);
        res.setRequired(required);
        res.setEditable(editable);
        res.setObj(item);
        res.setLineWrap(true);
        return res;
    }
 
    private static VCIJRealTextField createNumber(PRMItem item, boolean required, boolean editable){
        VCIJRealTextField res = new VCIJRealTextField("");
        res.setRequired(required);
        res.setEditable(editable);
        res.setObj(item);
        return res;
    }
    
    private static VCIJPasswordField createPassword(PRMItem item, boolean required, boolean editable){
        VCIJPasswordField res = new VCIJPasswordField();
        res.setRequired(required);
        res.setEditable(editable);
        res.setObj(item);
        return res;
    }    
    
    private static VCIJRadioButton createRadion(PRMItem item, boolean required, boolean editable){
        VCIJRadioButton res = new VCIJRadioButton();
        res.setRequired(required);
        res.setObj(item);
        return res;
    }
//    private static VCIJComboBox createCheckBox(PRMItem item, boolean required, boolean editable){
//        VCIJComboBox res = new VCIJComboBox();
//        res.setRequired(required);
//        res.setObj(item);
//        return res;
//    }
    private static VCIJComboBox createSelect(PRMItem item, boolean required, boolean editable){
        VCIJComboBox res = new VCIJComboBox();
        res.setRequired(required);
        res.setModel(getSelectDataModel(item, required));
        res.setObj(item);
        //add by songyf
        res.setEnabled(editable);
        if (editable) {
            res.setBackground(Color.WHITE);
        }
        String itemClass = item.getItemCustomClass();
        if(itemClass != null && !"".equals(itemClass)){
            IComboBoxDataProvider dataProvider = UIFUtils.getComboBoxDataProvider(itemClass);
            if(dataProvider != null){
                VCIJComboBoxModelValueObject[] datas = dataProvider.getDatas();
                if(datas != null){
                    DefaultComboBoxModel model = new DefaultComboBoxModel();
                    for(VCIJComboBoxModelValueObject bmvo : datas){
                        model.addElement(bmvo);
                    }
                    res.setModel(model);
                }
            }
        }
        return res;
    }
    
    private static ComboBoxModel getSelectDataModel(PRMItem item, boolean required){
        ComboBoxModel model = new DefaultComboBoxModel();
        
        List<String> list = item.getItemValueList();
        boolean isEnumAttr = isEnumAttr(item.getItemField());
        if (isEnumAttr == false) {
            list.clear();        //修正:非枚举属性选项定义无效处理,modify zhonggy 2015-06-02
        }else if(list.size() > 0) {
            //根据枚举定义修正表单选项定义    Add by zhonggy 2015-06-02
            String[] fields = item.getItemField().split("\\.");
            AttribItem attr = ApProvider.getInstance().getAbItemByName(fields[fields.length - 1]);
            String enumName = ApProvider.getInstance().getOtherValueByType(attr.other, "enumName");
            if (enumName== null || enumName.equals("")) {
                list.clear();
            }
            Map<String,String> listMap = new HashMap<String,String>();
            for (int i = 0; i < list.size(); i++) {
                String valueStr = list.get(i);
                //String value = valueStr.substring(0, valueStr.indexOf("{"));
                String key = valueStr.substring(valueStr.indexOf("{") + 1, valueStr.indexOf("}"));
                if (!listMap.containsKey(key)) {
                    listMap.put(key, valueStr);
                }
            }
            Map<String, String> enumChildMap = new HashMap<String, String>();
            EnumItem enumItem = EnumProvider.getInstance().getEnumByName(enumName);
            for (EnumChild child : enumItem.children) {
                String key = child.value;
                if (!enumChildMap.containsKey(key)) {
                    enumChildMap.put(key, child.name);
                }
            }
            for (Map.Entry<String, String> Listitem : listMap.entrySet()) {
                if (!enumChildMap.containsKey(Listitem.getKey())) {
                    list.remove(Listitem.getValue());        //去掉无效的选项
                }
            }
        }
        Map<String, String> map = new HashMap<String, String>();
        if (list.size() > 0) {
            model = getSelectListDataModel(item, list, "", map);
        }  else if ((!item.getItemListTable().equals("") || !item.getItemListTxt().equals("")) && !item.getItemListVal().equals("")) { 
            // 参照属性
            model = getSelectRefDataModel(item, map);
        } else if (!item.getItemAddFilter().equals("")) {
//            BusinessObjectConstants.SELECT_ATTRIBUTE.put(selectVal, item.getItemAddFilter());
//            getSelectTypeQueryHtml(field, operation, map, item);
        } else if(isEnumAttr){
            model = getSelectEnumDataModel(item, "", map, required);
        } else if(isLCStatusAttr(item.getItemField())){
            System.out.println(item);
        }
        return model;
    }
    
    /**
     * 判断属性是否是 生命周期属性
     * @param field 属性名称
     * @return
     */
    public static boolean isLCStatusAttr(String field){
        return (field.equalsIgnoreCase("lcstatus") || field.contains(".lcstatus"));
    }
    
    /**
     * 返回生命周期属性 ComboBoxModel
     * @param prmItem prmItem
     * @param btmName 业务类型名称
     * @return
     */
    public static ComboBoxModel getLCStatusComboboxModel(PRMItem prmItem, String btmName){
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        if(btmName == null || "".equals(btmName) || !isLCStatusAttr(prmItem.getItemField())) return model;
        int insertIndex = 0;
        if(prmItem != null && !prmItem.getItemField().equals("") && !isRequired(prmItem)){
            VCIJComboBoxModelValueObject mvo = new VCIJComboBoxModelValueObject("", "");
            model.addElement(mvo);
            insertIndex = 1;
        }
        try {
            BtmItem bi = BtmClient.getService().getBtmItemByName(btmName);
            if(bi == null || "".equals(bi.name)) return model;
            
            UIFUtils uif = new UIFUtils();
            LifeCycle lc = UIFUtils.getLifeCycle(bi.lifeCycle);
            if(lc == null) return model;
            TransitionVO[] routes = lc.routes;
            String startStatus = lc.startState;
            Map<String, TransitionVO> map = new HashMap<String, TransitionVO>();
            
            for(TransitionVO tvo : routes){
                String value = tvo.source;
                if(value == null || "".equals(value)) continue;
                String name = uif.transferLifecycle(tvo.source);
                if(value == null || "".equals(value)) continue;
                if(map.containsKey(value)) continue;
                map.put(value, tvo);
                VCIJComboBoxModelValueObject mvo = new VCIJComboBoxModelValueObject(value, name);
                if(startStatus.equals(value)){
                    model.insertElementAt(mvo, insertIndex);
                } else {
                    model.addElement(mvo);
                }
            }
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return model;
    }
    
    /**
     * 判断属性是否是使用枚举 
     * @param field 属性名称
     * @return
     */
    public static boolean isEnumAttr(String field){
        boolean res = false;
        String[] fields = field.split("\\.");
        AttribItem attr = ApProvider.getInstance().getAbItemByName(fields[fields.length - 1]);
        if(attr == null) return false;
        String enumName = ApProvider.getInstance().getOtherValueByType(attr.other, "enumName");
        if(enumName == null || "".equals(enumName)) return false;
        EnumItem enumItem = EnumProvider.getInstance().getEnumByName(enumName);
        if(enumItem == null) return false;
        res = true;
        return res;
    }
    
    private static ComboBoxModel getSelectListDataModel(PRMItem item, List<String> list, String operation, Map<String, String>  map){
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        for (int i = 0; i < list.size(); i++) {
            String valueStr = list.get(i);
            String key = valueStr.substring(0, valueStr.indexOf("{"));
            String value = valueStr.substring(valueStr.indexOf("{") + 1, valueStr.indexOf("}"));
            VCIJComboBoxModelValueObject data = new VCIJComboBoxModelValueObject(value, key);
            model.addElement(data);
        }
        return model;
    }
 
    private static ComboBoxModel getSelectRefDataModel(PRMItem item, Map<String, String>  map){
        DefaultComboBoxModel model = new DefaultComboBoxModel();
 
//        String field = item.getItemField();
        String type = item.getItemListTable();
        if (!item.getItemListTxt().equals("")) {
            type = item.getItemListTxt();
        }
//        String[] fields = field.split("\\.");
        String column = item.getItemListVal();
        String affectCol = item.getItemQueryRefFields();
        if (affectCol == null) {
            affectCol = "";
        }
        
        DataModelFactory factory = new DataModelFactory();
        BusinessObject[] bos = new BusinessObject[0];
        try {
            bos = factory.getAllTypeInfo(type);
        } catch (VCIError e) {
            e.printStackTrace();
        } 
        
        for (int i = 0; i < bos.length; i++) {
            String oidVal = getBOValueByAttr("oid", bos[i]);
            String displayVal = getBOValueByAttr(column, bos[i]);
            
            VCIJComboBoxModelValueObject vo = new VCIJComboBoxModelValueObject(oidVal, displayVal);
            model.addElement(vo);
        }
        return model;
    }
    protected static String getBOValueByAttr(String attrName, BusinessObject bo) {
        for (int i = 0; i < bo.hisAttrValList.length; i++) {
            if (bo.hisAttrValList[i].attrName.equalsIgnoreCase(attrName)) {
                return bo.hisAttrValList[i].attrVal;
            }
        }
        return "";
    }
    
    private static ComboBoxModel getSelectEnumDataModel(PRMItem item, String operation, Map<String, String>  map, boolean required){
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        String[] fields = item.getItemField().split("\\.");
        AttribItem attr = ApProvider.getInstance().getAbItemByName(fields[fields.length - 1]);
        String enumName = ApProvider.getInstance().getOtherValueByType(attr.other, "enumName");
        if (enumName== null || enumName.equals("")) {
            return model;
        }
        EnumItem enumItem = EnumProvider.getInstance().getEnumByName(enumName);
        if(!required){
            model.addElement(new VCIJComboBoxModelValueObject("", ""));
        }
        for (EnumChild child : enumItem.children) {
            VCIJComboBoxModelValueObject data = new VCIJComboBoxModelValueObject(child.value, child.name);
            model.addElement(data);
        }
        return model;
    }
    
    private static DateTimeControl createDateTime(PRMItem item, boolean required, boolean editable){
        DateTimeControl res = new DateTimeControl(item);
        res.setObj(item);
        //add by songyf
        res.setEnabled(editable);
        return res;
    }
    
    private static DateControl createDate(PRMItem item, boolean required, boolean editable){
        DateControl res = new DateControl(item);
        res.setObj(item);
        //add by songyf
        res.setEnabled(editable);
        return res;
    }
    private static TimeControl createTime(PRMItem item, boolean required, boolean editable){
        TimeControl res = new TimeControl(item);
        res.setObj(item);
        //add by songyf
        res.setEnabled(editable);
        return res;
    }
    
    /**
     * @Title        :createFile
     * @Description    : Modify By ZGY 2015-03-19
     * @param item
     * @param required
     * @param editable
     * @return
     */
    private static Component createFile(PRMItem item, boolean required, boolean editable){
        AbstractCustomControl panel = null;
        try {
            panel = new FileChooseControlPanel(item);
            panel.setObj(item);
            return panel;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    
    private static FileChooseControlPanel createMultiFile(PRMItem item, boolean required, boolean editable){
        FileChooseControlPanel res = new FileChooseControlPanel(item);
        res.setObj(item);
        return res;
    }
    
    
    private static UserChooseControl createUserChooseControl(PRMItem item, boolean required, boolean editable){
        UserChooseControl res = new UserChooseControl(item);
        res.setEnabled(editable);
        return res;
    }
}