Coverage Report - org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement
 
Classes in this File Line Coverage Branch Coverage Complexity
FieldElement
0%
0/241
0%
0/130
2.595
FieldElement$1
0%
0/1
N/A
2.595
FieldElement$LineNum
0%
0/1
N/A
2.595
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.common.ui.client.widgets.field.layout.element;
 17  
 
 18  
 import org.kuali.student.common.ui.client.application.Application;
 19  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.ValidationMessagePanel;
 20  
 import org.kuali.student.common.ui.client.widgets.HasInputWidget;
 21  
 import org.kuali.student.common.ui.client.widgets.HasWatermark;
 22  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 23  
 import org.kuali.student.common.ui.client.widgets.KSTitleDescPanel;
 24  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.AbbrButton.AbbrButtonType;
 25  
 import org.kuali.student.common.ui.client.widgets.field.layout.layouts.FieldLayoutComponent;
 26  
 import org.kuali.student.common.validation.dto.ValidationResultInfo;
 27  
 import org.kuali.student.common.validation.dto.ValidationResultInfo.ErrorLevel;
 28  
 
 29  
 import com.google.gwt.user.client.Element;
 30  
 import com.google.gwt.user.client.ui.Composite;
 31  
 import com.google.gwt.user.client.ui.FlowPanel;
 32  
 import com.google.gwt.user.client.ui.HTMLPanel;
 33  
 import com.google.gwt.user.client.ui.Panel;
 34  
 import com.google.gwt.user.client.ui.Widget;
 35  
 
 36  
 /**
 37  
  * A ui field element.  Areas which contain a field for user data entry should use
 38  
  * this class for visual and behavior consistency.  Used by FieldDescriptor for its layout.
 39  
  * 
 40  
  * General layout of a field element, all elements are conditional based on the field's
 41  
  * configuration through set methods on this class: <br>
 42  
  * <b>[label][requiredness indicator][help]<br>
 43  
  * [input widget]<br>
 44  
  * [constraint text]<br></b>
 45  
  * <br>
 46  
  * 
 47  
  * The messageKeyInfo passed in is used to generate the messages needed for a field these include:<br>
 48  
  * Field Label<br>
 49  
  * Help text<br>
 50  
  * Instructions<br>
 51  
  * Constraint text<br>
 52  
  * Watermark text - only if the widget one that accepts text input<br><br>
 53  
  * These are generated by the single key, the additional text is determined by special suffixes on keys within
 54  
  * the messages data - example - you pass in "sampleField" for the message key - it is automatically determined
 55  
  * that if there is a message in the messages data named "sampleField-instruct", instructions will be added to the field
 56  
  * in the appropriate location.<br>
 57  
  * List of the appended keys for use in messages data:<br>
 58  
  * "-help" for help text<br>
 59  
  * "-instruct" for instructions<br>
 60  
  * "-constraints" for constraint text<br>
 61  
  * "-watermark" for watermark text<br>
 62  
  * 
 63  
  * @author Kuali Student Team
 64  
  * @see FieldDescriptor
 65  
  * @see FieldLayout
 66  
  */
 67  
 public class FieldElement extends Composite implements FieldLayoutComponent{
 68  
 
 69  
         //Layout
 70  0
         private KSTitleDescPanel titlePanel = new KSTitleDescPanel();
 71  0
         private FlowPanel layout = new FlowPanel();
 72  
         private FieldTitle fieldTitle;
 73  0
         private SpanPanel instructions = new SpanPanel();
 74  0
         private SpanPanel constraints = new SpanPanel();
 75  0
         private AbbrPanel required = new AbbrPanel("Required", "ks-form-module-elements-required", " * ");
 76  0
         private AbbrButton help = new AbbrButton(AbbrButtonType.HELP);
 77  
         private Widget fieldWidget;
 78  0
         private SpanPanel widgetSpan = new SpanPanel();
 79  
         private String fieldHTMLId;
 80  0
         private String watermarkText = null;
 81  0
         public static enum LineNum{SINGLE, DOUBLE, TRIPLE}
 82  
 
 83  
         private ValidationMessagePanel validationPanel;
 84  
         private String fieldKey;
 85  0
         private boolean labelShown = true;
 86  
         
 87  
         private Panel parentPanel;
 88  
         private Element parentElement;
 89  
         
 90  0
         private ErrorLevel status = ErrorLevel.OK;
 91  
         
 92  
 
 93  
         /**
 94  
          * Sets this field's validation panel, note that this does not add it to the ui.  Attaching must be done
 95  
          * elsewhere.  Most FieldLayout implementations handle this attachment.
 96  
          * @param validationPanel
 97  
          */
 98  
         public void setValidationPanel(ValidationMessagePanel validationPanel) {
 99  0
                 this.validationPanel = validationPanel;
 100  0
         }
 101  
 
 102  
 
 103  
         public Panel getParentPanel() {
 104  0
                 return parentPanel;
 105  
         }
 106  
 
 107  
         public void setParentPanel(Panel parentPanel) {
 108  0
                 this.parentPanel = parentPanel;
 109  0
                 this.parentElement = parentPanel.getElement();
 110  0
         }
 111  
 
 112  
         public void setParentElement(Element element){
 113  0
                 parentElement = element;
 114  0
         }
 115  
 
 116  
         private String fieldName;
 117  
         private String instructionText;
 118  
 
 119  
     public String getInstructionText() {
 120  0
                 return instructionText;
 121  
         }
 122  
 
 123  0
         public FieldElement(String title, Widget widget) {
 124  0
             generateLayout(title, title, null, null, null, widget);
 125  
 
 126  0
     }
 127  
 
 128  0
     public FieldElement(String key, String title, Widget widget){
 129  0
             generateLayout(key, title, null, null, null, widget);
 130  0
     }
 131  
 
 132  
     /**
 133  
      * Standard constructor for FieldElement
 134  
      * @param key unique key to identify this field
 135  
      * @param info key for the messages used in this field element - see class description
 136  
      */
 137  0
     public FieldElement(String key, MessageKeyInfo info){
 138  0
             init(key, info, null);
 139  0
     }
 140  
 
 141  
     /**
 142  
      * Standard constructor for FieldElement
 143  
      * @param key unique key to identify this field
 144  
      * @param info key for the messages used in this field element - see class description
 145  
      * @param widget widget used for input/display on this field
 146  
      */
 147  0
     public FieldElement(String key, MessageKeyInfo info, Widget widget){
 148  0
             init(key, info, widget);
 149  
 
 150  0
     }
 151  
     
 152  
     private void init(String key, MessageKeyInfo info, Widget widget){
 153  0
             String title = Application.getApplicationContext().getUILabel(info.getGroup(), info.getType(), info.getState(), info.getId());
 154  
             
 155  0
             String help = Application.getApplicationContext().getUILabel(info.getGroup(), info.getType(), info.getState(),
 156  
                             info.getId() + HELP_MESSAGE_KEY);
 157  0
             if(help.equals(info.getId() + HELP_MESSAGE_KEY)){
 158  0
                     help = null;
 159  
             }
 160  
             
 161  0
             String instructions = Application.getApplicationContext().getUILabel(info.getGroup(), info.getType(), info.getState(),
 162  
                             info.getId() + INSTRUCT_MESSAGE_KEY);
 163  0
             if(instructions.equals(info.getId() + INSTRUCT_MESSAGE_KEY)){
 164  0
                     instructions = null;
 165  
             }
 166  
             
 167  0
             String constraints = Application.getApplicationContext().getUILabel(info.getGroup(), info.getType(), info.getState(),
 168  
                             info.getId() + CONSTRAINT_MESSAGE_KEY);
 169  0
             if(constraints.equals(info.getId() + CONSTRAINT_MESSAGE_KEY)){
 170  0
                     constraints = null;
 171  
             }
 172  
             
 173  0
             watermarkText = Application.getApplicationContext().getUILabel(info.getGroup(), info.getType(), info.getState(),
 174  
                             info.getId() + WATERMARK_MESSAGE_KEY);
 175  0
             if(watermarkText.equals(info.getId() + WATERMARK_MESSAGE_KEY)){
 176  0
                     watermarkText = null;
 177  
             }
 178  
             
 179  0
             generateLayout(key, title, help, instructions, constraints, widget);
 180  0
     }
 181  
 
 182  
     private void generateLayout(String key, String title, String helpText, String instructText, String constraintText, Widget widget){
 183  0
             this.setKey(key);
 184  0
                 fieldName = title;
 185  
 
 186  0
                 fieldHTMLId = HTMLPanel.createUniqueId();
 187  0
                 fieldTitle = new LabelPanel(title, fieldHTMLId);
 188  
 
 189  0
                 required.setVisible(false);
 190  0
                 fieldTitle.add(required);
 191  0
                 if(helpText != null){
 192  0
                         this.setHelp(helpText);
 193  
                 }
 194  
                 else{
 195  0
                         help.setVisible(false);
 196  
                 }
 197  
 
 198  0
                 fieldTitle.add(help);
 199  0
                 layout.add(fieldTitle);
 200  0
                 if(instructText != null){
 201  0
                         this.setInstructions(instructText);
 202  
                 }
 203  
                 else{
 204  0
                         instructions.setVisible(false);
 205  
                 }
 206  
                 
 207  0
                 if(constraintText != null){
 208  0
                         this.setConstraintText(constraintText);
 209  
                 }
 210  
                 else{
 211  0
                         constraints.setVisible(false);
 212  
                 }
 213  0
                 instructions.setStyleName("ks-form-module-elements-instruction");
 214  0
                 layout.add(instructions);
 215  0
                 layout.add(widgetSpan);
 216  0
                 if(widget != null){
 217  0
                         this.setWidget(widget);
 218  
                 }
 219  0
                 constraints.setStyleName("ks-form-module-elements-help-text");
 220  0
                 layout.add(constraints);
 221  
 
 222  
 
 223  0
         initWidget(layout);
 224  0
         layout.addStyleName("ks-form-module-elements");
 225  0
         layout.addStyleName("ks-form-module-single-line-margin");
 226  0
     }
 227  
 
 228  
     /**
 229  
      * Sets the widget for this field, automatically adds an id which will match this field's label-for tag in
 230  
      * its label
 231  
      * @see com.google.gwt.user.client.ui.Composite#setWidget(com.google.gwt.user.client.ui.Widget)
 232  
      */
 233  
     public void setWidget(Widget w){
 234  0
             if(fieldWidget != null){
 235  0
                     widgetSpan.remove(fieldWidget);
 236  
             }
 237  0
             fieldWidget = w;
 238  
             //TODO Do a check here to change the type of label based on widget type eventually
 239  0
             if(fieldWidget != null){
 240  
                     
 241  
                     //Checks for input widgets that may be incased in a more complex widget layout
 242  0
                     if(fieldWidget instanceof HasInputWidget){
 243  0
                             Widget input = ((HasInputWidget)fieldWidget).getInputWidget();
 244  0
                             if(input != null){
 245  0
                                     if(input instanceof HasWatermark && watermarkText != null){
 246  0
                                             ((HasWatermark)input).setWatermarkText(watermarkText);
 247  
                                     }
 248  0
                                     input.getElement().setAttribute("id", fieldHTMLId);
 249  
                             }
 250  
                             else{
 251  0
                                     fieldWidget.getElement().setAttribute("id", fieldHTMLId);
 252  
                             }
 253  0
                     }
 254  
                     else{
 255  0
                         if(fieldWidget instanceof HasWatermark && watermarkText != null){
 256  0
                                 ((HasWatermark)fieldWidget).setWatermarkText(watermarkText);
 257  
                         }
 258  0
                             fieldWidget.getElement().setAttribute("id", fieldHTMLId);
 259  
                     }
 260  
                     
 261  0
                     widgetSpan.add(fieldWidget);
 262  
             }
 263  0
     }
 264  
     
 265  
     /**
 266  
      * Sets the required string key to be used for when a field is required.  For example, in most cases this
 267  
      * key maps to a "*"
 268  
      * 
 269  
      * @param requiredKey
 270  
      */
 271  
     public void setRequiredString(String requiredKey){
 272  0
             String requiredText = Application.getApplicationContext().getMessage(requiredKey);
 273  0
             required.setText(requiredText);
 274  0
             required.setVisible(true);
 275  0
     }
 276  
     
 277  
     public void setRequiredString(String requiredKey, String style){
 278  0
             String requiredText = Application.getApplicationContext().getMessage(requiredKey);
 279  0
             required.setText(requiredText);
 280  0
             required.setStyleName(style);
 281  0
             required.setVisible(true);
 282  0
     }
 283  
 
 284  
     public AbbrPanel getRequiredPanel(){
 285  0
             return required;
 286  
     }
 287  
     
 288  
     public void clearRequiredText(){
 289  0
         required.setText("");
 290  0
     }
 291  
 
 292  
     public Widget getFieldWidget(){
 293  0
             return fieldWidget;
 294  
     }
 295  
 
 296  
     public FlowPanel getFieldDetailsLayout(){
 297  0
             FlowPanel div = new FlowPanel();
 298  0
                 div.add(fieldTitle);
 299  0
                 div.add(instructions);
 300  0
                 div.addStyleName("ks-form-module-elements");
 301  0
                 return div;
 302  
     }
 303  
 
 304  
     public FlowPanel getFieldWidgetAreaLayout(){
 305  0
             FlowPanel div = new FlowPanel();
 306  0
             div.add(fieldWidget);
 307  0
             div.add(constraints);
 308  0
             div.addStyleName("ks-form-module-elements");
 309  0
             return div;
 310  
     }
 311  
     
 312  
     public boolean isRequired() {
 313  0
         return required.isVisible();
 314  
     }
 315  
 
 316  
     public void setRequired(boolean isRequired){
 317  0
             required.setVisible(isRequired);
 318  0
     }
 319  
 
 320  
     public void setInstructions(String text){
 321  0
             instructionText = text;
 322  0
             if(instructionText != null && !instructionText.trim().equals("")){
 323  0
                     instructions.setHTML(text);
 324  0
                     instructions.setVisible(true);
 325  
             }
 326  0
     }
 327  
 
 328  
     public void setConstraintText(String text){
 329  0
             if(text != null && !text.trim().equals("")){
 330  0
                     constraints.setHTML(text);
 331  0
                     constraints.setVisible(true);
 332  
             }
 333  0
     }
 334  
 
 335  
     public void setHelp(final String html){
 336  0
             if(html != null && !html.trim().equals("")){
 337  0
                     help.setVisible(true);
 338  0
                     help.setHoverHTML(html);
 339  
                     /*help.addClickHandler(new ClickHandler(){
 340  
 
 341  
                                 @Override
 342  
                                 public void onClick(ClickEvent event) {
 343  
                                         //TODO show actual help window
 344  
                                         Window.alert(html);
 345  
 
 346  
                                 }
 347  
                         });*/
 348  
             }
 349  
             else{
 350  0
                     help.setVisible(false);
 351  
             }
 352  0
     }
 353  
 
 354  
         public Widget getTitleWidget() {
 355  0
             return titlePanel.getTitleWidget();
 356  
         }
 357  
 
 358  
         public ValidationMessagePanel getValidationPanel() {
 359  0
                 return validationPanel;
 360  
         }
 361  
 
 362  
         public Panel getEncapsulatingPanel() {
 363  0
                 return parentPanel;
 364  
         }
 365  
 
 366  
         public String getFieldName() {
 367  0
                 return fieldName;
 368  
         }
 369  
 
 370  
         /**
 371  
          * Turn on/off styling for errors on field element
 372  
          * 
 373  
          * @param error When true turns on error styling, when false turns off error styling
 374  
          */
 375  
         public void setErrorState(boolean error){
 376  0
                 if(error){
 377  0
                         fieldTitle.addStyleName("invalid");
 378  0
                         if(parentPanel != null){
 379  0
                                 parentPanel.addStyleName("error");
 380  
                         }
 381  0
                         else if(parentElement != null){
 382  0
                                 parentElement.setClassName("error");
 383  
                         }
 384  
                         //When there is an error, don't use warning style
 385  0
                         setWarnState(false);
 386  
                 }
 387  
                 else{
 388  0
                         fieldTitle.removeStyleName("invalid");
 389  0
                         if(parentPanel != null){
 390  0
                                 parentPanel.removeStyleName("error");
 391  
                         }
 392  0
                         else if(parentElement != null){
 393  0
                                 parentElement.setClassName("");
 394  
                         }
 395  
                         //Reset earn state, in case there are warnings
 396  0
                         setWarnState(validationPanel.hasWarnings());
 397  
                 }
 398  0
         }
 399  
         
 400  
         /**
 401  
          * Turn on/off styling for warnings on field element
 402  
          * 
 403  
          * @param warn When true turns on warning styling, when false turns off warning styling
 404  
          */
 405  
         public void setWarnState(boolean warn){
 406  0
                 if(warn){
 407  
                         //fieldTitle.addStyleName("invalid");
 408  0
                         if(parentPanel != null){
 409  0
                                 parentPanel.addStyleName("warning");
 410  
                         }
 411  0
                         else if(parentElement != null){
 412  0
                                 parentElement.setClassName("warning");
 413  
                         }
 414  
 
 415  
                 }
 416  
                 else{
 417  
                         //fieldTitle.removeStyleName("invalid");
 418  0
                         if(parentPanel != null){
 419  0
                                 parentPanel.removeStyleName("warning");
 420  
                         }
 421  0
                         else if(parentElement != null){
 422  0
                                 parentElement.setClassName("");
 423  
                         }
 424  
                 }
 425  0
         }
 426  
         
 427  
 
 428  
         /**
 429  
          * Processes a validation result and adds an appropriate message, if needed
 430  
          * @param vr
 431  
          * @return
 432  
          */
 433  
         public ErrorLevel processValidationResult(ValidationResultInfo vr) {
 434  
                 //Check if this field is responsible for processing its own validation results
 435  0
                 if(getFieldWidget() instanceof ValidationProcessable){
 436  0
                         if(((ValidationProcessable)getFieldWidget()).shouldProcessValidationResult(vr)){
 437  0
                                 if (fieldName != null && fieldName.trim() != "")
 438  0
                                         return ((ValidationProcessable)getFieldWidget()).processValidationResult(vr, fieldName);
 439  
                                 else        
 440  0
                                         return ((ValidationProcessable)getFieldWidget()).processValidationResult(vr);
 441  
                         }
 442  
                 }
 443  
                 
 444  0
                 status = ErrorLevel.OK;
 445  
 
 446  0
                 if(vr.getLevel() == ErrorLevel.ERROR){
 447  0
                         String message = Application.getApplicationContext().getUILabel("validation", vr.getMessage());
 448  0
                         this.addValidationErrorMessage(message);
 449  
                         
 450  0
                         if(status.getLevel() < ErrorLevel.ERROR.getLevel()){
 451  0
                                 status = vr.getLevel();
 452  
                         }
 453  0
                 }
 454  0
                 else if(vr.getLevel() == ErrorLevel.WARN){
 455  0
                         String message = Application.getApplicationContext().getUILabel("validation", vr.getMessage());
 456  0
                         this.addValidationWarningMessage(message);
 457  
                         
 458  0
                         if(status.getLevel() < ErrorLevel.WARN.getLevel()){
 459  0
                                 status = vr.getLevel();                        
 460  
                         }
 461  
                 }
 462  
                 else{
 463  
                         //TODO does nothing on ok, ok is not currently used
 464  
                 }
 465  0
                 return status;
 466  
         }
 467  
 
 468  
         /**
 469  
          * Add a validation message to this fields validation panel as defined by setValidationPanel.
 470  
          * @param text
 471  
          */
 472  
         public void addValidationErrorMessage(String text){
 473  0
                 if(validationPanel != null){
 474  
                         KSLabel message;
 475  0
                         if(fieldName != null && !fieldName.trim().equals("")){
 476  0
                                 message = new KSLabel(fieldName + " - " + text);
 477  
                         }
 478  
                         else{
 479  0
                                 message = new KSLabel(text);
 480  
                         }
 481  0
                         message.setStyleName("ks-form-error-label");
 482  0
                         this.setErrorState(true);
 483  0
                         this.validationPanel.addErrorMessage(message);
 484  
                 }
 485  0
         }
 486  
 
 487  
         /**
 488  
          * Add a validation message to this fields validation panel as defined by setValidationPanel.
 489  
          * @param text
 490  
          */
 491  
         public void addValidationWarningMessage(String text){
 492  0
                 if(validationPanel != null){
 493  0
                         SpanPanel message = new SpanPanel();
 494  0
                         if(fieldName != null && !fieldName.trim().equals("")){
 495  0
                                 message.setHTML("<b> Warning </b> " + fieldName + " - " + text);
 496  
                         }
 497  
                         else{
 498  0
                                 message.setHTML("<b> Warning </b> " + text);
 499  
                         }
 500  0
                         message.setStyleName("ks-form-warn-label");
 501  
                         //Only set field styling to warn, when no errors
 502  0
                         this.setWarnState((status != ErrorLevel.ERROR));
 503  0
                         this.validationPanel.addWarnMessage(message);
 504  
                 }
 505  0
         }
 506  
 
 507  
         /**
 508  
          * Clears validation error and highlighting that may exist on this panel or widget
 509  
          */
 510  
         public void clearValidationErrors(){
 511  0
                 this.setErrorState(false);
 512  0
                 if(validationPanel != null){
 513  0
                         this.validationPanel.clearErrors();
 514  
                 }
 515  
                 
 516  
                 //Clear errors on widget if widget responsible for its own errors
 517  0
                 if(getFieldWidget() instanceof ValidationProcessable){
 518  0
                         ((ValidationProcessable)getFieldWidget()).clearValidationErrors();
 519  
                 }
 520  0
         }
 521  
 
 522  
         /**
 523  
          * Clears validation warnings and highlighting that may exist on this panel or widget
 524  
          */
 525  
         public void clearValidationWarnings(){
 526  0
                 this.setWarnState(false);
 527  0
                 if(validationPanel != null){
 528  0
                         this.validationPanel.clearWarnings();
 529  
                 }                                
 530  
                 
 531  
                 //Clear warnings on widget if widget responsible for its own warnings
 532  0
                 if(getFieldWidget() instanceof ValidationProcessable){
 533  0
                         ((ValidationProcessable)getFieldWidget()).clearValidationWarnings();
 534  
                 }
 535  0
         }
 536  
 
 537  
         @Override
 538  
         public String getKey() {
 539  0
                 return fieldKey;
 540  
         }
 541  
 
 542  
         @Override
 543  
         public void setKey(String key) {
 544  0
             if(key == null){
 545  
                         //TODO better way to generate unique id here?
 546  0
                         key = HTMLPanel.createUniqueId();
 547  
                 }
 548  0
                 this.fieldKey = key;
 549  0
         }
 550  
 
 551  
         /**
 552  
          * Sets the expected number of lines needed to space the vertical height of this field consistently
 553  
          * with fields next to it horizontally
 554  
          * @param margin
 555  
          */
 556  
         public void setTitleDescLineHeight(LineNum margin) {
 557  0
                 layout.removeStyleName("ks-form-module-single-line-margin");
 558  0
                 switch(margin){
 559  
                         case TRIPLE:
 560  0
                                 if(firstLineExists() && secondLineExists()){
 561  0
                                         layout.addStyleName("ks-form-module-single-line-margin");
 562  
                                 }
 563  0
                                 else if((firstLineExists() || secondLineExists())){
 564  0
                                         layout.addStyleName("ks-form-module-double-line-margin");
 565  
                                 }
 566  
                                 else{
 567  0
                                         layout.addStyleName("ks-form-module-triple-line-margin");
 568  
                                 }
 569  
 
 570  0
                                 break;
 571  
                         case DOUBLE:
 572  0
                                 if((firstLineExists() || secondLineExists())){
 573  0
                                         layout.addStyleName("ks-form-module-single-line-margin");
 574  
                                 }
 575  
                                 else{
 576  0
                                         layout.addStyleName("ks-form-module-double-line-margin");
 577  
                                 }
 578  0
                                 break;
 579  
                         case SINGLE:
 580  0
                                 layout.addStyleName("ks-form-module-single-line-margin");
 581  
                                 break;
 582  
                 }
 583  
 
 584  0
         }
 585  
 
 586  
         private boolean firstLineExists(){
 587  0
                 boolean exists = false;
 588  0
                 if((fieldName != null && !fieldName.equals("")) || required.isVisible() || help.isVisible()){
 589  0
                         exists = true;
 590  
                 }
 591  0
                 return exists;
 592  
         }
 593  
 
 594  
         private boolean secondLineExists(){
 595  0
                 boolean exists = false;
 596  0
                 if(instructions.isVisible()){
 597  0
                         exists = true;
 598  
                 }
 599  0
                 return exists;
 600  
         }
 601  
 
 602  
         /**
 603  
          * Hides the label of this field visually, but screen readers can still read it for accessibility
 604  
          */
 605  
         public void hideLabel() {
 606  0
                 layout.removeStyleName("ks-form-module-double-line-margin");
 607  0
                 layout.removeStyleName("ks-form-module-triple-line-margin");
 608  0
                 layout.addStyleName("ks-form-module-single-line-margin");
 609  0
                 fieldTitle.setStyleName("accessibility-hidden");
 610  0
                 instructions.setVisible(false);
 611  0
                 labelShown = false;
 612  0
         }
 613  
         
 614  
         public boolean isLabelShown(){
 615  0
                 return labelShown;
 616  
         }
 617  
 }