001    /**
002     * Copyright 2010 The Kuali Foundation Licensed under the
003     * Educational Community License, Version 2.0 (the "License"); you may
004     * not use this file except in compliance with the License. You may
005     * obtain a copy of the License at
006     *
007     * http://www.osedu.org/licenses/ECL-2.0
008     *
009     * Unless required by applicable law or agreed to in writing,
010     * software distributed under the License is distributed on an "AS IS"
011     * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012     * or implied. See the License for the specific language governing
013     * permissions and limitations under the License.
014     */
015    
016    package org.kuali.student.common.ui.client.configurable.mvc;
017    
018    import com.google.gwt.dom.client.Element;
019    import com.google.gwt.user.client.DOM;
020    import com.google.gwt.user.client.ui.ComplexPanel;
021    import com.google.gwt.user.client.ui.Widget;
022    
023    /**
024     * This class provides static methods for generating H1-H6 elements with the passed in text
025     *
026     * @author Kuali Student Team (kuali-student@googlegroups.com)
027     *
028     */
029    public class SectionTitle extends ComplexPanel {
030    
031        private String reportText;
032    
033        private SectionTitle(Element e) {
034            this.setElement(e);
035        }
036    
037        public static SectionTitle generateEmptyTitle() {
038            return generateTitle(DOM.createSpan(), null);
039        }
040    
041        public static SectionTitle generateH1Title(String titletext) {
042    
043            Element headerElement = DOM.createElement("H1");
044            headerElement.setInnerText(titletext);
045            return generateTitle(headerElement, "KS-H1-Section-Title");
046        }
047    
048        public static SectionTitle generateH2Title(String titletext) {
049    
050            Element headerElement = DOM.createElement("H2");
051            headerElement.setInnerText(titletext);
052            return generateTitle(headerElement, "KS-H2-Section-Title");
053        }
054    
055        public static SectionTitle generateH3Title(String titletext) {
056    
057            Element headerElement = DOM.createElement("H3");
058            headerElement.setInnerText(titletext);
059            return generateTitle(headerElement, "KS-H3-Section-Title");
060        }
061    
062        public static SectionTitle generateH4Title(String titletext) {
063    
064            Element headerElement = DOM.createElement("H4");
065            headerElement.setInnerText(titletext);
066            return generateTitle(headerElement, "KS-H4-Section-Title");
067        }
068    
069        public static SectionTitle generateH5Title(String titletext) {
070    
071            Element headerElement = DOM.createElement("H5");
072            headerElement.setInnerText(titletext);
073            return generateTitle(headerElement, "KS-H5-Section-Title");
074        }
075    
076        public static SectionTitle generateH6Title(String titletext) {
077    
078            Element headerElement = DOM.createElement("H6");
079            headerElement.setInnerText(titletext);
080            return generateTitle(headerElement, "KS-H6-Section-Title");
081        }
082    
083        private static SectionTitle generateTitle(Element header, String styleName) {
084            SectionTitle thisTitle = new SectionTitle(header);
085            thisTitle.addStyleName("KS-Section-Title");
086            if(styleName != null){
087                    thisTitle.addStyleName(styleName);
088            }
089            return thisTitle;
090        }
091    
092        public void setText(String text){
093            this.getElement().setInnerText(text);
094            this.reportText = text;
095        }
096        
097        public void setHTML(String html){
098            this.getElement().setInnerHTML(html);
099            this.reportText = html;
100        }
101        
102        /**
103             * Adds a new child widget to the panel.
104             * 
105             * @param w the widget to be added
106             */
107            @Override
108            public void add(Widget w) {
109                add(w, getElement());
110            }
111              
112            /**
113             * Returns a text value of the title for the export report.
114             * 
115             * @return
116             */
117            public String getExportFieldValue() {
118                if ((this.reportText != null) && (this.reportText.length() > 0)){
119                    return this.reportText;
120                }
121                return this.getElement().getInnerText();
122            }
123    }
124    
125