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.field;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
020 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
021 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
022 import org.kuali.rice.krad.uif.UifConstants;
023 import org.kuali.rice.krad.uif.component.Component;
024 import org.kuali.rice.krad.uif.container.Group;
025 import org.kuali.rice.krad.uif.view.View;
026
027 import java.util.List;
028
029 /**
030 * Field that contains a nested <code>Group</code>. Can be used to group
031 * together fields by providing a group without header and footer, or simply to
032 * nest full groups. The items getter/setter provided is for convenience and
033 * will set the items <code>List</code> in the nested <code>Group</code>
034 *
035 * @author Kuali Rice Team (rice.collab@kuali.org)
036 */
037 @BeanTags({@BeanTag(name = "fieldGroup-bean", parent = "Uif-FieldGroupBase"),
038 @BeanTag(name = "verticalFieldGroup-bean", parent = "Uif-VerticalFieldGroup"),
039 @BeanTag(name = "horizontalFieldGroup-bean", parent = "Uif-HorizontalFieldGroup")})
040 public class FieldGroup extends FieldBase {
041 private static final long serialVersionUID = -505654043702442196L;
042
043 private Group group;
044
045 public FieldGroup() {
046 super();
047 }
048
049 /**
050 * The following initialization is performed:
051 *
052 * <ul>
053 * <li>Set the align on group if empty and the align has been set on the field</li>
054 * </ul>
055 *
056 * @see org.kuali.rice.krad.uif.component.ComponentBase#performInitialization(org.kuali.rice.krad.uif.view.View,
057 * java.lang.Object)
058 */
059 @Override
060 public void performInitialization(View view, Object model) {
061 super.performInitialization(view, model);
062
063 if (StringUtils.isNotBlank(getAlign()) && group != null) {
064 group.setAlign(getAlign());
065 }
066 }
067
068 @Override
069 public void performFinalize(View view, Object model, Component parent) {
070 super.performFinalize(view, model, parent);
071
072 this.addDataAttribute("parent", parent.getId());
073 if (group != null) {
074 this.addDataAttribute("group", group.getId());
075 }
076
077 setNestedComponentIdAndSuffix(getFieldLabel(), UifConstants.IdSuffixes.LABEL);
078
079 if (this.getFieldLabel() != null) {
080 this.getFieldLabel().setLabelForComponentId(this.getId() + UifConstants.IdSuffixes.FIELDSET);
081 }
082 }
083
084 /**
085 * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
086 */
087 @Override
088 public List<Component> getComponentsForLifecycle() {
089 List<Component> components = super.getComponentsForLifecycle();
090
091 components.add(group);
092
093 return components;
094 }
095
096 /**
097 * <code>Group</code> instance that is contained within in the field
098 *
099 * @return Group instance
100 */
101 @BeanTagAttribute(name = "group", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
102 public Group getGroup() {
103 return this.group;
104 }
105
106 /**
107 * Setter for the field's nested group
108 *
109 * @param group
110 */
111 public void setGroup(Group group) {
112 this.group = group;
113 }
114
115 /**
116 * List of <code>Component</code> instances contained in the nested group
117 *
118 * <p>
119 * Convenience method for configuration to get the items List from the
120 * field's nested group
121 * </p>
122 *
123 * @return List<? extends Component> items
124 */
125 @BeanTagAttribute(name = "items", type = BeanTagAttribute.AttributeType.LISTBEAN)
126 public List<? extends Component> getItems() {
127 if (group != null) {
128 return group.getItems();
129 }
130
131 return null;
132 }
133
134 /**
135 * Setter for the field's nested group items
136 *
137 * <p>
138 * Convenience method for configuration to set the items List for the
139 * field's nested group
140 * </p>
141 *
142 * @param items
143 */
144 public void setItems(List<? extends Component> items) {
145 if (group != null) {
146 group.setItems(items);
147 }
148 }
149
150 }