| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Group |
|
| 2.0;2 |
| 1 | /* | |
| 2 | * Copyright 2007 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community License, Version 1.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/ecl1.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.container; | |
| 17 | ||
| 18 | import org.apache.commons.lang.StringUtils; | |
| 19 | import org.kuali.rice.krad.uif.core.Component; | |
| 20 | import org.kuali.rice.krad.uif.core.DataBinding; | |
| 21 | import org.kuali.rice.krad.uif.field.AttributeField; | |
| 22 | import org.kuali.rice.krad.uif.field.Field; | |
| 23 | import org.kuali.rice.krad.uif.field.GroupField; | |
| 24 | import org.kuali.rice.krad.uif.widget.Accordion; | |
| 25 | ||
| 26 | import java.util.ArrayList; | |
| 27 | import java.util.HashSet; | |
| 28 | import java.util.List; | |
| 29 | import java.util.Set; | |
| 30 | ||
| 31 | /** | |
| 32 | * Container that holds a list of <code>Field</code> or other <code>Group</code> | |
| 33 | * instances | |
| 34 | * | |
| 35 | * <p> | |
| 36 | * Groups can exist at different levels of the <code>View</code>, providing | |
| 37 | * conceptual groupings such as the page, section, and group. In addition, other | |
| 38 | * group types can be created to add behavior like collection support | |
| 39 | * </p> | |
| 40 | * | |
| 41 | * <p> | |
| 42 | * <code>Group</code> implementation has properties for defaulting the binding | |
| 43 | * information (such as the parent object path and a binding prefix) for the | |
| 44 | * fields it contains. During the phase these properties (if given) are set on | |
| 45 | * the fields contained in the <code>Group</code> that implement | |
| 46 | * <code>DataBinding</code>, unless they have already been set on the field. | |
| 47 | * </p> | |
| 48 | * | |
| 49 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 50 | */ | |
| 51 | public class Group extends ContainerBase { | |
| 52 | private static final long serialVersionUID = 7953641325356535509L; | |
| 53 | ||
| 54 | private String fieldBindByNamePrefix; | |
| 55 | private String fieldBindingObjectPath; | |
| 56 | ||
| 57 | private Accordion accordion; | |
| 58 | ||
| 59 | private List<? extends Component> items; | |
| 60 | ||
| 61 | /** | |
| 62 | * Default Constructor | |
| 63 | */ | |
| 64 | 0 | public Group() { |
| 65 | 0 | items = new ArrayList<Component>(); |
| 66 | 0 | } |
| 67 | ||
| 68 | /** | |
| 69 | * The following actions are performed: | |
| 70 | * | |
| 71 | * <ul> | |
| 72 | * <li>Sets the bindByNamePrefix if blank on any AttributeField and | |
| 73 | * GroupField instances within the items List</li> | |
| 74 | * </ul> | |
| 75 | * | |
| 76 | * @see org.kuali.rice.krad.uif.core.ComponentBase#performInitialization(org.kuali.rice.krad.uif.container.View) | |
| 77 | */ | |
| 78 | @Override | |
| 79 | public void performInitialization(View view) { | |
| 80 | 0 | super.performInitialization(view); |
| 81 | ||
| 82 | 0 | for (Component component : getItems()) { |
| 83 | // append group's field bind by name prefix (if set) to each | |
| 84 | // attribute field's binding prefix | |
| 85 | 0 | if (component instanceof DataBinding) { |
| 86 | 0 | DataBinding field = (DataBinding) component; |
| 87 | ||
| 88 | 0 | if (StringUtils.isNotBlank(getFieldBindByNamePrefix())) { |
| 89 | 0 | String bindByNamePrefixToSet = getFieldBindByNamePrefix(); |
| 90 | ||
| 91 | 0 | if (StringUtils.isNotBlank(field.getBindingInfo().getBindByNamePrefix())) { |
| 92 | 0 | bindByNamePrefixToSet += "." + field.getBindingInfo().getBindByNamePrefix(); |
| 93 | } | |
| 94 | 0 | field.getBindingInfo().setBindByNamePrefix(bindByNamePrefixToSet); |
| 95 | } | |
| 96 | ||
| 97 | 0 | if (StringUtils.isNotBlank(fieldBindingObjectPath) && |
| 98 | StringUtils.isBlank(field.getBindingInfo().getBindingObjectPath())) { | |
| 99 | 0 | field.getBindingInfo().setBindingObjectPath(fieldBindingObjectPath); |
| 100 | } | |
| 101 | 0 | } |
| 102 | // set on GroupField's group to recursively set AttributeFields | |
| 103 | 0 | else if (component instanceof GroupField) { |
| 104 | 0 | GroupField groupField = (GroupField) component; |
| 105 | ||
| 106 | 0 | if (groupField.getGroup() != null) { |
| 107 | 0 | if (StringUtils.isBlank(groupField.getGroup().getFieldBindByNamePrefix())) { |
| 108 | 0 | groupField.getGroup().setFieldBindByNamePrefix(fieldBindByNamePrefix); |
| 109 | } | |
| 110 | 0 | if (StringUtils.isBlank(groupField.getGroup().getFieldBindingObjectPath())) { |
| 111 | 0 | groupField.getGroup().setFieldBindingObjectPath(fieldBindingObjectPath); |
| 112 | } | |
| 113 | } | |
| 114 | 0 | } else if (component instanceof Group) { |
| 115 | 0 | Group subGroup = (Group) component; |
| 116 | 0 | if (StringUtils.isNotBlank(getFieldBindByNamePrefix())) { |
| 117 | 0 | if (StringUtils.isNotBlank(subGroup.getFieldBindByNamePrefix())) { |
| 118 | 0 | subGroup.setFieldBindByNamePrefix( |
| 119 | getFieldBindByNamePrefix() + "." + subGroup.getFieldBindByNamePrefix()); | |
| 120 | } else { | |
| 121 | 0 | subGroup.setFieldBindByNamePrefix(getFieldBindByNamePrefix()); |
| 122 | } | |
| 123 | } | |
| 124 | 0 | } |
| 125 | } | |
| 126 | 0 | } |
| 127 | ||
| 128 | /** | |
| 129 | * @see org.kuali.rice.krad.uif.core.ComponentBase#getNestedComponents() | |
| 130 | */ | |
| 131 | @Override | |
| 132 | public List<Component> getNestedComponents() { | |
| 133 | 0 | List<Component> components = super.getNestedComponents(); |
| 134 | ||
| 135 | 0 | components.add(accordion); |
| 136 | ||
| 137 | 0 | return components; |
| 138 | } | |
| 139 | ||
| 140 | /** | |
| 141 | * @see org.kuali.rice.krad.web.view.container.ContainerBase#getSupportedComponents() | |
| 142 | */ | |
| 143 | @Override | |
| 144 | public Set<Class<? extends Component>> getSupportedComponents() { | |
| 145 | 0 | Set<Class<? extends Component>> supportedComponents = new HashSet<Class<? extends Component>>(); |
| 146 | 0 | supportedComponents.add(Field.class); |
| 147 | 0 | supportedComponents.add(Group.class); |
| 148 | ||
| 149 | 0 | return supportedComponents; |
| 150 | } | |
| 151 | ||
| 152 | /** | |
| 153 | * @see org.kuali.rice.krad.uif.core.Component#getComponentTypeName() | |
| 154 | */ | |
| 155 | @Override | |
| 156 | public String getComponentTypeName() { | |
| 157 | 0 | return "group"; |
| 158 | } | |
| 159 | ||
| 160 | /** | |
| 161 | * Binding prefix string to set on each of the groups | |
| 162 | * <code>AttributeField</code> instances | |
| 163 | * <p> | |
| 164 | * As opposed to setting the bindingPrefix on each attribute field instance, | |
| 165 | * it can be set here for the group. During initialize the string will then | |
| 166 | * be set on each attribute field instance if the bindingPrefix is blank and | |
| 167 | * not a form field | |
| 168 | * </p> | |
| 169 | * | |
| 170 | * @return String binding prefix to set | |
| 171 | * @see org.kuali.rice.krad.uif.field.AttributeField#getBindByNamePrefix | |
| 172 | */ | |
| 173 | public String getFieldBindByNamePrefix() { | |
| 174 | 0 | return this.fieldBindByNamePrefix; |
| 175 | } | |
| 176 | ||
| 177 | /** | |
| 178 | * Setter for the field binding prefix | |
| 179 | * | |
| 180 | * @param fieldBindByNamePrefix | |
| 181 | */ | |
| 182 | public void setFieldBindByNamePrefix(String fieldBindByNamePrefix) { | |
| 183 | 0 | this.fieldBindByNamePrefix = fieldBindByNamePrefix; |
| 184 | 0 | } |
| 185 | ||
| 186 | /** | |
| 187 | * Object binding path to set on each of the group's | |
| 188 | * <code>AttributeField</code> instances | |
| 189 | * | |
| 190 | * <p> | |
| 191 | * When the attributes of the group belong to a object whose path is | |
| 192 | * different from the default then this property can be given to set each of | |
| 193 | * the attributes instead of setting the model path on each one. The object | |
| 194 | * path can be overridden at the attribute level. The object path is set to | |
| 195 | * the fieldBindingObjectPath during the initialize phase. | |
| 196 | * </p> | |
| 197 | * | |
| 198 | * @return String model path to set | |
| 199 | * @see org.kuali.rice.krad.uif.BindingInfo.getBindingObjectPath() | |
| 200 | */ | |
| 201 | public String getFieldBindingObjectPath() { | |
| 202 | 0 | return this.fieldBindingObjectPath; |
| 203 | } | |
| 204 | ||
| 205 | /** | |
| 206 | * Setter for the field object binding path | |
| 207 | * | |
| 208 | * @param fieldBindingObjectPath | |
| 209 | */ | |
| 210 | public void setFieldBindingObjectPath(String fieldBindingObjectPath) { | |
| 211 | 0 | this.fieldBindingObjectPath = fieldBindingObjectPath; |
| 212 | 0 | } |
| 213 | ||
| 214 | /** | |
| 215 | * Accordion widget that provides collapse/expand functionality for the | |
| 216 | * group | |
| 217 | * | |
| 218 | * @return Accordion instance | |
| 219 | */ | |
| 220 | public Accordion getAccordion() { | |
| 221 | 0 | return this.accordion; |
| 222 | } | |
| 223 | ||
| 224 | /** | |
| 225 | * Setter for the group's accordion instance | |
| 226 | * | |
| 227 | * @param accordion | |
| 228 | */ | |
| 229 | public void setAccordion(Accordion accordion) { | |
| 230 | 0 | this.accordion = accordion; |
| 231 | 0 | } |
| 232 | ||
| 233 | /** | |
| 234 | * @see org.kuali.rice.krad.uif.container.ContainerBase#getItems() | |
| 235 | */ | |
| 236 | @Override | |
| 237 | public List<? extends Component> getItems() { | |
| 238 | 0 | return this.items; |
| 239 | } | |
| 240 | ||
| 241 | /** | |
| 242 | * Setter for the Group's list of components | |
| 243 | * | |
| 244 | * @param items | |
| 245 | */ | |
| 246 | @Override | |
| 247 | public void setItems(List<? extends Component> items) { | |
| 248 | 0 | this.items = items; |
| 249 | 0 | } |
| 250 | ||
| 251 | } |