View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.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/ecl2.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.field;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21  import org.kuali.rice.krad.datadictionary.parse.BeanTags;
22  import org.kuali.rice.krad.uif.UifConstants;
23  import org.kuali.rice.krad.uif.component.Component;
24  import org.kuali.rice.krad.uif.container.Group;
25  import org.kuali.rice.krad.uif.view.View;
26  
27  import java.util.List;
28  
29  /**
30   * Field that contains a nested <code>Group</code>. Can be used to group
31   * together fields by providing a group without header and footer, or simply to
32   * nest full groups. The items getter/setter provided is for convenience and
33   * will set the items <code>List</code> in the nested <code>Group</code>
34   *
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  @BeanTags({@BeanTag(name = "fieldGroup-bean", parent = "Uif-FieldGroupBase"),
38          @BeanTag(name = "verticalFieldGroup-bean", parent = "Uif-VerticalFieldGroup"),
39          @BeanTag(name = "horizontalFieldGroup-bean", parent = "Uif-HorizontalFieldGroup")})
40  public class FieldGroup extends FieldBase {
41      private static final long serialVersionUID = -505654043702442196L;
42  
43      private Group group;
44  
45      public FieldGroup() {
46          super();
47      }
48  
49      /**
50       * The following initialization is performed:
51       *
52       * <ul>
53       * <li>Set the align on group if empty and the align has been set on the field</li>
54       * </ul>
55       *
56       * @see org.kuali.rice.krad.uif.component.ComponentBase#performInitialization(org.kuali.rice.krad.uif.view.View,
57       *      java.lang.Object)
58       */
59      @Override
60      public void performInitialization(View view, Object model) {
61          super.performInitialization(view, model);
62  
63          if (StringUtils.isNotBlank(getAlign()) && group != null) {
64              group.setAlign(getAlign());
65          }
66      }
67  
68      @Override
69      public void performFinalize(View view, Object model, Component parent) {
70          super.performFinalize(view, model, parent);
71  
72          this.addDataAttribute(UifConstants.DataAttributes.PARENT, parent.getId());
73          if (group != null) {
74              this.addDataAttribute(UifConstants.DataAttributes.GROUP, group.getId());
75          }
76  
77          setNestedComponentIdAndSuffix(getFieldLabel(), UifConstants.IdSuffixes.LABEL);
78  
79          if (this.getFieldLabel() != null) {
80              this.getFieldLabel().setLabelForComponentId(this.getId() + UifConstants.IdSuffixes.FIELDSET);
81          }
82      }
83  
84      /**
85       * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
86       */
87      @Override
88      public List<Component> getComponentsForLifecycle() {
89          List<Component> components = super.getComponentsForLifecycle();
90  
91          components.add(group);
92  
93          return components;
94      }
95  
96      /**
97       * <code>Group</code> instance that is contained within in the field
98       *
99       * @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     /**
151      * @see org.kuali.rice.krad.uif.component.ComponentBase#copy()
152      */
153     @Override
154     protected <T> void copyProperties(T component) {
155         super.copyProperties(component);
156         FieldGroup fieldGroupCopy = (FieldGroup) component;
157 
158         if (this.group != null) {
159             fieldGroupCopy.setGroup((Group)this.group.copy());
160         }
161     }
162 }