View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.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/ecl2.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.datadictionary.uif.UifDictionaryBeanBase;
20  import org.kuali.rice.krad.uif.UifPropertyPaths;
21  import org.kuali.rice.krad.uif.container.Container;
22  import org.kuali.rice.krad.uif.view.View;
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  
27  import java.util.ArrayList;
28  import java.util.Arrays;
29  import java.util.HashMap;
30  import java.util.HashSet;
31  import java.util.List;
32  import java.util.Map;
33  import java.util.Set;
34  
35  /**
36   * Base class for all layout managers
37   * 
38   * <p>
39   * Provides general properties of all layout managers, such as the unique id,
40   * rendering template, and style settings
41   * </p>
42   * 
43   * @author Kuali Rice Team (rice.collab@kuali.org)
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> cssClasses;
54  
55  	@ReferenceCopy(newCollectionInstance=true)
56  	private Map<String, Object> context;
57  
58  	private List<PropertyReplacer> propertyReplacers;
59  
60  	public LayoutManagerBase() {
61          super();
62  
63  		cssClasses = new ArrayList<String>();
64  		context = new HashMap<String, Object>();
65  		propertyReplacers = new ArrayList<PropertyReplacer>();
66  	}
67  
68  	/**
69  	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#performInitialization(org.kuali.rice.krad.uif.view.View,
70  	 *      java.lang.Object, org.kuali.rice.krad.uif.container.Container)
71  	 */
72      @Override
73      public void performInitialization(View view, Object model, Container container) {
74  		// set id of layout manager from container
75  		if (StringUtils.isBlank(id)) {
76  			id = container.getId() + "_layout";
77  		}
78  	}
79  
80  	/**
81  	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#performApplyModel(org.kuali.rice.krad.uif.view.View,
82  	 *      java.lang.Object, org.kuali.rice.krad.uif.container.Container)
83  	 */
84      @Override
85      public void performApplyModel(View view, Object model, Container container) {
86  
87  	}
88  
89  	/**
90  	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#performFinalize(org.kuali.rice.krad.uif.view.View,
91  	 *      java.lang.Object, org.kuali.rice.krad.uif.container.Container)
92  	 */
93      @Override
94      public void performFinalize(View view, Object model, Container container) {
95  
96  	}
97  
98  	/**
99  	 * Set of property names for the layout manager base for which on the
100 	 * property value reference should be copied. Subclasses can override this
101 	 * but should include a call to super
102 	 * 
103 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getPropertiesForReferenceCopy()
104 	 */
105     @Override
106     public Set<String> getPropertiesForReferenceCopy() {
107 		Set<String> refCopyProperties = new HashSet<String>();
108 
109 		refCopyProperties.add(UifPropertyPaths.CONTEXT);
110 
111 		return refCopyProperties;
112 	}
113 
114 	/**
115 	 * Default Impl
116 	 * 
117 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getSupportedContainer()
118 	 */
119 	@Override
120 	public Class<? extends Container> getSupportedContainer() {
121 		return Container.class;
122 	}
123 
124 	/**
125 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getComponentsForLifecycle()
126 	 */
127     @Override
128     public List<Component> getComponentsForLifecycle() {
129 		return new ArrayList<Component>();
130 	}
131 
132     /**
133      * @see org.kuali.rice.krad.uif.layout.LayoutManager#getComponentPrototypes()
134      */
135     @Override
136     public List<Component> getComponentPrototypes() {
137         List<Component> components = new ArrayList<Component>();
138 
139         return components;
140     }
141 
142 	/**
143 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getId()
144 	 */
145     @Override
146     public String getId() {
147 		return this.id;
148 	}
149 
150 	/**
151 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#setId(java.lang.String)
152 	 */
153     @Override
154     public void setId(String id) {
155 		this.id = id;
156 	}
157 
158 	/**
159 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getTemplate()
160 	 */
161     @Override
162     public String getTemplate() {
163 		return this.template;
164 	}
165 
166 	/**
167 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#setTemplate(java.lang.String)
168 	 */
169     @Override
170     public void setTemplate(String template) {
171 		this.template = template;
172 	}
173 
174     /**
175      * The name of the layout manager template
176      *
177      * @return template name
178      * @see #getTemplate()
179      */
180     public String getTemplateName() {
181         return templateName;
182     }
183 
184     /**
185      * Setter for the layout managers template name
186      *
187      * @param templateName
188      */
189     public void setTemplateName(String templateName) {
190         this.templateName = templateName;
191     }
192 
193     /**
194 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getStyle()
195 	 */
196     @Override
197     public String getStyle() {
198 		return this.style;
199 	}
200 
201 	/**
202 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#setStyle(java.lang.String)
203 	 */
204     @Override
205     public void setStyle(String style) {
206 		this.style = style;
207 	}
208 
209 	/**
210 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getCssClasses()
211 	 */
212     @Override
213     public List<String> getCssClasses() {
214 		return this.cssClasses;
215 	}
216 
217 	/**
218 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#setCssClasses(java.util.List)
219 	 */
220     @Override
221 	public void setCssClasses(List<String> cssClasses) {
222 		this.cssClasses = cssClasses;
223 	}
224 
225 	/**
226 	 * Builds the HTML class attribute string by combining the styleClasses list
227 	 * with a space delimiter
228 	 * 
229 	 * @return String class attribute string
230 	 */
231 	public String getStyleClassesAsString() {
232 		if (cssClasses != null) {
233 			return StringUtils.join(cssClasses, " ");
234 		}
235 
236 		return "";
237 	}
238 
239 	/**
240 	 * Sets the styleClasses list from the given string that has the classes
241 	 * delimited by space. This is a convenience for configuration. If a child
242 	 * bean needs to inherit the classes from the parent, it should configure as
243 	 * a list and use merge="true"
244 	 * 
245 	 * @param styleClasses
246 	 */
247 	public void setStyleClasses(String styleClasses) {
248 		String[] classes = StringUtils.split(styleClasses);
249 		this.cssClasses = Arrays.asList(classes);
250 	}
251 
252 	/**
253 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#addStyleClass(java.lang.String)
254 	 */
255 	@Override
256 	public void addStyleClass(String styleClass){
257 		if(!cssClasses.contains(styleClass)){
258 			cssClasses.add(styleClass);
259 		}
260 	}
261 
262     /**
263      * @see org.kuali.rice.krad.uif.layout.LayoutManager#appendToStyle(java.lang.String)
264      */
265     @Override
266     public void appendToStyle(String styleRules) {
267         if (style == null) {
268             style = "";
269         }
270         style = style + styleRules;
271     }
272 
273     /**
274 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getContext()
275 	 */
276     @Override
277     public Map<String, Object> getContext() {
278 		return this.context;
279 	}
280 
281 	/**
282 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#setContext(java.util.Map)
283 	 */
284     @Override
285     public void setContext(Map<String, Object> context) {
286 		this.context = context;
287 	}
288 
289 	/**
290 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#pushObjectToContext(java.lang.String,
291 	 *      java.lang.Object)
292 	 */
293     @Override
294     public void pushObjectToContext(String objectName, Object object) {
295 		if (this.context == null) {
296 			this.context = new HashMap<String, Object>();
297 		}
298 
299 		this.context.put(objectName, object);
300 	}
301 
302 	/**
303 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getPropertyReplacers()
304 	 */
305     @Override
306     public List<PropertyReplacer> getPropertyReplacers() {
307 		return this.propertyReplacers;
308 	}
309 
310 	/**
311 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#setPropertyReplacers(java.util.List)
312 	 */
313     @Override
314     public void setPropertyReplacers(List<PropertyReplacer> propertyReplacers) {
315 		this.propertyReplacers = propertyReplacers;
316 	}
317 
318 }