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 java.util.List;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
22  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
23  import org.kuali.rice.krad.uif.CssConstants;
24  import org.kuali.rice.krad.uif.component.Component;
25  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
26  import org.kuali.rice.krad.uif.view.View;
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(Object model, Component parent) {
53          super.performFinalize(model, parent);
54  
55          View view = ViewLifecycle.getActiveLifecycle().getView();
56          if (supportTitleMessage != null &&
57                  view.getCurrentPage() != null && view.getCurrentPage().getHeader() != null &&
58                  view.isUnifiedHeader()) {
59              Header pageHeader = view.getCurrentPage().getHeader();
60  
61              // hide page header text
62              pageHeader.addStyleClass(CssConstants.Classes.HIDE_HEADER_TEXT_STYLE_CLASS);
63  
64              Message pageHeaderMessage = pageHeader.getRichHeaderMessage();
65  
66              if (pageHeaderMessage != null && StringUtils.isBlank(supportTitleMessage.getMessageText())) {
67                  pageHeaderMessage.addStyleClass(CssConstants.Classes.SUPPORT_TITLE_STYLE_CLASS);
68  
69                  // use page header rich content
70                  supportTitleMessage = pageHeaderMessage;
71              } else if (StringUtils.isNotBlank(pageHeader.getHeaderText()) && StringUtils.isBlank(
72                      supportTitleMessage.getMessageText())) {
73                  // use set page header text
74                  supportTitleMessage.setMessageText(pageHeader.getHeaderText().trim());
75              }
76          }
77      }
78  
79      /**
80       * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
81       */
82      @Override
83      public List<Component> getComponentsForLifecycle() {
84          List<Component> components = super.getComponentsForLifecycle();
85  
86          components.add(areaTitleMessage);
87          components.add(supportTitleMessage);
88          components.add(metadataMessage);
89  
90          return components;
91      }
92  
93      /**
94       * Represents the area in which this view and page exist (conceptially in the site);
95       * this title appears above the view title.
96       *
97       * @return the areaTitle text
98       */
99      @BeanTagAttribute(name = "areaTitleText")
100     public String getAreaTitleText() {
101         return areaTitleMessage.getMessageText();
102     }
103 
104     /**
105      * Set the areaTitle
106      *
107      * @param areaTitle
108      */
109     public void setAreaTitleText(String areaTitle) {
110         areaTitleMessage.setMessageText(areaTitle);
111     }
112 
113     /**
114      * Message object backing areaTitleText
115      *
116      * @return the areaTitle Message object
117      */
118     @BeanTagAttribute(name = "areaTitleMessage", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
119     public Message getAreaTitleMessage() {
120         return areaTitleMessage;
121     }
122 
123     /**
124      * Set the areaTitleMessage object
125      *
126      * @param areaTitleMessage
127      */
128     public void setAreaTitleMessage(Message areaTitleMessage) {
129         this.areaTitleMessage = areaTitleMessage;
130     }
131 
132     /**
133      * The supportTitleText represents the sub-area of this view that explains what the page is displaying; this is
134      * the text used in supportTitleMessage
135      *
136      * <p>This title appears below the view title and will be automatically set to the page title if not set.</p>
137      *
138      * @return the supportTitle text
139      */
140     @BeanTagAttribute(name = "supportTitleText")
141     public String getSupportTitleText() {
142         return supportTitleMessage.getMessageText();
143     }
144 
145     /**
146      * Set the supportTitleText
147      *
148      * @param supportTitle
149      */
150     public void setSupportTitleText(String supportTitle) {
151         supportTitleMessage.setMessageText(supportTitle);
152     }
153 
154     /**
155      * The supportTitleMessage represents the sub-area of this view that supports what the page is displaying, this is
156      * the Message component
157      *
158      * <p>This title appears below the view title and will be automatically set to the page title if not messageText is
159      * not set.</p>
160      *
161      * @return the supportTitle Message object
162      */
163     @BeanTagAttribute(name = "supportTitleMessage", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
164     public Message getSupportTitleMessage() {
165         return supportTitleMessage;
166     }
167 
168     /**
169      * Set the supportTitleMessage
170      *
171      * @param supportTitleMessage
172      */
173     public void setSupportTitleMessage(Message supportTitleMessage) {
174         this.supportTitleMessage = supportTitleMessage;
175     }
176 
177     /**
178      * The metadataText represents any relevant metadata about the view (last saved, etc).
179      * This message will appear in the bottom right of the ViewHeader container.
180      *
181      * @return the metadataText string
182      */
183     @BeanTagAttribute(name = "metadataText")
184     public String getMetadataText() {
185         return metadataMessage.getMessageText();
186     }
187 
188     /**
189      * Set the metadataText
190      *
191      * @param metadataText
192      */
193     public void setMetadataText(String metadataText) {
194         metadataMessage.setMessageText(metadataText);
195     }
196 
197     /**
198      * The metadataMessage represents any relevant metadata about the view (last saved, etc).
199      * This message will appear in the bottom right of the ViewHeader container.
200      *
201      * @return the metadataMessage object
202      */
203     @BeanTagAttribute(name = "metadataMessage", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
204     public Message getMetadataMessage() {
205         return metadataMessage;
206     }
207 
208     /**
209      * Set the metadataMessage
210      *
211      * @param metadataMessage
212      */
213     public void setMetadataMessage(Message metadataMessage) {
214         this.metadataMessage = metadataMessage;
215     }
216 
217     /**
218      * If true, this ViewHeader will be sticky (fixed to top of window, stays at top during scrolling)
219      *
220      * @return true if sticky, false otherwise
221      */
222     @BeanTagAttribute(name = "sticky")
223     public boolean isSticky() {
224         return sticky;
225     }
226 
227     /**
228      * Set to true to make this ViewHeader sticky
229      *
230      * @param sticky
231      */
232     public void setSticky(boolean sticky) {
233         this.sticky = sticky;
234     }
235 
236     /**
237      * @see org.kuali.rice.krad.datadictionary.DictionaryBeanBase#copyProperties(Object)
238      */
239     @Override
240     protected <T> void copyProperties(T component) {
241         super.copyProperties(component);
242 
243         ViewHeader viewHeaderCopy = (ViewHeader) component;
244 
245         if (this.areaTitleMessage != null) {
246             viewHeaderCopy.setAreaTitleMessage((Message) this.areaTitleMessage.copy());
247         }
248 
249         if (this.supportTitleMessage != null) {
250             viewHeaderCopy.setSupportTitleMessage((Message) this.supportTitleMessage.copy());
251         }
252 
253         if (this.metadataMessage != null) {
254             viewHeaderCopy.setMetadataMessage((Message) this.metadataMessage.copy());
255         }
256 
257         viewHeaderCopy.setSticky(this.sticky);
258     }
259 }