View Javadoc

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