001    /**
002     * Copyright 2005-2012 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     */
016    package org.kuali.rice.krad.uif.element;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.rice.krad.uif.component.Component;
020    import org.kuali.rice.krad.uif.container.Group;
021    import org.kuali.rice.krad.uif.view.View;
022    
023    import java.util.ArrayList;
024    import java.util.List;
025    
026    /**
027     * Content element that renders a header element and optionally a <code>Group</code> to
028     * present along with the header text
029     *
030     * <p>
031     * Generally the group is used to display content to the right of the header,
032     * such as links for the group or other information
033     * </p>
034     *
035     * @author Kuali Rice Team (rice.collab@kuali.org)
036     */
037    public class Header extends ContentElementBase {
038        private static final long serialVersionUID = -6950408292923393244L;
039    
040        private String headerText;
041        private String headerLevel;
042    
043        private String headerTagStyle;
044        private List<String> headerTagCssClasses;
045    
046        private Group upperGroup;
047        private Group rightGroup;
048        private Group lowerGroup;
049    
050        public Header() {
051            super();
052    
053            headerTagCssClasses = new ArrayList<String>();
054        }
055    
056        /**
057         * The following finalization is performed:
058         *
059         * <ul>
060         * <li>Set render on header group to false if no items are configured</li>
061         * </ul>
062         *
063         * @see org.kuali.rice.krad.uif.component.ComponentBase#performFinalize(org.kuali.rice.krad.uif.view.View,
064         *      java.lang.Object, org.kuali.rice.krad.uif.component.Component)
065         */
066        @Override
067        public void performFinalize(View view, Object model, Component parent) {
068            super.performFinalize(view, model, parent);
069    
070            // don't render header groups if no items were configured
071            if ((getUpperGroup() != null) && (getUpperGroup().getItems().isEmpty())) {
072                getUpperGroup().setRender(false);
073            }
074    
075            if ((getRightGroup() != null) && (getRightGroup().getItems().isEmpty())) {
076                getRightGroup().setRender(false);
077            }
078    
079            if ((getLowerGroup() != null) && (getLowerGroup().getItems().isEmpty())) {
080                getLowerGroup().setRender(false);
081            }
082            
083            //add preset styles to header groups
084            if(getUpperGroup() != null){
085                getUpperGroup().addStyleClass("uif-header-upperGroup");
086            }
087    
088            if(getRightGroup() != null){
089                getRightGroup().addStyleClass("uif-header-rightGroup");
090            }
091    
092            if(getLowerGroup() != null){
093                getLowerGroup().addStyleClass("uif-header-lowerGroup");
094            }
095        }
096    
097        /**
098         * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
099         */
100        @Override
101        public List<Component> getComponentsForLifecycle() {
102            List<Component> components = super.getComponentsForLifecycle();
103    
104            components.add(upperGroup);
105            components.add(rightGroup);
106            components.add(lowerGroup);
107    
108            return components;
109        }
110    
111        /**
112         * Text that should be displayed on the header
113         *
114         * @return String header text
115         */
116        public String getHeaderText() {
117            return this.headerText;
118        }
119    
120        /**
121         * Setter for the header text
122         *
123         * @param headerText
124         */
125        public void setHeaderText(String headerText) {
126            this.headerText = headerText;
127        }
128    
129        /**
130         * HTML header level (h1 ... h6) that should be applied to the header text
131         *
132         * @return String header level
133         */
134        public String getHeaderLevel() {
135            return this.headerLevel;
136        }
137    
138        /**
139         * Setter for the header level
140         *
141         * @param headerLevel
142         */
143        public void setHeaderLevel(String headerLevel) {
144            this.headerLevel = headerLevel;
145        }
146    
147        /**
148         * Style classes that should be applied to the header text (h tag)
149         *
150         * <p>
151         * Note the style class given here applies to only the header text. The
152         * style class property inherited from the <code>Component</code> interface
153         * can be used to set the class for the whole field div (which could
154         * include a nested <code>Group</code>)
155         * </p>
156         *
157         * @return List<String> list of style classes
158         * @see org.kuali.rice.krad.uif.component.Component#getCssClasses()
159         */
160        public List<String> getHeaderTagCssClasses() {
161            return this.headerTagCssClasses;
162        }
163    
164        /**
165         * Setter for the list of classes to apply to the header h tag
166         *
167         * @param headerTagCssClasses
168         */
169        public void setHeaderTagCssClasses(List<String> headerTagCssClasses) {
170            this.headerTagCssClasses = headerTagCssClasses;
171        }
172    
173        /**
174         * Builds the HTML class attribute string by combining the headerStyleClasses list
175         * with a space delimiter
176         *
177         * @return String class attribute string
178         */
179        public String getHeaderStyleClassesAsString() {
180            if (headerTagCssClasses != null) {
181                return StringUtils.join(headerTagCssClasses, " ");
182            }
183    
184            return "";
185        }
186    
187        /**
188         * Style that should be applied to the header h tag
189         *
190         * <p>
191         * Note the style given here applies to only the header text. The style
192         * property inherited from the <code>Component</code> interface can be used
193         * to set the style for the whole header div (which could include a nested
194         * <code>Group</code>)
195         * </p>
196         *
197         * @return String header style
198         * @see org.kuali.rice.krad.uif.component.Component#getStyle()
199         */
200        public String getHeaderTagStyle() {
201            return this.headerTagStyle;
202        }
203    
204        /**
205         * Setter for the header h tag style
206         *
207         * @param headerTagStyle
208         */
209        public void setHeaderTagStyle(String headerTagStyle) {
210            this.headerTagStyle = headerTagStyle;
211        }
212    
213        /**
214         * Nested group instance that can be used to render contents above the header text
215         *
216         * <p>
217         * The header group is useful for adding content such as links or actions that is presented with the header
218         * </p>
219         *
220         * @return Group instance
221         */
222        public Group getUpperGroup() {
223            return upperGroup;
224        }
225    
226        /**
227         * Setter for the header group instance that is rendered above the header text
228         *
229         * @param upperGroup
230         */
231        public void setUpperGroup(Group upperGroup) {
232            this.upperGroup = upperGroup;
233        }
234    
235        /**
236         * Nested group instance that can be used to render contents to the right of the header text
237         *
238         * <p>
239         * The header group is useful for adding content such as links or actions that is presented with the header
240         * </p>
241         *
242         * @return Group instance
243         */
244        public Group getRightGroup() {
245            return rightGroup;
246        }
247    
248        /**
249         * Setter for the header group instance that is rendered to the right of the header text
250         *
251         * @param rightGroup
252         */
253        public void setRightGroup(Group rightGroup) {
254            this.rightGroup = rightGroup;
255        }
256    
257        /**
258         * Nested group instance that can be used to render contents below the header text
259         *
260         * <p>
261         * The header group is useful for adding content such as links or actions that is presented with the header
262         * </p>
263         *
264         * @return Group instance
265         */
266        public Group getLowerGroup() {
267            return lowerGroup;
268        }
269    
270        /**
271         * Setter for the header group instance that is rendered below the header text
272         *
273         * @param lowerGroup
274         */
275        public void setLowerGroup(Group lowerGroup) {
276            this.lowerGroup = lowerGroup;
277        }
278    
279        /**
280         * List of <code>Component</code> instances contained in the lower header group
281         *
282         * <p>
283         * Convenience method for configuration to get the items List from the
284         * lower header group
285         * </p>
286         *
287         * @return List<? extends Component> items
288         */
289        public List<? extends Component> getItems() {
290            if (lowerGroup != null) {
291                return lowerGroup.getItems();
292            }
293    
294            return null;
295        }
296    
297        /**
298         * Setter for the lower group's items
299         *
300         * <p>
301         * Convenience method for configuration to set the items List for the
302         * lower header group
303         * </p>
304         *
305         * @param items
306         */
307        public void setItems(List<? extends Component> items) {
308            if (lowerGroup != null) {
309                lowerGroup.setItems(items);
310            }
311        }
312    }