View Javadoc

1   /**
2    * Copyright 2005-2014 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.util;
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.view.View;
23  import org.kuali.rice.krad.web.form.UifFormBase;
24  
25  import java.util.Map;
26  
27  /**
28   * BreadcrumbOptions specific to page.  Render options are only available at the page level.
29   */
30  @BeanTag(name = "pageBreadcrumbOptions-bean", parent = "Uif-PageBreadcrumbOptions")
31  public class PageBreadcrumbOptions extends BreadcrumbOptions {
32      private static final long serialVersionUID = -5666730356781875858L;
33  
34      //render options
35      private boolean renderViewBreadcrumb;
36      private boolean renderHomewardPathBreadcrumbs;
37      private boolean renderPreViewBreadcrumbs;
38      private boolean renderPrePageBreadcrumbs;
39      private boolean renderParentLocations;
40  
41      /**
42       * Setup the BreadcrumbOptions and BreadcrumbItem for a PageGroup.  To be called from performInitialization.
43       *
44       * @param view the page's View
45       * @param model the model
46       */
47      @Override
48      public void setupBreadcrumbs(View view, Object model) {
49          BreadcrumbOptions viewBreadcrumbOptions = view.getBreadcrumbOptions();
50  
51          //inherit prePageBreadcrumbs, preViewBreadcrumbs, and overrides from the view if not set
52          if (this.getHomewardPathBreadcrumbs() == null
53                  && viewBreadcrumbOptions != null
54                  && viewBreadcrumbOptions.getHomewardPathBreadcrumbs() != null) {
55              this.setHomewardPathBreadcrumbs(viewBreadcrumbOptions.getHomewardPathBreadcrumbs());
56  
57              for (BreadcrumbItem item : this.getHomewardPathBreadcrumbs()) {
58                  view.assignComponentIds(item);
59              }
60          }
61  
62          if (this.getPrePageBreadcrumbs() == null
63                  && viewBreadcrumbOptions != null
64                  && viewBreadcrumbOptions.getPrePageBreadcrumbs() != null) {
65              this.setPrePageBreadcrumbs(viewBreadcrumbOptions.getPrePageBreadcrumbs());
66  
67              for (BreadcrumbItem item : this.getPrePageBreadcrumbs()) {
68                  view.assignComponentIds(item);
69              }
70          }
71  
72          if (this.getPreViewBreadcrumbs() == null
73                  && viewBreadcrumbOptions != null
74                  && viewBreadcrumbOptions.getPreViewBreadcrumbs() != null) {
75              this.setPreViewBreadcrumbs(viewBreadcrumbOptions.getPreViewBreadcrumbs());
76  
77              for (BreadcrumbItem item : this.getPreViewBreadcrumbs()) {
78                  view.assignComponentIds(item);
79              }
80          }
81  
82          if (this.getBreadcrumbOverrides() == null
83                  && viewBreadcrumbOptions != null
84                  && viewBreadcrumbOptions.getBreadcrumbOverrides() != null) {
85              this.setBreadcrumbOverrides(viewBreadcrumbOptions.getBreadcrumbOverrides());
86  
87              for (BreadcrumbItem item : this.getBreadcrumbOverrides()) {
88                  view.assignComponentIds(item);
89              }
90          }
91      }
92  
93      /**
94       * Finalize the setup of the BreadcrumbOptions and the BreadcrumbItem for the PageGroup.  To be called from the
95       * performFinalize method.
96       *
97       * @param view the page's View
98       * @param model the model
99       */
100     @Override
101     public void finalizeBreadcrumbs(View view, Object model, Container parent, BreadcrumbItem breadcrumbItem) {
102         //set breadcrumbItem label same as the header, if not set
103         if (StringUtils.isBlank(breadcrumbItem.getLabel()) && parent.getHeader() != null && StringUtils.isNotBlank(
104                 parent.getHeader().getHeaderText())) {
105             breadcrumbItem.setLabel(parent.getHeader().getHeaderText());
106         }
107 
108         //if label still blank, dont render
109         if (StringUtils.isBlank(breadcrumbItem.getLabel())) {
110             breadcrumbItem.setRender(false);
111         }
112 
113         //special breadcrumb request param handling
114         if (breadcrumbItem.getUrl().getControllerMapping() == null
115                 && breadcrumbItem.getUrl().getViewId() == null
116                 && model instanceof UifFormBase
117                 && breadcrumbItem.getUrl().getRequestParameters() == null
118                 && ((UifFormBase) model).getInitialRequestParameters() != null) {
119             //add the current request parameters if controllerMapping, viewId, and requestParams are null
120             //(this means that no explicit breadcrumbItem customization was set)
121             Map<String, String> requestParameters = ((UifFormBase) model).getInitialRequestParameters();
122 
123             //remove ajax properties because breadcrumb should always be a full view request
124             requestParameters.remove("ajaxReturnType");
125             requestParameters.remove("ajaxRequest");
126 
127             //remove pageId because this should be set by the BreadcrumbItem setting
128             requestParameters.remove("pageId");
129 
130             breadcrumbItem.getUrl().setRequestParameters(requestParameters);
131         }
132 
133         //form key handling
134         if (breadcrumbItem.getUrl().getFormKey() == null
135                 && model instanceof UifFormBase
136                 && ((UifFormBase) model).getFormKey() != null) {
137             breadcrumbItem.getUrl().setFormKey(((UifFormBase) model).getFormKey());
138         }
139 
140         //automatically set breadcrumbItem UifUrl properties below, if not set
141         if (breadcrumbItem.getUrl().getControllerMapping() == null && model instanceof UifFormBase) {
142             breadcrumbItem.getUrl().setControllerMapping(((UifFormBase) model).getControllerMapping());
143         }
144 
145         if (breadcrumbItem.getUrl().getViewId() == null) {
146             breadcrumbItem.getUrl().setViewId(view.getId());
147         }
148 
149         if (breadcrumbItem.getUrl().getPageId() == null) {
150             breadcrumbItem.getUrl().setPageId(parent.getId());
151         }
152     }
153 
154     /**
155      * Whether or not to render the view breadcrumb at this level
156      *
157      * @return true if rendering the view breadcrumb, false otherwise
158      */
159     @BeanTagAttribute(name = "renderViewBreadcrumb")
160     public boolean isRenderViewBreadcrumb() {
161         return renderViewBreadcrumb;
162     }
163 
164     /**
165      * Set renderViewBreadcrumb
166      *
167      * @param renderViewBreadcrumb
168      */
169     public void setRenderViewBreadcrumb(boolean renderViewBreadcrumb) {
170         this.renderViewBreadcrumb = renderViewBreadcrumb;
171     }
172 
173     /**
174      * If true, render the homewardPathBreadcrumbs (if any are set), otherwise do not render them
175      *
176      * @return true if rendering homewardPathBreadcrumbs, false otherwise
177      */
178     @BeanTagAttribute(name = "renderHomewardPathBreadcrumbs")
179     public boolean isRenderHomewardPathBreadcrumbs() {
180         return renderHomewardPathBreadcrumbs;
181     }
182 
183     /**
184      * Set renderHomewardPathBreadcrumbs
185      *
186      * @param renderHomewardPathBreadcrumbs
187      */
188     public void setRenderHomewardPathBreadcrumbs(boolean renderHomewardPathBreadcrumbs) {
189         this.renderHomewardPathBreadcrumbs = renderHomewardPathBreadcrumbs;
190     }
191 
192     /**
193      * If true, render the preViewBreadcrumbs (if any are set), otherwise do not render them
194      *
195      * @return true if rendering preViewBreadcrumbs, false otherwise
196      */
197     @BeanTagAttribute(name = "renderPreViewBreadcrumbs")
198     public boolean isRenderPreViewBreadcrumbs() {
199         return renderPreViewBreadcrumbs;
200     }
201 
202     /**
203      * Set renderPreViewBreadcrumbs
204      *
205      * @param renderPreViewBreadcrumbs
206      */
207     public void setRenderPreViewBreadcrumbs(boolean renderPreViewBreadcrumbs) {
208         this.renderPreViewBreadcrumbs = renderPreViewBreadcrumbs;
209     }
210 
211     /**
212      * If true, render the prePageBreadcrumbs (if any are set), otherwise do not render them
213      *
214      * @return true if rendering prePageBreadcrumbs, false otherwise
215      */
216     @BeanTagAttribute(name = "renderPrePageBreadcrumbs")
217     public boolean isRenderPrePageBreadcrumbs() {
218         return renderPrePageBreadcrumbs;
219     }
220 
221     /**
222      * Set renderPrePageBreadcrumbs
223      *
224      * @param renderPrePageBreadcrumbs
225      */
226     public void setRenderPrePageBreadcrumbs(boolean renderPrePageBreadcrumbs) {
227         this.renderPrePageBreadcrumbs = renderPrePageBreadcrumbs;
228     }
229 
230     /**
231      * If true, render the parent location breadcrumbs.  These BreadcrumbItems are automatically generated based on the
232      * view's parentLocation property settings by traversing parent views/pages or based on a history path.
233      *
234      * @return true if rendering the parent location breadcrumbs, false otherwise
235      */
236     @BeanTagAttribute(name = "renderParentLocations")
237     public boolean isRenderParentLocations() {
238         return renderParentLocations;
239     }
240 
241     /**
242      * Set renderParentLocations
243      *
244      * @param renderParentLocations
245      */
246     public void setRenderParentLocations(boolean renderParentLocations) {
247         this.renderParentLocations = renderParentLocations;
248     }
249 
250     /**
251      * Copies the properties over for the copy method.
252      *
253      * @param breadcrumbOptions The BreadcrumbOptions to copy
254      */
255     protected <T> void copyProperties(T breadcrumbOptions) {
256         super.copyProperties(breadcrumbOptions);
257         PageBreadcrumbOptions breadcrumbOptionsCopy = (PageBreadcrumbOptions) breadcrumbOptions;
258 
259         breadcrumbOptionsCopy.setRenderViewBreadcrumb(this.renderViewBreadcrumb);
260         breadcrumbOptionsCopy.setRenderHomewardPathBreadcrumbs(this.renderHomewardPathBreadcrumbs);
261         breadcrumbOptionsCopy.setRenderPreViewBreadcrumbs(this.renderPreViewBreadcrumbs);
262         breadcrumbOptionsCopy.setRenderPrePageBreadcrumbs(this.renderPrePageBreadcrumbs);
263         breadcrumbOptionsCopy.setRenderParentLocations(this.renderParentLocations);
264     }
265 }