View Javadoc
1   /**
2    * Copyright 2005-2015 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 java.util.List;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
22  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
23  import org.kuali.rice.krad.datadictionary.parse.BeanTags;
24  import org.kuali.rice.krad.uif.UifConstants;
25  import org.kuali.rice.krad.uif.component.Component;
26  import org.kuali.rice.krad.uif.container.Group;
27  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleRestriction;
28  import org.kuali.rice.krad.uif.util.LifecycleElement;
29  
30  /**
31   * Field that contains a nested <code>Group</code>. Can be used to group
32   * together fields by providing a group without header and footer, or simply to
33   * nest full groups. The items getter/setter provided is for convenience and
34   * will set the items <code>List</code> in the nested <code>Group</code>
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  @BeanTags({@BeanTag(name = "fieldGroup", parent = "Uif-FieldGroupBase"),
39          @BeanTag(name = "verticalFieldGroup", parent = "Uif-VerticalFieldGroup"),
40          @BeanTag(name = "horizontalFieldGroup", parent = "Uif-HorizontalFieldGroup")})
41  public class FieldGroup extends FieldBase {
42      private static final long serialVersionUID = -505654043702442196L;
43  
44      private Group group;
45  
46      public FieldGroup() {
47          super();
48      }
49  
50      /**
51       * The following initialization is performed:
52       *
53       * <ul>
54       * <li>Set the align on group if empty and the align has been set on the field</li>
55       * </ul>
56       *
57       * {@inheritDoc}
58       */
59      @Override
60      public void performInitialization(Object model) {
61          super.performInitialization(model);
62  
63          if (StringUtils.isNotBlank(getAlign()) && group != null) {
64              group.setAlign(getAlign());
65          }
66      }
67  
68      /**
69       * {@inheritDoc}
70       */
71      @Override
72      public void afterEvaluateExpression() {
73          super.afterEvaluateExpression();
74          
75          if (group != null) {
76              group.setReadOnly(getReadOnly());
77          }
78      }
79  
80      @Override
81      public void performFinalize(Object model, LifecycleElement parent) {
82          super.performFinalize(model, parent);
83  
84          this.addDataAttribute(UifConstants.DataAttributes.PARENT, parent.getId());
85          if (group != null) {
86              this.addDataAttribute(UifConstants.DataAttributes.GROUP, group.getId());
87          }
88  
89          setNestedComponentIdAndSuffix(getFieldLabel(), UifConstants.IdSuffixes.LABEL);
90  
91          if (this.getFieldLabel() != null) {
92              this.getFieldLabel().setLabelForComponentId(this.getId() + UifConstants.IdSuffixes.FIELDSET);
93          }
94      }
95  
96      /**
97       * <code>Group</code> instance that is contained within in the field
98       *
99       * @return Group instance
100      */
101     @BeanTagAttribute(type = BeanTagAttribute.AttributeType.DIRECTORBYTYPE)
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     @ViewLifecycleRestriction
126     @BeanTagAttribute
127     public List<? extends Component> getItems() {
128         if (group != null) {
129             return group.getItems();
130         }
131 
132         return null;
133     }
134 
135     /**
136      * Setter for the field's nested group items
137      *
138      * <p>
139      * Convenience method for configuration to set the items List for the
140      * field's nested group
141      * </p>
142      *
143      * @param items
144      */
145     public void setItems(List<? extends Component> items) {
146         if (group != null) {
147             group.setItems(items);
148         }
149     }
150 }