001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.uif.field;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.krad.uif.container.Group;
020import org.kuali.rice.krad.uif.view.View;
021import org.kuali.rice.krad.uif.component.Component;
022
023import java.util.List;
024
025/**
026 * Field that contains a nested <code>Group</code>. Can be used to group
027 * together fields by providing a group without header and footer, or simply to
028 * nest full groups. The items getter/setter provided is for convenience and
029 * will set the items <code>List</code> in the nested <code>Group</code>
030 * 
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 */
033public class FieldGroup extends FieldBase {
034        private static final long serialVersionUID = -505654043702442196L;
035
036        private Group group;
037
038        public FieldGroup() {
039                super();
040        }
041
042        /**
043         * The following initialization is performed:
044     *
045         * <ul>
046         * <li>Set the align on group if empty and the align has been set on the
047         * field</li>
048         * </ul>
049         *
050         * @see org.kuali.rice.krad.uif.component.ComponentBase#performInitialization(org.kuali.rice.krad.uif.view.View, java.lang.Object)
051         */
052        @Override
053        public void performInitialization(View view, Object model) {
054                super.performInitialization(view, model);
055
056                if (StringUtils.isNotBlank(getAlign()) && group != null) {
057                        group.setAlign(getAlign());
058                }
059        }
060
061        /**
062         * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
063         */
064        @Override
065        public List<Component> getComponentsForLifecycle() {
066                List<Component> components = super.getComponentsForLifecycle();
067
068                components.add(group);
069
070                return components;
071        }
072
073        /**
074         * <code>Group</code> instance that is contained within in the field
075         * 
076         * @return Group instance
077         */
078        public Group getGroup() {
079                return this.group;
080        }
081
082        /**
083         * Setter for the field's nested group
084         * 
085         * @param group
086         */
087        public void setGroup(Group group) {
088                this.group = group;
089        }
090
091        /**
092         * List of <code>Component</code> instances contained in the nested group
093         * 
094         * <p>
095         * Convenience method for configuration to get the items List from the
096         * field's nested group
097         * </p>
098         * 
099         * @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}