001/** 002 * Copyright 2005-2018 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.element; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.krad.datadictionary.parse.BeanTag; 020import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 021import org.kuali.rice.krad.uif.CssConstants; 022import org.kuali.rice.krad.uif.UifConstants; 023import org.kuali.rice.krad.uif.component.Component; 024import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle; 025import org.kuali.rice.krad.uif.util.LifecycleElement; 026import org.kuali.rice.krad.uif.view.View; 027 028/** 029 * The ViewHeader component represents the header for the view. 030 * 031 * <p>This header has support for a "Unified" header in 032 * which both the page title and view title appear in its content. An "area title" and "metadata" can also be set 033 * to provide context. </p> 034 * 035 * @author Kuali Rice Team (rice.collab@kuali.org) 036 */ 037@BeanTag(name = "viewHeader", parent = "Uif-ViewHeader") 038public class ViewHeader extends Header { 039 private static final long serialVersionUID = -974112303431464467L; 040 041 private Message areaTitleMessage; 042 private Message supportTitleMessage; 043 private Message metadataMessage; 044 private boolean sticky; 045 046 /** 047 * Sets the supportTitleMessage if one has not been set and unified header is being used, based on the value 048 * of page title 049 * 050 * {@inheritDoc} 051 */ 052 @Override 053 public void performFinalize(Object model, LifecycleElement parent) { 054 super.performFinalize(model, parent); 055 056 View view = ViewLifecycle.getView(); 057 if (supportTitleMessage != null && 058 view.getCurrentPage() != null && view.getCurrentPage().getHeader() != null && 059 view.isUnifiedHeader()) { 060 Header pageHeader = view.getCurrentPage().getHeader(); 061 062 // hide page header text 063 pageHeader.addStyleClass(CssConstants.Classes.HIDE_HEADER_TEXT_STYLE_CLASS); 064 065 Message pageHeaderMessage = pageHeader.getRichHeaderMessage(); 066 067 if (pageHeaderMessage != null && StringUtils.isBlank(supportTitleMessage.getMessageText())) { 068 pageHeaderMessage.addStyleClass(CssConstants.Classes.SUPPORT_TITLE_STYLE_CLASS); 069 070 // use page header rich content 071 supportTitleMessage = pageHeaderMessage; 072 } else if (StringUtils.isNotBlank(pageHeader.getHeaderText()) && StringUtils.isBlank( 073 supportTitleMessage.getMessageText())) { 074 // use set page header text 075 supportTitleMessage.setMessageText(pageHeader.getHeaderText().trim()); 076 } 077 } 078 079 // Add content container classes 080 this.getCssClasses().addAll(0, view.getContentContainerCssClasses()); 081 082 // Add sticky data attribute marker 083 if (this.isSticky()) { 084 this.addDataAttribute(UifConstants.DataAttributes.STICKY, "true"); 085 } 086 } 087 088 /** 089 * Represents the area in which this view and page exist (conceptially in the site); 090 * this title appears above the view title. 091 * 092 * @return the areaTitle text 093 */ 094 @BeanTagAttribute 095 public String getAreaTitleText() { 096 return areaTitleMessage.getMessageText(); 097 } 098 099 /** 100 * Set the areaTitle 101 * 102 * @param areaTitle 103 */ 104 public void setAreaTitleText(String areaTitle) { 105 areaTitleMessage.setMessageText(areaTitle); 106 } 107 108 /** 109 * Message object backing areaTitleText 110 * 111 * @return the areaTitle Message object 112 */ 113 @BeanTagAttribute 114 public Message getAreaTitleMessage() { 115 return areaTitleMessage; 116 } 117 118 /** 119 * Set the areaTitleMessage object 120 * 121 * @param areaTitleMessage 122 */ 123 public void setAreaTitleMessage(Message areaTitleMessage) { 124 this.areaTitleMessage = areaTitleMessage; 125 } 126 127 /** 128 * The supportTitleText represents the sub-area of this view that explains what the page is displaying; this is 129 * the text used in supportTitleMessage 130 * 131 * <p>This title appears below the view title and will be automatically set to the page title if not set.</p> 132 * 133 * @return the supportTitle text 134 */ 135 @BeanTagAttribute 136 public String getSupportTitleText() { 137 return supportTitleMessage.getMessageText(); 138 } 139 140 /** 141 * Set the supportTitleText 142 * 143 * @param supportTitle 144 */ 145 public void setSupportTitleText(String supportTitle) { 146 supportTitleMessage.setMessageText(supportTitle); 147 } 148 149 /** 150 * The supportTitleMessage represents the sub-area of this view that supports what the page is displaying, this is 151 * the Message component 152 * 153 * <p>This title appears below the view title and will be automatically set to the page title if not messageText is 154 * not set.</p> 155 * 156 * @return the supportTitle Message object 157 */ 158 @BeanTagAttribute 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 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 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 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}