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