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.uif.UifPropertyPaths;
20  import org.kuali.rice.krad.uif.container.Container;
21  import org.kuali.rice.krad.uif.view.View;
22  import org.kuali.rice.krad.uif.component.Component;
23  import org.kuali.rice.krad.uif.component.ConfigurableBase;
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 ConfigurableBase implements LayoutManager {
46  	private static final long serialVersionUID = -2657663560459456814L;
47  
48  	private String id;
49  	private String template;
50  	private String style;
51  
52  	private List<String> styleClasses;
53  
54  	@ReferenceCopy(newCollectionInstance=true)
55  	private Map<String, Object> context;
56  
57  	private List<PropertyReplacer> propertyReplacers;
58  
59  	public LayoutManagerBase() {
60          super();
61  
62  		styleClasses = new ArrayList<String>();
63  		context = new HashMap<String, Object>();
64  		propertyReplacers = new ArrayList<PropertyReplacer>();
65  	}
66  
67  	/**
68  	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#performInitialization(org.kuali.rice.krad.uif.view.View,
69  	 *      java.lang.Object, org.kuali.rice.krad.uif.container.Container)
70  	 */
71  	public void performInitialization(View view, Object model, Container container) {
72  		// set id of layout manager from container
73  		if (StringUtils.isBlank(id)) {
74  			id = container.getId() + "_layout";
75  		}
76  	}
77  
78  	/**
79  	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#performApplyModel(org.kuali.rice.krad.uif.view.View,
80  	 *      java.lang.Object, org.kuali.rice.krad.uif.container.Container)
81  	 */
82  	public void performApplyModel(View view, Object model, Container container) {
83  
84  	}
85  
86  	/**
87  	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#performFinalize(org.kuali.rice.krad.uif.view.View,
88  	 *      java.lang.Object, org.kuali.rice.krad.uif.container.Container)
89  	 */
90  	public void performFinalize(View view, Object model, Container container) {
91  
92  	}
93  
94  	/**
95  	 * Set of property names for the layout manager base for which on the
96  	 * property value reference should be copied. Subclasses can override this
97  	 * but should include a call to super
98  	 * 
99  	 * @see org.kuali.rice.krad.uif.layout.LayoutManager.
100 	 *      getPropertiesForReferenceCopy()
101 	 */
102 	public Set<String> getPropertiesForReferenceCopy() {
103 		Set<String> refCopyProperties = new HashSet<String>();
104 
105 		refCopyProperties.add(UifPropertyPaths.CONTEXT);
106 
107 		return refCopyProperties;
108 	}
109 
110 	/**
111 	 * Default Impl
112 	 * 
113 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getSupportedContainer()
114 	 */
115 	@Override
116 	public Class<? extends Container> getSupportedContainer() {
117 		return Container.class;
118 	}
119 
120 	/**
121 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getComponentsForLifecycle()
122 	 */
123 	public List<Component> getComponentsForLifecycle() {
124 		return new ArrayList<Component>();
125 	}
126 
127     /**
128      * @see org.kuali.rice.krad.uif.layout.LayoutManager#getComponentPrototypes()
129      */
130     public List<Component> getComponentPrototypes() {
131         List<Component> components = new ArrayList<Component>();
132 
133         return components;
134     }
135 
136 	/**
137 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getId()
138 	 */
139 	public String getId() {
140 		return this.id;
141 	}
142 
143 	/**
144 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#setId(java.lang.String)
145 	 */
146 	public void setId(String id) {
147 		this.id = id;
148 	}
149 
150 	/**
151 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getTemplate()
152 	 */
153 	public String getTemplate() {
154 		return this.template;
155 	}
156 
157 	/**
158 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#setTemplate(java.lang.String)
159 	 */
160 	public void setTemplate(String template) {
161 		this.template = template;
162 	}
163 
164 	/**
165 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getStyle()
166 	 */
167 	public String getStyle() {
168 		return this.style;
169 	}
170 
171 	/**
172 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#setStyle(java.lang.String)
173 	 */
174 	public void setStyle(String style) {
175 		this.style = style;
176 	}
177 
178 	/**
179 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getStyleClasses()
180 	 */
181 	public List<String> getStyleClasses() {
182 		return this.styleClasses;
183 	}
184 
185 	/**
186 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#setStyleClasses(java.util.List)
187 	 */
188 	public void setStyleClasses(List<String> styleClasses) {
189 		this.styleClasses = styleClasses;
190 	}
191 
192 	/**
193 	 * Builds the HTML class attribute string by combining the styleClasses list
194 	 * with a space delimiter
195 	 * 
196 	 * @return String class attribute string
197 	 */
198 	public String getStyleClassesAsString() {
199 		if (styleClasses != null) {
200 			return StringUtils.join(styleClasses, " ");
201 		}
202 
203 		return "";
204 	}
205 
206 	/**
207 	 * Sets the styleClasses list from the given string that has the classes
208 	 * delimited by space. This is a convenience for configuration. If a child
209 	 * bean needs to inherit the classes from the parent, it should configure as
210 	 * a list and use merge="true"
211 	 * 
212 	 * @param styleClasses
213 	 */
214 	public void setStyleClasses(String styleClasses) {
215 		String[] classes = StringUtils.split(styleClasses);
216 		this.styleClasses = Arrays.asList(classes);
217 	}
218 
219 	/**
220 	 * This method adds a single style to the list of css style classes on this layoutManager
221 	 * 
222 	 * @param style
223 	 */
224 	@Override
225 	public void addStyleClass(String styleClass){
226 		if(!styleClasses.contains(styleClass)){
227 			styleClasses.add(styleClass);
228 		}
229 	}
230 
231 	/**
232 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getContext()
233 	 */
234 	public Map<String, Object> getContext() {
235 		return this.context;
236 	}
237 
238 	/**
239 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#setContext(java.util.Map)
240 	 */
241 	public void setContext(Map<String, Object> context) {
242 		this.context = context;
243 	}
244 
245 	/**
246 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#pushObjectToContext(java.lang.String,
247 	 *      java.lang.Object)
248 	 */
249 	public void pushObjectToContext(String objectName, Object object) {
250 		if (this.context == null) {
251 			this.context = new HashMap<String, Object>();
252 		}
253 
254 		this.context.put(objectName, object);
255 	}
256 
257 	/**
258 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#getPropertyReplacers()
259 	 */
260 	public List<PropertyReplacer> getPropertyReplacers() {
261 		return this.propertyReplacers;
262 	}
263 
264 	/**
265 	 * @see org.kuali.rice.krad.uif.layout.LayoutManager#setPropertyReplacers(java.util.List)
266 	 */
267 	public void setPropertyReplacers(List<PropertyReplacer> propertyReplacers) {
268 		this.propertyReplacers = propertyReplacers;
269 	}
270 
271 }