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