View Javadoc

1   /**
2    * Copyright 2005-2013 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.element;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21  import org.kuali.rice.krad.datadictionary.parse.BeanTags;
22  import org.kuali.rice.krad.uif.UifConstants;
23  import org.kuali.rice.krad.uif.component.Component;
24  import org.kuali.rice.krad.uif.view.View;
25  
26  import java.util.List;
27  
28  /**
29   * The ViewHeader component represents the header for the view
30   *
31   * <p>This header has support for a "Unified" header in
32   * which both the page title and view title appear in its content.  An "area title" and "metadata" can also be set
33   * to provide context. </p>
34   *
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  @BeanTag(name = "viewHeader-bean", parent = "Uif-ViewHeader")
38  public class ViewHeader extends Header {
39  
40      private Message areaTitleMessage;
41      private Message supportTitleMessage;
42      private Message metadataMessage;
43      private boolean sticky;
44  
45      /**
46       * Sets the supportTitleMessage if one has not been set and unified header is being used, based on the value
47       * of page title
48       *
49       * @see Component#performFinalize(org.kuali.rice.krad.uif.view.View, Object, org.kuali.rice.krad.uif.component.Component)
50       */
51      @Override
52      public void performFinalize(View view, Object model, Component parent) {
53          super.performFinalize(view, model, parent);
54  
55          if (supportTitleMessage != null &&
56                  view.getCurrentPage() != null && view.getCurrentPage().getHeader() != null &&
57                  view.isUnifiedHeader()) {
58              Header pageHeader = view.getCurrentPage().getHeader();
59  
60              // hide page header text
61              pageHeader.addStyleClass(UifConstants.CssClasses.HIDE_HEADER_TEXT_STYLE_CLASS);
62  
63              Message pageHeaderMessage = pageHeader.getRichHeaderMessage();
64  
65              if (pageHeaderMessage != null && StringUtils.isBlank(supportTitleMessage.getMessageText())) {
66                  pageHeaderMessage.addStyleClass(UifConstants.CssClasses.SUPPORT_TITLE_STYLE_CLASS);
67  
68                  // use page header rich content
69                  supportTitleMessage = pageHeaderMessage;
70              } else if (StringUtils.isNotBlank(pageHeader.getHeaderText()) && StringUtils.isBlank(
71                      supportTitleMessage.getMessageText())) {
72                  // use set page header text
73                  supportTitleMessage.setMessageText(pageHeader.getHeaderText().trim());
74              }
75          }
76      }
77  
78      /**
79       * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
80       */
81      @Override
82      public List<Component> getComponentsForLifecycle() {
83          List<Component> components = super.getComponentsForLifecycle();
84  
85          components.add(areaTitleMessage);
86          components.add(supportTitleMessage);
87          components.add(metadataMessage);
88  
89          return components;
90      }
91  
92      /**
93       * Represents the area in which this view and page exist (conceptially in the site);
94       * this title appears above the view title.
95       *
96       * @return the areaTitle text
97       */
98      @BeanTagAttribute(name = "areaTitleText")
99      public String getAreaTitleText() {
100         return areaTitleMessage.getMessageText();
101     }
102 
103     /**
104      * Set the areaTitle
105      *
106      * @param areaTitle
107      */
108     public void setAreaTitleText(String areaTitle) {
109         areaTitleMessage.setMessageText(areaTitle);
110     }
111 
112     /**
113      * Message object backing areaTitleText
114      *
115      * @return the areaTitle Message object
116      */
117     @BeanTagAttribute(name = "areaTitleMessage", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
118     public Message getAreaTitleMessage() {
119         return areaTitleMessage;
120     }
121 
122     /**
123      * Set the areaTitleMessage object
124      *
125      * @param areaTitleMessage
126      */
127     public void setAreaTitleMessage(Message areaTitleMessage) {
128         this.areaTitleMessage = areaTitleMessage;
129     }
130 
131     /**
132      * The supportTitleText represents the sub-area of this view that explains what the page is displaying.
133      * This title appears below the view title and will be automatically set to the page title if not set.
134      *
135      * @return the supportTitle text
136      */
137     @BeanTagAttribute(name = "supportTitleText")
138     public String getSupportTitleText() {
139         return supportTitleMessage.getMessageText();
140     }
141 
142     /**
143      * Set the supportTitleText
144      *
145      * @param supportTitle
146      */
147     public void setSupportTitleText(String supportTitle) {
148         supportTitleMessage.setMessageText(supportTitle);
149     }
150 
151     /**
152      * The supportTitleMessage represents the sub-area of this view that supports what the page is displaying.
153      * This title appears below the view title and will be automatically set to the page title if not messageText is
154      * not set.
155      *
156      * @return the supportTitle Message object
157      */
158     @BeanTagAttribute(name = "supportTitleMessage", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
159     public Message getSupportTitleMessage() {
160         return supportTitleMessage;
161     }
162 
163     /**
164      * Set the supportTitleMessage
165      *
166      * @param supportTitleMessage
167      */
168     public void setSupportTitleMessage(Message supportTitleMessage) {
169         this.supportTitleMessage = supportTitleMessage;
170     }
171 
172     /**
173      * The metadataText represents any relevant metadata about the view (last saved, etc).
174      * This message will appear in the bottom right of the ViewHeader container.
175      *
176      * @return the metadataText string
177      */
178     @BeanTagAttribute(name = "metadataText")
179     public String getMetadataText() {
180         return metadataMessage.getMessageText();
181     }
182 
183     /**
184      * Set the metadataText
185      *
186      * @param metadataText
187      */
188     public void setMetadataText(String metadataText) {
189         metadataMessage.setMessageText(metadataText);
190     }
191 
192     /**
193      * The metadataMessage represents any relevant metadata about the view (last saved, etc).
194      * This message will appear in the bottom right of the ViewHeader container.
195      *
196      * @return the metadataMessage object
197      */
198     @BeanTagAttribute(name = "metadataMessage", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
199     public Message getMetadataMessage() {
200         return metadataMessage;
201     }
202 
203     /**
204      * Set the metadataMessage
205      *
206      * @param metadataMessage
207      */
208     public void setMetadataMessage(Message metadataMessage) {
209         this.metadataMessage = metadataMessage;
210     }
211 
212     /**
213      * If true, this ViewHeader will be sticky (fixed to top of window, stays at top during scrolling)
214      *
215      * @return true if sticky, false otherwise
216      */
217     @BeanTagAttribute(name = "sticky")
218     public boolean isSticky() {
219         return sticky;
220     }
221 
222     /**
223      * Set to true to make this ViewHeader sticky
224      *
225      * @param sticky
226      */
227     public void setSticky(boolean sticky) {
228         this.sticky = sticky;
229     }
230 }