View Javadoc
1   /**
2    * Copyright 2005-2016 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", 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      @BeanTagAttribute
73      public String getCollapsedIconClass() {
74          return collapsedIconClass;
75      }
76  
77      /**
78       * Setter for {@link Disclosure#getCollapsedIconClass()}.
79       * 
80       * @param collapsedIconClass property value
81       */
82      public void setCollapsedIconClass(String collapsedIconClass) {
83          this.collapsedIconClass = collapsedIconClass;
84      }
85  
86      /**
87       * Class for the icon that should be rendered when the disclosure group is expanded.
88       *
89       * <p>Note this is only applicable when {@link #isRenderIcon()} is true</p>
90       *
91       * @return class for expanded icon
92       */
93      @BeanTagAttribute
94      public String getExpandedIconClass() {
95          return expandedIconClass;
96      }
97  
98      /**
99       * 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 }