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.widget;
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.ClientSideState;
21  import org.kuali.rice.krad.uif.component.Component;
22  import org.kuali.rice.krad.uif.util.LifecycleElement;
23  
24  /**
25   * Decorates a group with collapse/expand functionality
26   *
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  @BeanTag(name = "disclosure-bean", parent = "Uif-Disclosure")
30  public class Disclosure extends WidgetBase {
31      private static final long serialVersionUID = 1238789480161901850L;
32  
33      private String collapsedIconClass;
34      private String expandedIconClass;
35  
36      private boolean renderIcon;
37  
38      private int animationSpeed;
39  
40      @ClientSideState(variableName = "open")
41      private boolean defaultOpen;
42      private boolean ajaxRetrievalWhenOpened;
43  
44      public Disclosure() {
45          super();
46  
47          defaultOpen = true;
48          renderIcon = true;
49      }
50  
51      /**
52       * Sets forceSessionPersistence when using the ajax retrieval option
53       *
54       * {@inheritDoc}
55       */
56      @Override
57      public void performApplyModel(Object model, LifecycleElement parent) {
58          super.performApplyModel(model, parent);
59  
60          if (parent instanceof Component && ajaxRetrievalWhenOpened) {
61              ((Component) parent).setForceSessionPersistence(true);
62          }
63      }
64  
65      /**
66       * Class for the icon that should be rendered when the disclosure group is disclosed.
67       *
68       * <p>Note this is only applicable when {@link #isRenderIcon()} is true</p>
69       *
70       * @return class for collapsed icon
71       */
72      public String getCollapsedIconClass() {
73          return collapsedIconClass;
74      }
75  
76      /**
77       * Setter for {@link Disclosure#getCollapsedIconClass()}.
78       * 
79       * @param collapsedIconClass property value
80       */
81      public void setCollapsedIconClass(String collapsedIconClass) {
82          this.collapsedIconClass = collapsedIconClass;
83      }
84  
85      /**
86       * Class for the icon that should be rendered when the disclosure group is expanded.
87       *
88       * <p>Note this is only applicable when {@link #isRenderIcon()} is true</p>
89       *
90       * @return class for expanded icon
91       */
92      public String getExpandedIconClass() {
93          return expandedIconClass;
94      }
95  
96      /**
97       * Setter for {@link Disclosure#getExpandedIconClass()}.
98       * 
99       * @param expandedIconClass property value
100      */
101     public void setExpandedIconClass(String expandedIconClass) {
102         this.expandedIconClass = expandedIconClass;
103     }
104 
105     /**
106      * Indicates whether the expanded and collapsed icons should be rendered for the disclosure.
107      *
108      * @return boolean true if icons should be rendered, false if not
109      */
110     public boolean isRenderIcon() {
111         return renderIcon;
112     }
113 
114     /**
115      * Setter for {@link #isRenderIcon()}.
116      * 
117      * @param renderIcon property value
118      */
119     public void setRenderIcon(boolean renderIcon) {
120         
121         this.renderIcon = renderIcon;
122     }
123 
124     /**
125      * Gives the speed for the open/close animation, a smaller int will result
126      * in a faster animation
127      *
128      * @return animation speed
129      */
130     @BeanTagAttribute(name = "animationSpeed")
131     public int getAnimationSpeed() {
132         return this.animationSpeed;
133     }
134 
135     /**
136      * Setter for the open/close animation speed
137      *
138      * @param animationSpeed
139      */
140     public void setAnimationSpeed(int animationSpeed) {
141         this.animationSpeed = animationSpeed;
142     }
143 
144     /**
145      * Indicates whether the group should be initially open
146      *
147      * @return true if group should be initially open, false if it
148      *         should be closed
149      */
150     @BeanTagAttribute(name = "defaultOpen")
151     public boolean isDefaultOpen() {
152         return this.defaultOpen;
153     }
154 
155     /**
156      * Setter for the default open indicator
157      *
158      * @param defaultOpen
159      */
160     public void setDefaultOpen(boolean defaultOpen) {
161         this.defaultOpen = defaultOpen;
162     }
163 
164     /**
165      * When true, the group content will be retrieved when the disclosure is opened
166      *
167      * <p>This only works if by default, the disclosure is closed.</p>
168      *
169      * @return true if use ajax retrieval when disclosure opens, false otherwise
170      */
171     public boolean isAjaxRetrievalWhenOpened() {
172         return ajaxRetrievalWhenOpened;
173     }
174 
175     /**
176      * Set ajaxRetrievalWhenOpened
177      *
178      * @param ajaxRetrievalWhenOpened
179      */
180     public void setAjaxRetrievalWhenOpened(boolean ajaxRetrievalWhenOpened) {
181         this.ajaxRetrievalWhenOpened = ajaxRetrievalWhenOpened;
182     }
183 }