001 /** 002 * Copyright 2005-2014 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.uif.UifPropertyPaths; 020 import org.kuali.rice.krad.uif.container.Container; 021 import org.kuali.rice.krad.uif.view.View; 022 import org.kuali.rice.krad.uif.component.Component; 023 import org.kuali.rice.krad.uif.component.ConfigurableBase; 024 import org.kuali.rice.krad.uif.component.PropertyReplacer; 025 import org.kuali.rice.krad.uif.component.ReferenceCopy; 026 027 import java.util.ArrayList; 028 import java.util.Arrays; 029 import java.util.HashMap; 030 import java.util.HashSet; 031 import java.util.List; 032 import java.util.Map; 033 import java.util.Set; 034 035 /** 036 * Base class for all layout managers 037 * 038 * <p> 039 * Provides general properties of all layout managers, such as the unique id, 040 * rendering template, and style settings 041 * </p> 042 * 043 * @author Kuali Rice Team (rice.collab@kuali.org) 044 */ 045 public abstract class LayoutManagerBase extends ConfigurableBase implements LayoutManager { 046 private static final long serialVersionUID = -2657663560459456814L; 047 048 private String id; 049 private String template; 050 private String style; 051 052 private List<String> styleClasses; 053 054 @ReferenceCopy(newCollectionInstance=true) 055 private Map<String, Object> context; 056 057 private List<PropertyReplacer> propertyReplacers; 058 059 public LayoutManagerBase() { 060 super(); 061 062 styleClasses = new ArrayList<String>(); 063 context = new HashMap<String, Object>(); 064 propertyReplacers = new ArrayList<PropertyReplacer>(); 065 } 066 067 /** 068 * @see org.kuali.rice.krad.uif.layout.LayoutManager#performInitialization(org.kuali.rice.krad.uif.view.View, 069 * java.lang.Object, org.kuali.rice.krad.uif.container.Container) 070 */ 071 public void performInitialization(View view, Object model, Container container) { 072 // set id of layout manager from container 073 if (StringUtils.isBlank(id)) { 074 id = container.getId() + "_layout"; 075 } 076 } 077 078 /** 079 * @see org.kuali.rice.krad.uif.layout.LayoutManager#performApplyModel(org.kuali.rice.krad.uif.view.View, 080 * java.lang.Object, org.kuali.rice.krad.uif.container.Container) 081 */ 082 public void performApplyModel(View view, Object model, Container container) { 083 084 } 085 086 /** 087 * @see org.kuali.rice.krad.uif.layout.LayoutManager#performFinalize(org.kuali.rice.krad.uif.view.View, 088 * java.lang.Object, org.kuali.rice.krad.uif.container.Container) 089 */ 090 public void performFinalize(View view, Object model, Container container) { 091 092 } 093 094 /** 095 * Set of property names for the layout manager base for which on the 096 * property value reference should be copied. Subclasses can override this 097 * but should include a call to super 098 * 099 * @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 }