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