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