View Javadoc

1   /**
2    * Copyright 2005-2015 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.control;
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.datadictionary.validator.ErrorReport;
21  import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
22  import org.kuali.rice.krad.uif.component.Component;
23  import org.kuali.rice.krad.uif.element.Message;
24  import org.kuali.rice.krad.uif.util.ComponentFactory;
25  import org.kuali.rice.krad.uif.view.View;
26  
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  /**
31   * Represents a HTML Checkbox control. Typically used for boolean attributes (where the
32   * value is either on/off, true/false)
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  @BeanTag(name = "checkboxControl-bean", parent = "Uif-CheckboxControl")
37  public class CheckboxControl extends ControlBase implements ValueConfiguredControl {
38      private static final long serialVersionUID = -1397028958569144230L;
39  
40      private String value;
41      private String checkboxLabel;
42  
43      private Message richLabelMessage;
44      private List<Component> inlineComponents;
45  
46      public CheckboxControl() {
47          super();
48      }
49  
50      /**
51       * Sets up rich message content for the label, if any exists
52       *
53       * @see Component#performApplyModel(org.kuali.rice.krad.uif.view.View, Object, org.kuali.rice.krad.uif.component.Component)
54       */
55      @Override
56      public void performApplyModel(View view, Object model, Component parent) {
57          super.performApplyModel(view, model, parent);
58  
59          if (richLabelMessage == null) {
60              Message message = ComponentFactory.getMessage();
61              view.assignComponentIds(message);
62              message.setMessageText(checkboxLabel);
63              message.setInlineComponents(inlineComponents);
64              message.setGenerateSpan(false);
65              view.getViewHelperService().performComponentInitialization(view, model, message);
66              this.setRichLabelMessage(message);
67          }
68      }
69  
70      /**
71       * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
72       */
73      @Override
74      public List<Component> getComponentsForLifecycle() {
75          List<Component> components = super.getComponentsForLifecycle();
76  
77          components.add(richLabelMessage);
78  
79          return components;
80      }
81  
82      /**
83       * The value that will be submitted when the checkbox control is checked
84       *
85       * <p>
86       * Value can be left blank, in which case the checkbox will submit a boolean value that
87       * will populate a boolean property. In cases where the checkbox needs to submit another value (for
88       * instance possibly in the checkbox group) the value can be set which will override the default.
89       * </p>
90       *
91       * @return value for checkbox
92       */
93      @BeanTagAttribute(name="value")
94      public String getValue() {
95          return value;
96      }
97  
98      /**
99       * Setter for the value that should be submitted when the checkbox is checked
100      *
101      * @param value
102      */
103     public void setValue(String value) {
104         this.value = value;
105     }
106 
107     /**
108      * Returns the label text for this checkbox
109      *
110      * @return the checkbox label text
111      */
112     @BeanTagAttribute(name="checkboxLabel")
113     public String getCheckboxLabel() {
114         return checkboxLabel;
115     }
116 
117     /**
118      * Sets the label text for this checkbox
119      *
120      * @param checkboxLabel the label text
121      */
122     public void setCheckboxLabel(String checkboxLabel) {
123         this.checkboxLabel = checkboxLabel;
124     }
125 
126     /**
127      * Gets the Message that represents the rich message content of the label if labelText is using rich message tags.
128      * <b>DO NOT set this
129      * property directly unless you need full control over the message structure.</b>
130      *
131      * @return Message with rich message structure, null if no rich message structure
132      */
133     @BeanTagAttribute(name="richLabelMessage",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
134     public Message getRichLabelMessage() {
135         return richLabelMessage;
136     }
137 
138     /**
139      * Sets the Message that represents the rich message content of the label if it is using rich message tags.  <b>DO
140      * NOT set this
141      * property directly unless you need full control over the message structure.</b>
142      *
143      * @param richLabelMessage
144      */
145     public void setRichLabelMessage(Message richLabelMessage) {
146         this.richLabelMessage = richLabelMessage;
147     }
148 
149     /**
150      * Gets the inlineComponents used by index in the checkboxLabel that has rich message component index tags
151      *
152      * @return the Label's inlineComponents
153      */
154     @BeanTagAttribute(name="inlineComponents",type= BeanTagAttribute.AttributeType.LISTBEAN)
155     public List<Component> getInlineComponents() {
156         return inlineComponents;
157     }
158 
159     /**
160      * Sets the inlineComponents used by index in the checkboxLabel that has rich message component index tags
161      *
162      * @param inlineComponents
163      */
164     public void setInlineComponents(List<Component> inlineComponents) {
165         this.inlineComponents = inlineComponents;
166     }
167 
168     /**
169      * @see org.kuali.rice.krad.uif.component.ComponentBase#copy()
170      */
171     @Override
172     protected <T> void copyProperties(T component) {
173         super.copyProperties(component);
174         CheckboxControl checkboxControlCopy = (CheckboxControl) component;
175         checkboxControlCopy.setValue(this.value);
176         checkboxControlCopy.setCheckboxLabel(this.checkboxLabel);
177 
178         if (this.richLabelMessage != null) {
179             checkboxControlCopy.setRichLabelMessage((Message)this.richLabelMessage.copy());
180         }
181 
182         if(inlineComponents != null) {
183             List<Component> inlineComponentsCopy = new ArrayList<Component>();
184             for(Component inlineComponent : inlineComponents)   {
185                 inlineComponentsCopy.add((Component)inlineComponent.copy());
186             }
187             checkboxControlCopy.setInlineComponents(inlineComponentsCopy);
188         }
189     }
190 
191     /**
192      * @see org.kuali.rice.krad.uif.component.Component#completeValidation
193      */
194     @Override
195     public void completeValidation(ValidationTrace tracer){
196         tracer.addBean(this);
197 
198         super.completeValidation(tracer.getCopy());
199     }
200 }