View Javadoc
1   /**
2    * Copyright 2005-2015 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.uif.container.Container;
22  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
23  import org.kuali.rice.krad.uif.view.View;
24  
25  /**
26   * BreadcrumbOptions specific to page.  Render options are only available at the page level.
27   */
28  @BeanTag(name = "pageBreadcrumbOptions", parent = "Uif-PageBreadcrumbOptions")
29  public class PageBreadcrumbOptions extends BreadcrumbOptions {
30      private static final long serialVersionUID = -5666730356781875858L;
31  
32      //render options
33      private boolean renderViewBreadcrumb;
34      private boolean renderHomewardPathBreadcrumbs;
35      private boolean renderPreViewBreadcrumbs;
36      private boolean renderPrePageBreadcrumbs;
37      private boolean renderParentLocations;
38  
39      /**
40       * Setup the BreadcrumbOptions and BreadcrumbItem for a PageGroup.  To be called from performInitialization.
41       *
42       * @param model the model
43       */
44      @Override
45      public void setupBreadcrumbs(Object model) {
46          View view = ViewLifecycle.getView();
47          BreadcrumbOptions viewBreadcrumbOptions = view.getBreadcrumbOptions();
48  
49          //inherit prePageBreadcrumbs, preViewBreadcrumbs, and overrides from the view if not set
50          if (this.getHomewardPathBreadcrumbs() == null
51                  && viewBreadcrumbOptions != null
52                  && viewBreadcrumbOptions.getHomewardPathBreadcrumbs() != null) {
53              this.setHomewardPathBreadcrumbs(viewBreadcrumbOptions.getHomewardPathBreadcrumbs());
54          }
55  
56          if (this.getPrePageBreadcrumbs() == null
57                  && viewBreadcrumbOptions != null
58                  && viewBreadcrumbOptions.getPrePageBreadcrumbs() != null) {
59              this.setPrePageBreadcrumbs(viewBreadcrumbOptions.getPrePageBreadcrumbs());
60          }
61  
62          if (this.getPreViewBreadcrumbs() == null
63                  && viewBreadcrumbOptions != null
64                  && viewBreadcrumbOptions.getPreViewBreadcrumbs() != null) {
65              this.setPreViewBreadcrumbs(viewBreadcrumbOptions.getPreViewBreadcrumbs());
66          }
67  
68          if (this.getBreadcrumbOverrides() == null
69                  && viewBreadcrumbOptions != null
70                  && viewBreadcrumbOptions.getBreadcrumbOverrides() != null) {
71              this.setBreadcrumbOverrides(viewBreadcrumbOptions.getBreadcrumbOverrides());
72          }
73      }
74  
75      /**
76       * Finalize the setup of the BreadcrumbOptions and the BreadcrumbItem for the PageGroup.  To be called from the
77       * performFinalize method.
78       *
79       * @param model the model
80       */
81      @Override
82      public void finalizeBreadcrumbs(Object model, Container parent, BreadcrumbItem breadcrumbItem) {
83          //set breadcrumbItem label same as the header, if not set
84          if (StringUtils.isBlank(breadcrumbItem.getLabel()) && parent.getHeader() != null && StringUtils.isNotBlank(
85                  parent.getHeader().getHeaderText())) {
86              breadcrumbItem.setLabel(parent.getHeader().getHeaderText());
87          }
88  
89          //if label still blank, dont render
90          if (StringUtils.isBlank(breadcrumbItem.getLabel())) {
91              breadcrumbItem.setRender(false);
92          }
93  
94          // set breadcrumb url attributes
95          finalizeBreadcrumbsUrl(model, parent, breadcrumbItem);
96  
97          if (breadcrumbItem.getUrl().getPageId() == null) {
98              breadcrumbItem.getUrl().setPageId(parent.getId());
99          }
100     }
101 
102     /**
103      * Whether or not to render the view breadcrumb at this level
104      *
105      * @return true if rendering the view breadcrumb, false otherwise
106      */
107     @BeanTagAttribute(name = "renderViewBreadcrumb")
108     public boolean isRenderViewBreadcrumb() {
109         return renderViewBreadcrumb;
110     }
111 
112     /**
113      * Set renderViewBreadcrumb
114      *
115      * @param renderViewBreadcrumb
116      */
117     public void setRenderViewBreadcrumb(boolean renderViewBreadcrumb) {
118         this.renderViewBreadcrumb = renderViewBreadcrumb;
119     }
120 
121     /**
122      * If true, render the homewardPathBreadcrumbs (if any are set), otherwise do not render them
123      *
124      * @return true if rendering homewardPathBreadcrumbs, false otherwise
125      */
126     @BeanTagAttribute(name = "renderHomewardPathBreadcrumbs")
127     public boolean isRenderHomewardPathBreadcrumbs() {
128         return renderHomewardPathBreadcrumbs;
129     }
130 
131     /**
132      * Set renderHomewardPathBreadcrumbs
133      *
134      * @param renderHomewardPathBreadcrumbs
135      */
136     public void setRenderHomewardPathBreadcrumbs(boolean renderHomewardPathBreadcrumbs) {
137         this.renderHomewardPathBreadcrumbs = renderHomewardPathBreadcrumbs;
138     }
139 
140     /**
141      * If true, render the preViewBreadcrumbs (if any are set), otherwise do not render them
142      *
143      * @return true if rendering preViewBreadcrumbs, false otherwise
144      */
145     @BeanTagAttribute(name = "renderPreViewBreadcrumbs")
146     public boolean isRenderPreViewBreadcrumbs() {
147         return renderPreViewBreadcrumbs;
148     }
149 
150     /**
151      * Set renderPreViewBreadcrumbs
152      *
153      * @param renderPreViewBreadcrumbs
154      */
155     public void setRenderPreViewBreadcrumbs(boolean renderPreViewBreadcrumbs) {
156         this.renderPreViewBreadcrumbs = renderPreViewBreadcrumbs;
157     }
158 
159     /**
160      * If true, render the prePageBreadcrumbs (if any are set), otherwise do not render them
161      *
162      * @return true if rendering prePageBreadcrumbs, false otherwise
163      */
164     @BeanTagAttribute(name = "renderPrePageBreadcrumbs")
165     public boolean isRenderPrePageBreadcrumbs() {
166         return renderPrePageBreadcrumbs;
167     }
168 
169     /**
170      * Set renderPrePageBreadcrumbs
171      *
172      * @param renderPrePageBreadcrumbs
173      */
174     public void setRenderPrePageBreadcrumbs(boolean renderPrePageBreadcrumbs) {
175         this.renderPrePageBreadcrumbs = renderPrePageBreadcrumbs;
176     }
177 
178     /**
179      * If true, render the parent location breadcrumbs.  These BreadcrumbItems are automatically generated based on the
180      * view's parentLocation property settings by traversing parent views/pages or based on a history path.
181      *
182      * @return true if rendering the parent location breadcrumbs, false otherwise
183      */
184     @BeanTagAttribute(name = "renderParentLocations")
185     public boolean isRenderParentLocations() {
186         return renderParentLocations;
187     }
188 
189     /**
190      * Set renderParentLocations
191      *
192      * @param renderParentLocations
193      */
194     public void setRenderParentLocations(boolean renderParentLocations) {
195         this.renderParentLocations = renderParentLocations;
196     }
197 }