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.view.View;
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 collapseImageSrc;
34      private String expandImageSrc;
35  
36      private int animationSpeed;
37  
38      @ClientSideState(variableName = "open")
39      private boolean defaultOpen;
40      private boolean ajaxRetrievalWhenOpened;
41  
42      private boolean renderImage;
43  
44      public Disclosure() {
45          super();
46  
47          defaultOpen = true;
48          renderImage = true;
49  
50      }
51  
52      /**
53       * Sets forceSessionPersistence when using the ajax retrieval option
54       *
55       * @see Component#performApplyModel(org.kuali.rice.krad.uif.view.View, Object, org.kuali.rice.krad.uif.component.Component)
56       */
57      @Override
58      public void performApplyModel(View view, Object model, Component parent) {
59          super.performFinalize(view, model, parent);
60  
61          if(ajaxRetrievalWhenOpened){
62              parent.setForceSessionPersistence(true);
63          }
64      }
65  
66      /**
67       * Path to the images that should be displayed to collapse the group
68       *
69       * @return image path
70       */
71      @BeanTagAttribute(name="CollapseImageSrc")
72      public String getCollapseImageSrc() {
73          return this.collapseImageSrc;
74      }
75  
76      /**
77       * Setter for the collapse image path
78       *
79       * @param collapseImageSrc
80       */
81      public void setCollapseImageSrc(String collapseImageSrc) {
82          this.collapseImageSrc = collapseImageSrc;
83      }
84  
85      /**
86       * Path to the images that should be displayed to expand the group
87       *
88       * @return image path
89       */
90      @BeanTagAttribute(name="expandImageSrc")
91      public String getExpandImageSrc() {
92          return this.expandImageSrc;
93      }
94  
95      /**
96       * Setter for the expand image path
97       *
98       * @param expandImageSrc
99       */
100     public void setExpandImageSrc(String expandImageSrc) {
101         this.expandImageSrc = expandImageSrc;
102     }
103 
104     /**
105      * Gives the speed for the open/close animation, a smaller int will result
106      * in a faster animation
107      *
108      * @return animation speed
109      */
110     @BeanTagAttribute(name="animationSpeed")
111     public int getAnimationSpeed() {
112         return this.animationSpeed;
113     }
114 
115     /**
116      * Setter for the open/close animation speed
117      *
118      * @param animationSpeed
119      */
120     public void setAnimationSpeed(int animationSpeed) {
121         this.animationSpeed = animationSpeed;
122     }
123 
124     /**
125      * Indicates whether the group should be initially open
126      *
127      * @return true if group should be initially open, false if it
128      *         should be closed
129      */
130     @BeanTagAttribute(name="defaultOpen")
131     public boolean isDefaultOpen() {
132         return this.defaultOpen;
133     }
134 
135     /**
136      * Setter for the default open indicator
137      *
138      * @param defaultOpen
139      */
140     public void setDefaultOpen(boolean defaultOpen) {
141         this.defaultOpen = defaultOpen;
142     }
143 
144     /**
145      * When true, the group content will be retrieved when the disclosure is opened
146      *
147      * <p>This only works if by default, the disclosure is closed.</p>
148      *
149      * @return true if use ajax retrieval when disclosure opens, false otherwise
150      */
151     public boolean isAjaxRetrievalWhenOpened() {
152         return ajaxRetrievalWhenOpened;
153     }
154 
155     /**
156      * Set ajaxRetrievalWhenOpened
157      *
158      * @param ajaxRetrievalWhenOpened
159      */
160     public void setAjaxRetrievalWhenOpened(boolean ajaxRetrievalWhenOpened) {
161         this.ajaxRetrievalWhenOpened = ajaxRetrievalWhenOpened;
162     }
163 
164     /**
165      * Indicates whether the expand/collapse image should be rendered for the closure, if set to false only
166      * the group title will be clickable
167      *
168      * @return true to render the expand/colapse image false to not
169      */
170     @BeanTagAttribute(name="renderImage")
171     public boolean isRenderImage() {
172         return renderImage;
173     }
174 
175     /**
176      * Setter for the render expand/collapse image indicator
177      *
178      * @param renderImage
179      */
180     public void setRenderImage(boolean renderImage) {
181         this.renderImage = renderImage;
182     }
183 
184     /**
185      * @see org.kuali.rice.krad.uif.component.ComponentBase#copy()
186      */
187     @Override
188     protected <T> void copyProperties(T component) {
189         super.copyProperties(component);
190         Disclosure disclosureCopy = (Disclosure) component;
191         disclosureCopy.setAnimationSpeed(this.animationSpeed);
192         disclosureCopy.setCollapseImageSrc(this.collapseImageSrc);
193         disclosureCopy.setDefaultOpen(this.defaultOpen);
194         disclosureCopy.setAjaxRetrievalWhenOpened(this.ajaxRetrievalWhenOpened);
195         disclosureCopy.setExpandImageSrc(this.expandImageSrc);
196         disclosureCopy.setRenderImage(this.renderImage);
197     }
198 }