1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.layout;
17
18 import com.google.common.collect.Lists;
19 import com.google.common.collect.Maps;
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22 import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase;
23 import org.kuali.rice.krad.uif.component.Component;
24 import org.kuali.rice.krad.uif.component.PropertyReplacer;
25 import org.kuali.rice.krad.uif.component.ReferenceCopy;
26 import org.kuali.rice.krad.uif.container.Container;
27 import org.kuali.rice.krad.uif.view.View;
28
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34
35
36
37
38
39
40
41
42
43
44
45 public abstract class LayoutManagerBase extends UifDictionaryBeanBase implements LayoutManager {
46 private static final long serialVersionUID = -2657663560459456814L;
47
48 private String id;
49 private String template;
50 private String templateName;
51
52 private String style;
53 private List<String> libraryCssClasses;
54 private List<String> cssClasses;
55 private List<String> additionalCssClasses;
56
57 @ReferenceCopy(newCollectionInstance = true)
58 private Map<String, Object> context;
59
60 private List<PropertyReplacer> propertyReplacers;
61
62 public LayoutManagerBase() {
63 super();
64
65 cssClasses = new ArrayList<String>();
66 context = new HashMap<String, Object>();
67 propertyReplacers = new ArrayList<PropertyReplacer>();
68 }
69
70
71
72
73
74 @Override
75 public void performInitialization(View view, Object model, Container container) {
76
77 if (StringUtils.isBlank(id)) {
78 id = container.getId() + "_layout";
79 }
80 }
81
82
83
84
85
86 @Override
87 public void performApplyModel(View view, Object model, Container container) {
88
89 }
90
91
92
93
94
95 @Override
96 public void performFinalize(View view, Object model, Container container) {
97
98 List<String> finalCssClasses = new ArrayList<String>();
99
100 if(this.libraryCssClasses != null && view.isUseLibraryCssClasses()){
101 finalCssClasses.addAll(libraryCssClasses);
102 }
103
104 if(this.cssClasses != null){
105 finalCssClasses.addAll(cssClasses);
106 }
107
108 if(this.additionalCssClasses != null){
109 finalCssClasses.addAll(additionalCssClasses);
110 }
111
112 cssClasses = finalCssClasses;
113 }
114
115
116
117
118
119
120 @Override
121 public Class<? extends Container> getSupportedContainer() {
122 return Container.class;
123 }
124
125
126
127
128 @Override
129 public List<Component> getComponentsForLifecycle() {
130 return new ArrayList<Component>();
131 }
132
133
134
135
136 @Override
137 public List<Component> getComponentPrototypes() {
138 List<Component> components = new ArrayList<Component>();
139
140 return components;
141 }
142
143
144
145
146 @Override
147 @BeanTagAttribute(name = "id")
148 public String getId() {
149 return this.id;
150 }
151
152
153
154
155 @Override
156 public void setId(String id) {
157 this.id = id;
158 }
159
160
161
162
163 @Override
164 @BeanTagAttribute(name = "template")
165 public String getTemplate() {
166 return this.template;
167 }
168
169
170
171
172 @Override
173 public void setTemplate(String template) {
174 this.template = template;
175 }
176
177
178
179
180 @BeanTagAttribute(name = "tempateName")
181 public String getTemplateName() {
182 return templateName;
183 }
184
185
186
187
188 public void setTemplateName(String templateName) {
189 this.templateName = templateName;
190 }
191
192
193
194
195 @Override
196 @BeanTagAttribute(name = "Style")
197 public String getStyle() {
198 return this.style;
199 }
200
201
202
203
204 @Override
205 public void setStyle(String style) {
206 this.style = style;
207 }
208
209
210
211
212 @Override
213 @BeanTagAttribute(name = "libraryCssClasses", type = BeanTagAttribute.AttributeType.LISTVALUE)
214 public List<String> getLibraryCssClasses() {
215 return libraryCssClasses;
216 }
217
218
219
220
221 @Override
222 public void setLibraryCssClasses(List<String> libraryCssClasses) {
223 this.libraryCssClasses = libraryCssClasses;
224 }
225
226
227
228
229 @Override
230 @BeanTagAttribute(name = "cssClasses", type = BeanTagAttribute.AttributeType.LISTVALUE)
231 public List<String> getCssClasses() {
232 return this.cssClasses;
233 }
234
235
236
237
238 @Override
239 @BeanTagAttribute(name = "additionalCssClasses", type = BeanTagAttribute.AttributeType.LISTVALUE)
240 public List<String> getAdditionalCssClasses() {
241 return additionalCssClasses;
242 }
243
244
245
246
247 @Override
248 public void setAdditionalCssClasses(List<String> additionalCssClasses) {
249 this.additionalCssClasses = additionalCssClasses;
250 }
251
252
253
254
255 @Override
256 public void setCssClasses(List<String> cssClasses) {
257 this.cssClasses = cssClasses;
258 }
259
260
261
262
263
264
265
266 public String getStyleClassesAsString() {
267 if (cssClasses != null) {
268 return StringUtils.join(cssClasses, " ");
269 }
270
271 return "";
272 }
273
274
275
276
277
278
279
280
281
282 public void setStyleClasses(String styleClasses) {
283 String[] classes = StringUtils.split(styleClasses);
284 this.cssClasses = Arrays.asList(classes);
285 }
286
287
288
289
290 @Override
291 public void addStyleClass(String styleClass) {
292 if (!cssClasses.contains(styleClass)) {
293 cssClasses.add(styleClass);
294 }
295 }
296
297
298
299
300 @Override
301 public void appendToStyle(String styleRules) {
302 if (style == null) {
303 style = "";
304 }
305 style = style + styleRules;
306 }
307
308
309
310
311 @Override
312 @BeanTagAttribute(name = "context", type = BeanTagAttribute.AttributeType.MAPBEAN)
313 public Map<String, Object> getContext() {
314 return this.context;
315 }
316
317
318
319
320 @Override
321 public void setContext(Map<String, Object> context) {
322 this.context = context;
323 }
324
325
326
327
328
329 @Override
330 public void pushObjectToContext(String objectName, Object object) {
331 if (this.context == null) {
332 this.context = new HashMap<String, Object>();
333 }
334
335 this.context.put(objectName, object);
336 }
337
338
339
340
341 @Override
342 @BeanTagAttribute(name = "propertyReplacers", type = BeanTagAttribute.AttributeType.LISTBEAN)
343 public List<PropertyReplacer> getPropertyReplacers() {
344 return this.propertyReplacers;
345 }
346
347
348
349
350 @Override
351 public void setPropertyReplacers(List<PropertyReplacer> propertyReplacers) {
352 this.propertyReplacers = propertyReplacers;
353 }
354
355
356 @Override
357 public <T> T copy() {
358 T copiedClass = null;
359 try {
360 copiedClass = (T)this.getClass().newInstance();
361 }
362 catch(Exception exception) {
363 throw new RuntimeException();
364 }
365
366 copyProperties(copiedClass);
367
368 return copiedClass;
369 }
370
371 protected <T> void copyProperties(T layoutManager) {
372 super.copyProperties(layoutManager);
373
374 LayoutManagerBase layoutManagerBaseCopy = (LayoutManagerBase) layoutManager;
375
376 layoutManagerBaseCopy.setId(this.getId());
377 layoutManagerBaseCopy.setTemplate(this.getTemplate());
378 layoutManagerBaseCopy.setTemplateName(this.getTemplateName());
379 layoutManagerBaseCopy.setStyle(this.getStyle());
380
381 layoutManagerBaseCopy.setContext(this.getContext());
382
383 if (libraryCssClasses != null) {
384 layoutManagerBaseCopy.setLibraryCssClasses(new ArrayList<String>(libraryCssClasses));
385 }
386
387 if (getCssClasses() != null) {
388 layoutManagerBaseCopy.setCssClasses(new ArrayList<String>(getCssClasses()));
389 }
390
391 if (getAdditionalCssClasses() != null) {
392 layoutManagerBaseCopy.setAdditionalCssClasses(new ArrayList<String>(getAdditionalCssClasses()));
393 }
394
395 if (getPropertyReplacers() != null) {
396 List<PropertyReplacer> propertyReplacersCopy = Lists.newArrayListWithExpectedSize(
397 getPropertyReplacers().size());
398 for (PropertyReplacer propertyReplacer : propertyReplacers) {
399 propertyReplacersCopy.add((PropertyReplacer) propertyReplacer.copy());
400 }
401
402 layoutManagerBaseCopy.setPropertyReplacers(propertyReplacersCopy);
403 }
404
405 layoutManagerBaseCopy.setComponentCode(this.getComponentCode());
406 layoutManagerBaseCopy.setNamespaceCode(this.getNamespaceCode());
407 }
408 }