001 /**
002 * Copyright 2005-2014 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 */
016 package org.kuali.rice.krad.uif.widget;
017
018 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
019 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
020 import org.kuali.rice.krad.uif.component.ClientSideState;
021 import org.kuali.rice.krad.uif.component.Component;
022 import org.kuali.rice.krad.uif.view.View;
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-bean", parent = "Uif-Disclosure")
030 public class Disclosure extends WidgetBase {
031 private static final long serialVersionUID = 1238789480161901850L;
032
033 private String collapseImageSrc;
034 private String expandImageSrc;
035
036 private int animationSpeed;
037
038 @ClientSideState(variableName = "open")
039 private boolean defaultOpen;
040 private boolean ajaxRetrievalWhenOpened;
041
042 private boolean renderImage;
043
044 public Disclosure() {
045 super();
046
047 defaultOpen = true;
048 renderImage = true;
049
050 }
051
052 /**
053 * Sets forceSessionPersistence when using the ajax retrieval option
054 *
055 * @see Component#performApplyModel(org.kuali.rice.krad.uif.view.View, Object, org.kuali.rice.krad.uif.component.Component)
056 */
057 @Override
058 public void performApplyModel(View view, Object model, Component parent) {
059 super.performFinalize(view, model, parent);
060
061 if(ajaxRetrievalWhenOpened){
062 parent.setForceSessionPersistence(true);
063 }
064 }
065
066 /**
067 * Path to the images that should be displayed to collapse the group
068 *
069 * @return image path
070 */
071 @BeanTagAttribute(name="CollapseImageSrc")
072 public String getCollapseImageSrc() {
073 return this.collapseImageSrc;
074 }
075
076 /**
077 * Setter for the collapse image path
078 *
079 * @param collapseImageSrc
080 */
081 public void setCollapseImageSrc(String collapseImageSrc) {
082 this.collapseImageSrc = collapseImageSrc;
083 }
084
085 /**
086 * Path to the images that should be displayed to expand the group
087 *
088 * @return image path
089 */
090 @BeanTagAttribute(name="expandImageSrc")
091 public String getExpandImageSrc() {
092 return this.expandImageSrc;
093 }
094
095 /**
096 * Setter for the expand image path
097 *
098 * @param expandImageSrc
099 */
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 }