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.widget;
017
018import org.kuali.rice.krad.datadictionary.parse.BeanTag;
019import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
020import org.kuali.rice.krad.uif.component.ClientSideState;
021import org.kuali.rice.krad.uif.component.Component;
022import org.kuali.rice.krad.uif.util.LifecycleElement;
023
024/**
025 * Decorates a group with collapse/expand functionality
026 *
027 * @author Kuali Rice Team (rice.collab@kuali.org)
028 */
029@BeanTag(name = "disclosure", parent = "Uif-Disclosure")
030public class Disclosure extends WidgetBase {
031    private static final long serialVersionUID = 1238789480161901850L;
032
033    private String collapsedIconClass;
034    private String expandedIconClass;
035
036    private boolean renderIcon;
037
038    private int animationSpeed;
039
040    @ClientSideState(variableName = "open")
041    private boolean defaultOpen;
042    private boolean ajaxRetrievalWhenOpened;
043
044    public Disclosure() {
045        super();
046
047        defaultOpen = true;
048        renderIcon = true;
049    }
050
051    /**
052     * Sets forceSessionPersistence when using the ajax retrieval option
053     *
054     * {@inheritDoc}
055     */
056    @Override
057    public void performApplyModel(Object model, LifecycleElement parent) {
058        super.performApplyModel(model, parent);
059
060        if (parent instanceof Component && ajaxRetrievalWhenOpened) {
061            ((Component) parent).setForceSessionPersistence(true);
062        }
063    }
064
065    /**
066     * Class for the icon that should be rendered when the disclosure group is disclosed.
067     *
068     * <p>Note this is only applicable when {@link #isRenderIcon()} is true</p>
069     *
070     * @return class for collapsed icon
071     */
072    @BeanTagAttribute
073    public String getCollapsedIconClass() {
074        return collapsedIconClass;
075    }
076
077    /**
078     * Setter for {@link Disclosure#getCollapsedIconClass()}.
079     * 
080     * @param collapsedIconClass property value
081     */
082    public void setCollapsedIconClass(String collapsedIconClass) {
083        this.collapsedIconClass = collapsedIconClass;
084    }
085
086    /**
087     * Class for the icon that should be rendered when the disclosure group is expanded.
088     *
089     * <p>Note this is only applicable when {@link #isRenderIcon()} is true</p>
090     *
091     * @return class for expanded icon
092     */
093    @BeanTagAttribute
094    public String getExpandedIconClass() {
095        return expandedIconClass;
096    }
097
098    /**
099     * Setter for {@link Disclosure#getExpandedIconClass()}.
100     * 
101     * @param expandedIconClass property value
102     */
103    public void setExpandedIconClass(String expandedIconClass) {
104        this.expandedIconClass = expandedIconClass;
105    }
106
107    /**
108     * Indicates whether the expanded and collapsed icons should be rendered for the disclosure.
109     *
110     * @return boolean true if icons should be rendered, false if not
111     */
112    @BeanTagAttribute
113    public boolean isRenderIcon() {
114        return renderIcon;
115    }
116
117    /**
118     * Setter for {@link #isRenderIcon()}.
119     * 
120     * @param renderIcon property value
121     */
122    public void setRenderIcon(boolean renderIcon) {
123        this.renderIcon = renderIcon;
124    }
125
126    /**
127     * Gives the speed for the open/close animation, a smaller int will result
128     * in a faster animation
129     *
130     * @return animation speed
131     */
132    @BeanTagAttribute
133    public int getAnimationSpeed() {
134        return this.animationSpeed;
135    }
136
137    /**
138     * Setter for the open/close animation speed
139     *
140     * @param animationSpeed
141     */
142    public void setAnimationSpeed(int animationSpeed) {
143        this.animationSpeed = animationSpeed;
144    }
145
146    /**
147     * Indicates whether the group should be initially open
148     *
149     * @return true if group should be initially open, false if it
150     *         should be closed
151     */
152    @BeanTagAttribute
153    public boolean isDefaultOpen() {
154        return this.defaultOpen;
155    }
156
157    /**
158     * Setter for the default open indicator
159     *
160     * @param defaultOpen
161     */
162    public void setDefaultOpen(boolean defaultOpen) {
163        this.defaultOpen = defaultOpen;
164    }
165
166    /**
167     * When true, the group content will be retrieved when the disclosure is opened
168     *
169     * <p>This only works if by default, the disclosure is closed.</p>
170     *
171     * @return true if use ajax retrieval when disclosure opens, false otherwise
172     */
173    @BeanTagAttribute
174    public boolean isAjaxRetrievalWhenOpened() {
175        return ajaxRetrievalWhenOpened;
176    }
177
178    /**
179     * Set ajaxRetrievalWhenOpened
180     *
181     * @param ajaxRetrievalWhenOpened
182     */
183    public void setAjaxRetrievalWhenOpened(boolean ajaxRetrievalWhenOpened) {
184        this.ajaxRetrievalWhenOpened = ajaxRetrievalWhenOpened;
185    }
186}