1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.field;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.datadictionary.validator.ErrorReport;
22 import org.kuali.rice.krad.datadictionary.validator.Validator;
23 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
24 import org.kuali.rice.krad.uif.component.Component;
25 import org.kuali.rice.krad.uif.element.Link;
26 import org.kuali.rice.krad.uif.view.View;
27 import org.kuali.rice.krad.uif.widget.LightBox;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32
33
34
35
36
37 @BeanTag(name = "linkField-bean", parent = "Uif-LinkField")
38 public class LinkField extends FieldBase {
39 private static final long serialVersionUID = -1908504471910271148L;
40
41 private Link link;
42
43 public LinkField() {
44 super();
45 }
46
47
48
49
50
51
52
53
54
55
56
57 @Override
58 public void performInitialization(View view, Object model) {
59 super.performInitialization(view, model);
60
61 if (StringUtils.isBlank(getLinkText())) {
62 setLinkText(this.getLabel());
63 }
64 }
65
66
67
68
69
70
71
72
73
74 @Override
75 public void performFinalize(View view, Object model, Component parent) {
76 super.performFinalize(view, model, parent);
77
78
79 if (this.getFieldLabel() != null && this.getLink() != null && StringUtils.isNotBlank(this.getLink().getId())) {
80 this.getFieldLabel().setLabelForComponentId(this.getLink().getId());
81 }
82 }
83
84
85
86
87 @Override
88 public List<Component> getComponentsForLifecycle() {
89 List<Component> components = super.getComponentsForLifecycle();
90
91 components.add(link);
92
93 return components;
94 }
95
96
97
98
99
100
101 @BeanTagAttribute(name="link",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
102 public Link getLink() {
103 return link;
104 }
105
106
107
108
109
110
111 public void setLink(Link link) {
112 this.link = link;
113 }
114
115
116
117
118
119
120 @BeanTagAttribute(name="linkText")
121 public String getLinkText() {
122 return link.getLinkText();
123 }
124
125
126
127
128
129
130 public void setLinkText(String linkLabel) {
131 link.setLinkText(linkLabel);
132 }
133
134
135
136
137
138
139 @BeanTagAttribute(name="target")
140 public String getTarget() {
141 return link.getTarget();
142 }
143
144
145
146
147
148
149 public void setTarget(String target) {
150 link.setTarget(target);
151 }
152
153
154
155
156
157
158 @BeanTagAttribute(name="href")
159 public String getHref() {
160 return link.getHref();
161 }
162
163
164
165
166
167
168 public void setHref(String hrefText) {
169 link.setHref(hrefText);
170 }
171
172
173
174
175
176
177 public void setLightBox(LightBox lightBox) {
178 if (link != null) {
179 link.setLightBox(lightBox);
180 }
181 }
182
183
184
185
186
187
188 @BeanTagAttribute(name="lightBox",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
189 public LightBox getLightBox() {
190 if (link != null) {
191 return link.getLightBox();
192 }
193
194 return null;
195 }
196
197
198
199
200 @Override
201 public void completeValidation(ValidationTrace tracer){
202 tracer.addBean(this);
203
204
205 if(getLink()==null){
206 if(Validator.checkExpressions(this, "link")){
207 String currentValues [] = {"link = "+getLink()};
208 tracer.createError("Link should be set",currentValues);
209 }
210 }
211
212
213 if(getLabel()==null){
214 if(Validator.checkExpressions(this, "label")){
215 String currentValues [] = {"label ="+getLabel(),"link ="+getLink()};
216 tracer.createWarning("Label is null, link should be used instead",currentValues);
217 }
218 }
219
220 super.completeValidation(tracer.getCopy());
221 }
222
223
224
225
226 @Override
227 protected <T> void copyProperties(T component) {
228 super.copyProperties(component);
229 LinkField linkFieldCopy = (LinkField) component;
230
231 if (this.link != null) {
232 linkFieldCopy.setLink((Link)this.link.copy());
233 }
234 }
235 }