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 java.util.HashMap;
019import java.util.Map;
020
021import org.kuali.rice.krad.datadictionary.parse.BeanTag;
022import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
023import org.kuali.rice.krad.uif.component.Component;
024import org.kuali.rice.krad.uif.element.ContentElementBase;
025import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
026import org.kuali.rice.krad.uif.util.LifecycleElement;
027import org.kuali.rice.krad.uif.util.UrlInfo;
028import org.kuali.rice.krad.uif.view.View;
029
030import java.util.HashMap;
031import java.util.Map;
032
033/**
034 * BreadcrumbItem represents a single item in the breadcrumb list that is generated by the breadcrumbs widget.
035 *
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 */
038@BeanTag(name = "breadcrumbItem", parent = "Uif-BreadcrumbItem")
039public class BreadcrumbItem extends ContentElementBase {
040    private static final long serialVersionUID = 6694853722827812544L;
041
042    private String label;
043    private UrlInfo url;
044    private Component siblingBreadcrumbComponent;
045    private boolean renderAsLink;
046
047    /**
048     * The following updates are done here:
049     *
050     * <ul>
051     * <li>Evaluate expressions on url object</li>
052     * </ul>
053     *
054     * {@inheritDoc}
055     */
056    @Override
057    public void performApplyModel(Object model, LifecycleElement parent) {
058        super.performApplyModel(model, parent);
059
060        View view = ViewLifecycle.getView();
061        if (url != null) {
062            Map<String, Object> context = new HashMap<String, Object>();
063
064            Map<String, Object> viewContext = view.getContext();
065            if (viewContext != null) {
066                context.putAll(viewContext);
067            }
068
069            ViewLifecycle.getExpressionEvaluator().populatePropertyExpressionsFromGraph(url, false);
070            ViewLifecycle.getExpressionEvaluator().evaluateExpressionsOnConfigurable(view, url, context);
071        }
072    }
073
074    /**
075     * The label for this breadcrumbItem.  The label is the textual content that will be displayed for the breadcrumb.
076     *
077     * @return the label
078     */
079    @BeanTagAttribute(name = "label")
080    public String getLabel() {
081        return label;
082    }
083
084    /**
085     * Set the label for this breadcrumbItem.  The label is the textual content that will be displayed for the
086     * breadcrumb.
087     *
088     * @param label
089     */
090    public void setLabel(String label) {
091        this.label = label;
092    }
093
094    /**
095     * The url used for the breadcrumb link represented by this item
096     *
097     * @return the url object
098     */
099    @BeanTagAttribute(name = "url")
100    public UrlInfo getUrl() {
101        return url;
102    }
103
104    /**
105     * Set the url object
106     *
107     * @param urlObject
108     */
109    public void setUrl(UrlInfo urlObject) {
110        this.url = urlObject;
111    }
112
113    /**
114     * Set the breadcrumb component for this breadcrumbs sibling content/navigation.  This content will appear in
115     * a pop-up menu.
116     *
117     * @return the sibling component to appear in a popup menu
118     */
119    @BeanTagAttribute(name = "siblingBreadcrumbComponent", type = BeanTagAttribute.AttributeType.SINGLEBEAN)
120    public Component getSiblingBreadcrumbComponent() {
121        return siblingBreadcrumbComponent;
122    }
123
124    /**
125     * Set the sibling breadcrumb component
126     *
127     * @param siblingBreadcrumbComponent
128     */
129    public void setSiblingBreadcrumbComponent(Component siblingBreadcrumbComponent) {
130        this.siblingBreadcrumbComponent = siblingBreadcrumbComponent;
131    }
132
133    /**
134     * If true, the breadcrumbItem will render as a link, otherwise it will render as a span (not-clickable).
135     * By default, the last BreadcrumbItem in the list will ALWAYS render as span regardless of this property's value.
136     *
137     * @return true if rendering as a link, false otherwise
138     */
139    @BeanTagAttribute(name = "renderAsLink")
140    public boolean isRenderAsLink() {
141        return renderAsLink;
142    }
143
144    /**
145     * Set to true to render as a link, false otherwise
146     *
147     * @param renderAsLink
148     */
149    public void setRenderAsLink(boolean renderAsLink) {
150        this.renderAsLink = renderAsLink;
151    }
152}