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.uif.container.Group;
20  import org.kuali.rice.krad.uif.view.View;
21  import org.kuali.rice.krad.uif.component.Component;
22  
23  import java.util.List;
24  
25  /**
26   * Field that contains a nested <code>Group</code>. Can be used to group
27   * together fields by providing a group without header and footer, or simply to
28   * nest full groups. The items getter/setter provided is for convenience and
29   * will set the items <code>List</code> in the nested <code>Group</code>
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public class FieldGroup extends FieldBase {
34  	private static final long serialVersionUID = -505654043702442196L;
35  
36  	private Group group;
37  
38  	public FieldGroup() {
39  		super();
40  	}
41  
42  	/**
43  	 * The following initialization is performed:
44       *
45  	 * <ul>
46  	 * <li>Set the align on group if empty and the align has been set on the
47  	 * field</li>
48  	 * </ul>
49  	 *
50  	 * @see org.kuali.rice.krad.uif.component.ComponentBase#performInitialization(org.kuali.rice.krad.uif.view.View, java.lang.Object)
51  	 */
52  	@Override
53  	public void performInitialization(View view, Object model) {
54  		super.performInitialization(view, model);
55  
56  		if (StringUtils.isNotBlank(getAlign()) && group != null) {
57  			group.setAlign(getAlign());
58  		}
59  	}
60  
61  	/**
62  	 * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
63  	 */
64  	@Override
65  	public List<Component> getComponentsForLifecycle() {
66  		List<Component> components = super.getComponentsForLifecycle();
67  
68  		components.add(group);
69  
70  		return components;
71  	}
72  
73  	/**
74  	 * <code>Group</code> instance that is contained within in the field
75  	 * 
76  	 * @return Group instance
77  	 */
78  	public Group getGroup() {
79  		return this.group;
80  	}
81  
82  	/**
83  	 * Setter for the field's nested group
84  	 * 
85  	 * @param group
86  	 */
87  	public void setGroup(Group group) {
88  		this.group = group;
89  	}
90  
91  	/**
92  	 * List of <code>Component</code> instances contained in the nested group
93  	 * 
94  	 * <p>
95  	 * Convenience method for configuration to get the items List from the
96  	 * field's nested group
97  	 * </p>
98  	 * 
99  	 * @return List<? extends Component> items
100 	 */
101 	public List<? extends Component> getItems() {
102 		if (group != null) {
103 			return group.getItems();
104 		}
105 
106 		return null;
107 	}
108 
109 	/**
110 	 * Setter for the field's nested group items
111 	 * 
112 	 * <p>
113 	 * Convenience method for configuration to set the items List for the
114 	 * field's nested group
115 	 * </p>
116 	 * 
117 	 * @param items
118 	 */
119     public void setItems(List<? extends Component> items) {
120         if (group != null) {
121             group.setItems(items);
122         }
123     }
124 
125 }