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.util;
17  
18  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
20  import org.kuali.rice.krad.uif.component.Component;
21  import org.kuali.rice.krad.uif.element.ContentElementBase;
22  import org.kuali.rice.krad.uif.view.View;
23  
24  import java.util.ArrayList;
25  import java.util.HashMap;
26  import java.util.List;
27  import java.util.Map;
28  
29  /**
30   * BreadcrumbItem represents a single item in the breadcrumb list that is generated by the breadcrumbs widget
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  @BeanTag(name = "breadcrumbItem-bean", parent = "Uif-BreadcrumbItem")
35  public class BreadcrumbItem extends ContentElementBase {
36      private String label;
37      private UrlInfo url;
38      private Component siblingBreadcrumbComponent;
39      private boolean renderAsLink;
40  
41      /**
42       * The following updates are done here:
43       *
44       * <ul>
45       * <li>Evaluate expressions on url object</li>
46       * </ul>
47       *
48       * @see org.kuali.rice.krad.uif.component.Component#performApplyModel(org.kuali.rice.krad.uif.view.View,
49       *      java.lang.Object, org.kuali.rice.krad.uif.component.Component)
50       */
51      @Override
52      public void performApplyModel(View view, Object model, Component parent) {
53          super.performApplyModel(view, model, parent);
54  
55          if (url != null) {
56              Map<String, Object> context = new HashMap<String, Object>();
57  
58              Map<String, Object> viewContext = view.getContext();
59              if (viewContext != null) {
60                  context.putAll(viewContext);
61              }
62  
63              ExpressionUtils.populatePropertyExpressionsFromGraph(url, false);
64              view.getViewHelperService().getExpressionEvaluator().evaluateExpressionsOnConfigurable(view, url,
65                      context);
66          }
67      }
68  
69      /**
70       * Adds siblingBreadcrumbComponent to the components for the lifecycle
71       *
72       * @see org.kuali.rice.krad.uif.component.Component#getComponentsForLifecycle()
73       */
74      @Override
75      public List<Component> getComponentsForLifecycle() {
76          List<Component> components = new ArrayList<Component>();
77  
78          components.add(siblingBreadcrumbComponent);
79          components.addAll(super.getComponentsForLifecycle());
80  
81          return components;
82      }
83  
84      /**
85       * The label for this breadcrumbItem.  The label is the textual content that will be displayed for the breadcrumb.
86       *
87       * @return the label
88       */
89      @BeanTagAttribute(name = "label")
90      public String getLabel() {
91          return label;
92      }
93  
94      /**
95       * Set the label for this breadcrumbItem.  The label is the textual content that will be displayed for the
96       * breadcrumb.
97       *
98       * @param label
99       */
100     public void setLabel(String label) {
101         this.label = label;
102     }
103 
104     /**
105      * The url used for the breadcrumb link represented by this item
106      *
107      * @return the url object
108      */
109     @BeanTagAttribute(name = "url")
110     public UrlInfo getUrl() {
111         return url;
112     }
113 
114     /**
115      * Set the url object
116      *
117      * @param urlObject
118      */
119     public void setUrl(UrlInfo urlObject) {
120         this.url = urlObject;
121     }
122 
123     /**
124      * Set the breadcrumb component for this breadcrumbs sibling content/navigation.  This content will appear in
125      * a pop-up menu.
126      *
127      * @return the sibling component to appear in a popup menu
128      */
129     @BeanTagAttribute(name = "siblingBreadcrumbComponent", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
130     public Component getSiblingBreadcrumbComponent() {
131         return siblingBreadcrumbComponent;
132     }
133 
134     /**
135      * Set the sibling breadcrumb component
136      *
137      * @param siblingBreadcrumbComponent
138      */
139     public void setSiblingBreadcrumbComponent(Component siblingBreadcrumbComponent) {
140         this.siblingBreadcrumbComponent = siblingBreadcrumbComponent;
141     }
142 
143     /**
144      * If true, the breadcrumbItem will render as a link, otherwise it will render as a span (not-clickable).
145      * By default, the last BreadcrumbItem in the list will ALWAYS render as span regardless of this property's value.
146      *
147      * @return true if rendering as a link, false otherwise
148      */
149     @BeanTagAttribute(name = "renderAsLink")
150     public boolean isRenderAsLink() {
151         return renderAsLink;
152     }
153 
154     /**
155      * Set to true to render as a link, false otherwise
156      *
157      * @param renderAsLink
158      */
159     public void setRenderAsLink(boolean renderAsLink) {
160         this.renderAsLink = renderAsLink;
161     }
162 
163     /**
164      * @see org.kuali.rice.krad.uif.component.ComponentBase#copy()
165      */
166     @Override
167     protected <T> void copyProperties(T component) {
168         super.copyProperties(component);
169         BreadcrumbItem breadcrumbItemCopy = (BreadcrumbItem) component;
170         breadcrumbItemCopy.setLabel(this.label);
171 
172         if (this.siblingBreadcrumbComponent != null) {
173             breadcrumbItemCopy.setSiblingBreadcrumbComponent((Component)this.siblingBreadcrumbComponent.copy());
174         }
175 
176         breadcrumbItemCopy.setRenderAsLink(this.renderAsLink);
177 
178         if (this.url != null) {
179             breadcrumbItemCopy.setUrl((UrlInfo)this.url.copy());
180         }
181     }
182 }