View Javadoc

1   /**
2    * Copyright 2005-2013 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  
28  /**
29   * Field that contains a nested <code>Group</code>. Can be used to group
30   * together fields by providing a group without header and footer, or simply to
31   * nest full groups. The items getter/setter provided is for convenience and
32   * will set the items <code>List</code> in the nested <code>Group</code>
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  @BeanTags({@BeanTag(name = "fieldGroup-bean", parent = "Uif-FieldGroupBase"),
37          @BeanTag(name = "verticalFieldGroup-bean", parent = "Uif-VerticalFieldGroup"),
38          @BeanTag(name = "horizontalFieldGroup-bean", parent = "Uif-HorizontalFieldGroup")})
39  public class FieldGroup extends FieldBase {
40      private static final long serialVersionUID = -505654043702442196L;
41  
42      private Group group;
43  
44      public FieldGroup() {
45          super();
46      }
47  
48      /**
49       * The following initialization is performed:
50       *
51       * <ul>
52       * <li>Set the align on group if empty and the align has been set on the field</li>
53       * </ul>
54       *
55       * @see org.kuali.rice.krad.uif.component.ComponentBase#performInitialization(org.kuali.rice.krad.uif.view.View,
56       *      java.lang.Object)
57       */
58      @Override
59      public void performInitialization(Object model) {
60          super.performInitialization(model);
61  
62          if (StringUtils.isNotBlank(getAlign()) && group != null) {
63              group.setAlign(getAlign());
64          }
65      }
66  
67      @Override
68      public void performFinalize(Object model, Component parent) {
69          super.performFinalize(model, parent);
70  
71          this.addDataAttribute(UifConstants.DataAttributes.PARENT, parent.getId());
72          if (group != null) {
73              this.addDataAttribute(UifConstants.DataAttributes.GROUP, group.getId());
74          }
75  
76          setNestedComponentIdAndSuffix(getFieldLabel(), UifConstants.IdSuffixes.LABEL);
77  
78          if (this.getFieldLabel() != null) {
79              this.getFieldLabel().setLabelForComponentId(this.getId() + UifConstants.IdSuffixes.FIELDSET);
80          }
81      }
82  
83      /**
84       * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
85       */
86      @Override
87      public List<Component> getComponentsForLifecycle() {
88          List<Component> components = super.getComponentsForLifecycle();
89  
90          components.add(group);
91  
92          return components;
93      }
94  
95      /**
96       * <code>Group</code> instance that is contained within in the field
97       *
98       * @return Group instance
99       */
100     @BeanTagAttribute(name = "group", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
101     public Group getGroup() {
102         return this.group;
103     }
104 
105     /**
106      * Setter for the field's nested group
107      *
108      * @param group
109      */
110     public void setGroup(Group group) {
111         this.group = group;
112     }
113 
114     /**
115      * List of <code>Component</code> instances contained in the nested group
116      *
117      * <p>
118      * Convenience method for configuration to get the items List from the
119      * field's nested group
120      * </p>
121      *
122      * @return List<? extends Component> items
123      */
124     @BeanTagAttribute(name = "items", type = BeanTagAttribute.AttributeType.LISTBEAN)
125     public List<? extends Component> getItems() {
126         if (group != null) {
127             return group.getItems();
128         }
129 
130         return null;
131     }
132 
133     /**
134      * Setter for the field's nested group items
135      *
136      * <p>
137      * Convenience method for configuration to set the items List for the
138      * field's nested group
139      * </p>
140      *
141      * @param items
142      */
143     public void setItems(List<? extends Component> items) {
144         if (group != null) {
145             group.setItems(items);
146         }
147     }
148 
149     /**
150      * @see org.kuali.rice.krad.datadictionary.DictionaryBeanBase#copyProperties(Object)
151      */
152     @Override
153     protected <T> void copyProperties(T component) {
154         super.copyProperties(component);
155 
156         FieldGroup fieldGroupCopy = (FieldGroup) component;
157 
158         if (this.group != null) {
159             fieldGroupCopy.setGroup((Group)this.group.copy());
160         }
161     }
162 }