zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
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
package cn.autoform.web.formula.info.impl.cpn;
 
import cn.autoform.db.entity.form.FormCpnInfo;
import cn.autoform.web.formula.info.FormCpn;
 
public class FormCpnFactory {
    
    public static FormCpn getFormCpn(FormCpnInfo field){
        FormCpn cpn = null;
        switch (field.getTagType()) {
            case text:
                cpn = new TextCpn();
                break;
            case textarea:
                cpn = new TextAreaCpn();
                break;
            case radio:
                cpn = new RadioCpn();
                break;
            case number:
                cpn = new NumberCpn();
                break;
            case mytext:
                cpn = new JoinFormCpn();
                break;
            case dropdownlist:
                cpn = new DropdownListCpn();
                break;
            case checkbox:
                cpn = new CheckboxCpn();
                break;
            case calendar:
                cpn = new CalendarCpn();
                break;
            case subform:
                cpn = new ChildCpn();
                break;
            case tree:
                cpn = new TreeCpn();
                break;
            default:
                return cpn;
        }
        cpn.init(field);
        return cpn;
    }
    
    /**
     * 克隆控件
     * @param formCpn
     * @return
     */
    public static FormCpn clone(FormCpn formCpn) {
        Class<?> clazz = formCpn.getClass();
        FormCpn cloneFormCpn = newInstance(clazz);
        if(cloneFormCpn == null)
            return null;
        cloneFormCpn.putAll(formCpn);
        cloneFormCpn.setFormCpnListener(formCpn.getFormCpnListener());
        cloneFormCpn.setFieldId(formCpn.getFieldId());
        
        return cloneFormCpn;
    }
    
    /**
     * 创建实例
     * @param clazz
     * @return
     */
    public static FormCpn newInstance(Class<?> clazz){
        try {
            return (FormCpn) clazz.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
            return null;
        }
    }
}