Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
LayoutManagerBase |
|
| 1.2173913043478262;1.217 |
1 | /* | |
2 | * Copyright 2007 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 1.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl1.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.kuali.rice.krad.uif.layout; | |
17 | ||
18 | import org.apache.commons.lang.StringUtils; | |
19 | import org.kuali.rice.krad.uif.UifPropertyPaths; | |
20 | import org.kuali.rice.krad.uif.container.Container; | |
21 | import org.kuali.rice.krad.uif.container.View; | |
22 | import org.kuali.rice.krad.uif.core.Component; | |
23 | import org.kuali.rice.krad.uif.core.PropertyReplacer; | |
24 | import org.kuali.rice.krad.uif.core.ReferenceCopy; | |
25 | ||
26 | import java.util.ArrayList; | |
27 | import java.util.Arrays; | |
28 | import java.util.HashMap; | |
29 | import java.util.HashSet; | |
30 | import java.util.List; | |
31 | import java.util.Map; | |
32 | import java.util.Set; | |
33 | ||
34 | /** | |
35 | * Base class for all layout managers | |
36 | * | |
37 | * <p> | |
38 | * Provides general properties of all layout managers, such as the unique id, | |
39 | * rendering template, and style settings | |
40 | * </p> | |
41 | * | |
42 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
43 | */ | |
44 | public abstract class LayoutManagerBase implements LayoutManager { | |
45 | private static final long serialVersionUID = -2657663560459456814L; | |
46 | ||
47 | private String id; | |
48 | private String template; | |
49 | private String style; | |
50 | ||
51 | private List<String> styleClasses; | |
52 | ||
53 | @ReferenceCopy(newCollectionInstance=true) | |
54 | private Map<String, Object> context; | |
55 | ||
56 | private List<PropertyReplacer> propertyReplacers; | |
57 | ||
58 | 0 | public LayoutManagerBase() { |
59 | 0 | styleClasses = new ArrayList<String>(); |
60 | 0 | context = new HashMap<String, Object>(); |
61 | 0 | propertyReplacers = new ArrayList<PropertyReplacer>(); |
62 | 0 | } |
63 | ||
64 | /** | |
65 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#performInitialization(org.kuali.rice.krad.uif.container.View, | |
66 | * org.kuali.rice.krad.uif.container.Container) | |
67 | */ | |
68 | public void performInitialization(View view, Container container) { | |
69 | // set id of layout manager from container | |
70 | 0 | if (StringUtils.isBlank(id)) { |
71 | 0 | id = container.getId() + "_layout"; |
72 | } | |
73 | 0 | } |
74 | ||
75 | /** | |
76 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#performApplyModel(org.kuali.rice.krad.uif.container.View, | |
77 | * java.lang.Object, org.kuali.rice.krad.uif.container.Container) | |
78 | */ | |
79 | public void performApplyModel(View view, Object model, Container container) { | |
80 | ||
81 | 0 | } |
82 | ||
83 | /** | |
84 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#performFinalize(org.kuali.rice.krad.uif.container.View, | |
85 | * java.lang.Object, org.kuali.rice.krad.uif.container.Container) | |
86 | */ | |
87 | public void performFinalize(View view, Object model, Container container) { | |
88 | ||
89 | 0 | } |
90 | ||
91 | /** | |
92 | * Set of property names for the layout manager base for which on the | |
93 | * property value reference should be copied. Subclasses can override this | |
94 | * but should include a call to super | |
95 | * | |
96 | * @see org.kuali.rice.krad.uif.layout.LayoutManager. | |
97 | * getPropertiesForReferenceCopy() | |
98 | */ | |
99 | public Set<String> getPropertiesForReferenceCopy() { | |
100 | 0 | Set<String> refCopyProperties = new HashSet<String>(); |
101 | ||
102 | 0 | refCopyProperties.add(UifPropertyPaths.CONTEXT); |
103 | ||
104 | 0 | return refCopyProperties; |
105 | } | |
106 | ||
107 | /** | |
108 | * Default Impl | |
109 | * | |
110 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#getSupportedContainer() | |
111 | */ | |
112 | @Override | |
113 | public Class<? extends Container> getSupportedContainer() { | |
114 | 0 | return Container.class; |
115 | } | |
116 | ||
117 | /** | |
118 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#getNestedComponents() | |
119 | */ | |
120 | @Override | |
121 | public List<Component> getNestedComponents() { | |
122 | 0 | return new ArrayList<Component>(); |
123 | } | |
124 | ||
125 | /** | |
126 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#getId() | |
127 | */ | |
128 | public String getId() { | |
129 | 0 | return this.id; |
130 | } | |
131 | ||
132 | /** | |
133 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#setId(java.lang.String) | |
134 | */ | |
135 | public void setId(String id) { | |
136 | 0 | this.id = id; |
137 | 0 | } |
138 | ||
139 | /** | |
140 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#getTemplate() | |
141 | */ | |
142 | public String getTemplate() { | |
143 | 0 | return this.template; |
144 | } | |
145 | ||
146 | /** | |
147 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#setTemplate(java.lang.String) | |
148 | */ | |
149 | public void setTemplate(String template) { | |
150 | 0 | this.template = template; |
151 | 0 | } |
152 | ||
153 | /** | |
154 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#getStyle() | |
155 | */ | |
156 | public String getStyle() { | |
157 | 0 | return this.style; |
158 | } | |
159 | ||
160 | /** | |
161 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#setStyle(java.lang.String) | |
162 | */ | |
163 | public void setStyle(String style) { | |
164 | 0 | this.style = style; |
165 | 0 | } |
166 | ||
167 | /** | |
168 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#getStyleClasses() | |
169 | */ | |
170 | public List<String> getStyleClasses() { | |
171 | 0 | return this.styleClasses; |
172 | } | |
173 | ||
174 | /** | |
175 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#setStyleClasses(java.util.List) | |
176 | */ | |
177 | public void setStyleClasses(List<String> styleClasses) { | |
178 | 0 | this.styleClasses = styleClasses; |
179 | 0 | } |
180 | ||
181 | /** | |
182 | * Builds the HTML class attribute string by combining the styleClasses list | |
183 | * with a space delimiter | |
184 | * | |
185 | * @return String class attribute string | |
186 | */ | |
187 | public String getStyleClassesAsString() { | |
188 | 0 | if (styleClasses != null) { |
189 | 0 | return StringUtils.join(styleClasses, " "); |
190 | } | |
191 | ||
192 | 0 | return ""; |
193 | } | |
194 | ||
195 | /** | |
196 | * Sets the styleClasses list from the given string that has the classes | |
197 | * delimited by space. This is a convenience for configuration. If a child | |
198 | * bean needs to inherit the classes from the parent, it should configure as | |
199 | * a list and use merge="true" | |
200 | * | |
201 | * @param styleClasses | |
202 | */ | |
203 | public void setStyleClasses(String styleClasses) { | |
204 | 0 | String[] classes = StringUtils.split(styleClasses); |
205 | 0 | this.styleClasses = Arrays.asList(classes); |
206 | 0 | } |
207 | ||
208 | /** | |
209 | * This method adds a single style to the list of css style classes on this layoutManager | |
210 | * | |
211 | * @param style | |
212 | */ | |
213 | @Override | |
214 | public void addStyleClass(String styleClass){ | |
215 | 0 | if(!styleClasses.contains(styleClass)){ |
216 | 0 | styleClasses.add(styleClass); |
217 | } | |
218 | 0 | } |
219 | ||
220 | /** | |
221 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#getContext() | |
222 | */ | |
223 | public Map<String, Object> getContext() { | |
224 | 0 | return this.context; |
225 | } | |
226 | ||
227 | /** | |
228 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#setContext(java.util.Map) | |
229 | */ | |
230 | public void setContext(Map<String, Object> context) { | |
231 | 0 | this.context = context; |
232 | 0 | } |
233 | ||
234 | /** | |
235 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#pushObjectToContext(java.lang.String, | |
236 | * java.lang.Object) | |
237 | */ | |
238 | public void pushObjectToContext(String objectName, Object object) { | |
239 | 0 | if (this.context == null) { |
240 | 0 | this.context = new HashMap<String, Object>(); |
241 | } | |
242 | ||
243 | 0 | this.context.put(objectName, object); |
244 | 0 | } |
245 | ||
246 | /** | |
247 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#getPropertyReplacers() | |
248 | */ | |
249 | public List<PropertyReplacer> getPropertyReplacers() { | |
250 | 0 | return this.propertyReplacers; |
251 | } | |
252 | ||
253 | /** | |
254 | * @see org.kuali.rice.krad.uif.layout.LayoutManager#setPropertyReplacers(java.util.List) | |
255 | */ | |
256 | public void setPropertyReplacers(List<PropertyReplacer> propertyReplacers) { | |
257 | 0 | this.propertyReplacers = propertyReplacers; |
258 | 0 | } |
259 | ||
260 | } |