001    /**
002     * Copyright 2005-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.krad.uif.layout;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
020    import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase;
021    import org.kuali.rice.krad.uif.UifPropertyPaths;
022    import org.kuali.rice.krad.uif.container.Container;
023    import org.kuali.rice.krad.uif.view.View;
024    import org.kuali.rice.krad.uif.component.Component;
025    import org.kuali.rice.krad.uif.component.PropertyReplacer;
026    import org.kuali.rice.krad.uif.component.ReferenceCopy;
027    
028    import java.util.ArrayList;
029    import java.util.Arrays;
030    import java.util.HashMap;
031    import java.util.HashSet;
032    import java.util.List;
033    import java.util.Map;
034    import java.util.Set;
035    
036    /**
037     * Base class for all layout managers
038     *
039     * <p>
040     * Provides general properties of all layout managers, such as the unique id,
041     * rendering template, and style settings
042     * </p>
043     *
044     * @author Kuali Rice Team (rice.collab@kuali.org)
045     */
046    public abstract class LayoutManagerBase extends UifDictionaryBeanBase implements LayoutManager {
047            private static final long serialVersionUID = -2657663560459456814L;
048    
049            private String id;
050            private String template;
051        private String templateName;
052    
053            private String style;
054            private List<String> cssClasses;
055    
056            @ReferenceCopy(newCollectionInstance=true)
057            private Map<String, Object> context;
058    
059            private List<PropertyReplacer> propertyReplacers;
060    
061            public LayoutManagerBase() {
062            super();
063    
064                    cssClasses = new ArrayList<String>();
065                    context = new HashMap<String, Object>();
066                    propertyReplacers = new ArrayList<PropertyReplacer>();
067            }
068    
069            /**
070             * @see org.kuali.rice.krad.uif.layout.LayoutManager#performInitialization(org.kuali.rice.krad.uif.view.View,
071             *      java.lang.Object, org.kuali.rice.krad.uif.container.Container)
072             */
073        @Override
074        public void performInitialization(View view, Object model, Container container) {
075                    // set id of layout manager from container
076                    if (StringUtils.isBlank(id)) {
077                            id = container.getId() + "_layout";
078                    }
079            }
080    
081            /**
082             * @see org.kuali.rice.krad.uif.layout.LayoutManager#performApplyModel(org.kuali.rice.krad.uif.view.View,
083             *      java.lang.Object, org.kuali.rice.krad.uif.container.Container)
084             */
085        @Override
086        public void performApplyModel(View view, Object model, Container container) {
087    
088            }
089    
090            /**
091             * @see org.kuali.rice.krad.uif.layout.LayoutManager#performFinalize(org.kuali.rice.krad.uif.view.View,
092             *      java.lang.Object, org.kuali.rice.krad.uif.container.Container)
093             */
094        @Override
095        public void performFinalize(View view, Object model, Container container) {
096    
097            }
098    
099            /**
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    }