View Javadoc

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