commit | author | age
|
a18bfa
|
1 |
package cn.autoform.web.formula.info.impl.cpn; |
Z |
2 |
|
|
3 |
import cn.autoform.db.entity.form.FormCpnInfo; |
|
4 |
import cn.autoform.web.formula.info.Form; |
|
5 |
import cn.autoform.web.formula.info.FormCpn; |
|
6 |
import cn.autoform.web.formula.info.FormCpnListener; |
|
7 |
import cn.autoform.web.formula.info.FormulaInfo; |
|
8 |
import cn.autoform.web.formula.prop.Attribute; |
|
9 |
import cn.autoform.web.formula.prop.CpnMsg; |
|
10 |
import cn.autoform.web.formula.prop.MsgType; |
|
11 |
import lombok.EqualsAndHashCode; |
|
12 |
import lombok.Getter; |
|
13 |
import lombok.Setter; |
|
14 |
import org.apache.commons.lang3.StringUtils; |
|
15 |
|
|
16 |
import java.util.*; |
|
17 |
|
|
18 |
/** |
|
19 |
* 普通控件抽象类 |
|
20 |
* @author WangYX |
|
21 |
* |
|
22 |
*/ |
|
23 |
@EqualsAndHashCode(callSuper=false, of={"fieldId", "index"}) |
|
24 |
public abstract class AbstractBaseFormCpn extends HashMap<Object, Object> implements FormCpn{ |
|
25 |
|
|
26 |
/** |
|
27 |
* |
|
28 |
*/ |
|
29 |
private static final long serialVersionUID = -1159764957350079218L; |
|
30 |
|
|
31 |
/** |
|
32 |
* 映射key |
|
33 |
*/ |
|
34 |
protected static Map<Object, Object> MAPPING_KEY = new HashMap<>(); |
|
35 |
|
|
36 |
static{ |
|
37 |
MAPPING_KEY.put("值", Attribute.value); |
|
38 |
} |
|
39 |
|
|
40 |
/* 表单控件监听 */ |
|
41 |
protected FormCpnListener formCpnListener; |
|
42 |
|
|
43 |
/* 触发事件 */ |
|
44 |
@Getter |
|
45 |
@Setter |
|
46 |
protected List<FormulaInfo> formulas; |
|
47 |
|
|
48 |
/* 控件别名 */ |
|
49 |
@Getter |
|
50 |
@Setter |
|
51 |
protected String fieldId; |
|
52 |
|
|
53 |
/* 父控件 */ |
|
54 |
@Setter |
|
55 |
protected FormCpn parentFormCpn; |
|
56 |
|
|
57 |
/* 在子表单中的下标 */ |
|
58 |
@Getter |
|
59 |
@Setter |
|
60 |
protected Integer index; |
|
61 |
|
|
62 |
public AbstractBaseFormCpn(/*String fieldId*/) { |
|
63 |
/*this.fieldId = fieldId;*/ |
|
64 |
this.formCpnListener = new BaseFormCpnListener(); |
|
65 |
} |
|
66 |
|
|
67 |
public void init(FormCpnInfo formCpnInfo){ |
|
68 |
this.fieldId = formCpnInfo.getTagAttribute().getAlias(); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public Object get(Object key) { |
|
73 |
Object mappIngKey = MAPPING_KEY.get(key); |
|
74 |
Object val = super.get(mappIngKey == null ? key : mappIngKey); |
|
75 |
return val == null ? "" : val; |
|
76 |
} |
|
77 |
|
|
78 |
|
|
79 |
@Override |
|
80 |
public Object put(Object key, Object value) { |
|
81 |
if(StringUtils.isBlank(Objects.toString(key))) |
|
82 |
return null; |
|
83 |
if(Objects.equals(FORMULA_KEY, key)) |
|
84 |
return setFormula((FormulaInfo) value); |
|
85 |
boolean isFormat = false; |
|
86 |
// 控件属性 可见,可编辑,值 |
|
87 |
if(!isFormat){ |
|
88 |
for(Attribute attr : Attribute.values()){ |
|
89 |
if(Objects.equals(attr.toString(), key.toString())){ |
|
90 |
key = Attribute.valueOf(Objects.toString(key)); |
|
91 |
isFormat = true; |
|
92 |
break; |
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
// 表单提示消息 |
|
97 |
if(!isFormat){ |
|
98 |
for(MsgType msg : MsgType.values()){ |
|
99 |
if(Objects.equals(msg.toString(), key.toString())){ |
|
100 |
((Form)get(FORM_KEY)).setMsg(MsgType.valueOf(Objects.toString(key)), Objects.toString(value, ""), this); |
|
101 |
return value; |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
105 |
// 控件错误消息 |
|
106 |
if(!isFormat){ |
|
107 |
for(CpnMsg msg : CpnMsg.values()){ |
|
108 |
if(Objects.equals(msg.toString(), key.toString())){ |
|
109 |
key = CpnMsg.valueOf(Objects.toString(key)); |
|
110 |
Object values = get(key); |
|
111 |
if(values == null) |
|
112 |
value = new ArrayList<>(Arrays.asList(value.toString())); |
|
113 |
else |
|
114 |
value = ((List)values).add(value); |
|
115 |
isFormat = true; |
|
116 |
break; |
|
117 |
} |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
try{ |
|
122 |
return super.put(key, value); |
|
123 |
}finally { |
|
124 |
if((key instanceof Attribute) && ((Attribute)key) == Attribute.value) |
|
125 |
formCpnListener.change(this); |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
/* |
|
130 |
* 添加事件 |
|
131 |
*/ |
|
132 |
public Object setFormula(FormulaInfo value) { |
|
133 |
if(this.formulas == null) |
|
134 |
this.formulas = new ArrayList<>(); |
|
135 |
this.formulas.add(value); |
|
136 |
return value; |
|
137 |
} |
|
138 |
|
|
139 |
@Override |
|
140 |
public void setFormCpnListener(FormCpnListener formCpnListener) { |
|
141 |
this.formCpnListener = formCpnListener; |
|
142 |
} |
|
143 |
|
|
144 |
@Override |
|
145 |
public FormCpnListener getFormCpnListener() { |
|
146 |
return this.formCpnListener; |
|
147 |
} |
|
148 |
|
|
149 |
@Override |
|
150 |
public FormCpn getParentCpn() { |
|
151 |
return this.parentFormCpn; |
|
152 |
} |
|
153 |
|
|
154 |
@Override |
|
155 |
public FormCpn clone(){ |
|
156 |
// return FormCpnFactory.clone(this); |
|
157 |
return (FormCpn) super.clone(); |
|
158 |
} |
|
159 |
|
|
160 |
@Override |
|
161 |
public Object getValue() { |
|
162 |
return get(Attribute.value); |
|
163 |
} |
|
164 |
|
|
165 |
} |