Coverage Report - org.kuali.student.common.ui.client.widgets.field.layout.layouts.GroupFieldLayout
 
Classes in this File Line Coverage Branch Coverage Complexity
GroupFieldLayout
0%
0/103
0%
0/28
2.077
GroupFieldLayout$ValidationLocation
0%
0/1
N/A
2.077
 
 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.layouts;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
 22  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.ClearBreak;
 23  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.ValidationMessagePanel;
 24  
 import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonLayout;
 25  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement;
 26  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel;
 27  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement.LineNum;
 28  
 
 29  
 import com.google.gwt.user.client.ui.FlowPanel;
 30  
 import com.google.gwt.user.client.ui.Widget;
 31  
 
 32  
 public class GroupFieldLayout extends FieldLayout{
 33  0
         private SpanPanel top = new SpanPanel();
 34  0
         private FlowPanel layout = new FlowPanel();
 35  0
         private FlowPanel fieldContainer = new FlowPanel();
 36  0
         private FlowPanel fieldsPanel = new FlowPanel();
 37  0
         private SpanPanel buttonArea = new SpanPanel();
 38  0
         private ValidationMessagePanel validationPanel = new ValidationMessagePanel();
 39  0
         private List<FieldElement> currentLine = new ArrayList<FieldElement>();
 40  0
         private int lineCount = 0;
 41  0
         public static enum ValidationLocation{NONE, TOP, RIGHT};
 42  
         private ValidationLocation loc;
 43  0
         private boolean lineHasTitles = false;
 44  0
         private boolean lineHasDescriptions = false;
 45  
         
 46  
         public GroupFieldLayout(){
 47  0
                 super();
 48  0
                 this.loc = ValidationLocation.RIGHT;
 49  0
                 init();
 50  0
         }
 51  
         
 52  
         public GroupFieldLayout(ValidationLocation loc){
 53  0
                 super();
 54  0
                 this.loc = loc;
 55  0
                 init();
 56  0
         }
 57  
         
 58  
         public GroupFieldLayout(SectionTitle title){
 59  0
                 super();
 60  0
                 this.loc = ValidationLocation.RIGHT;
 61  0
                 this.setLayoutTitle(title);
 62  0
                 init();
 63  0
         }
 64  
         
 65  
         public GroupFieldLayout(SectionTitle title, ValidationLocation loc){
 66  0
                 super();
 67  0
                 this.loc = loc;
 68  0
                 this.setLayoutTitle(title);
 69  0
                 init();
 70  0
         }
 71  
         
 72  
         private void init(){
 73  
                 //lines.add(currentLine);
 74  0
                 this.instructions.setVisible(false);
 75  0
                 layout.add(this.instructions);
 76  0
                 layout.add(this.message);
 77  0
                 if(loc == ValidationLocation.RIGHT){
 78  0
                         this.hasValidation = true;
 79  0
                         fieldContainer.add(fieldsPanel);
 80  0
                         fieldContainer.add(validationPanel);
 81  0
                         layout.add(fieldContainer);
 82  0
                         fieldContainer.setStyleName("ks-form-module-group");
 83  0
                         fieldContainer.addStyleName("clearfix");
 84  0
                         fieldsPanel.setStyleName("ks-form-module-fields");
 85  0
                         fieldsPanel.addStyleName("clearfix");
 86  0
                         validationPanel.setStyleName("ks-form-module-validation");
 87  
                 }
 88  0
                 else if(loc == ValidationLocation.TOP){
 89  0
                         this.hasValidation = true;
 90  0
                         fieldContainer.add(validationPanel);
 91  0
                         fieldContainer.add(fieldsPanel);
 92  0
                         layout.add(fieldContainer);
 93  0
                         fieldContainer.setStyleName("ks-form-module-group");
 94  0
                         fieldContainer.addStyleName("clearfix");
 95  0
                         fieldsPanel.setStyleName("ks-form-module-fields");
 96  0
                         fieldsPanel.addStyleName("clearfix");
 97  0
                         validationPanel.setStyleName("ks-form-module-validation");
 98  
                 }
 99  
                 else{
 100  0
                         this.hasValidation = false;
 101  0
                         fieldContainer.add(fieldsPanel);
 102  0
                         layout.add(fieldContainer);
 103  0
                         fieldContainer.setStyleName("ks-form-module-group");
 104  0
                         fieldContainer.addStyleName("clearfix");
 105  0
                         fieldsPanel.setStyleName("ks-form-module-fields");
 106  0
                         fieldsPanel.addStyleName("clearfix");
 107  
                 }
 108  
                 
 109  0
                 top.add(layout);
 110  0
                 top.add(buttonArea);
 111  0
                 this.add(top);
 112  
                 
 113  0
         }
 114  
         
 115  
         public void nextLine(){
 116  0
                 fieldsPanel.add(new ClearBreak());
 117  0
                 currentLine = new ArrayList<FieldElement>();
 118  
                 //lines.add(currentLine);
 119  0
                 lineCount++;
 120  0
                 lineHasTitles = false;
 121  0
                 lineHasDescriptions = false;
 122  0
         }
 123  
         
 124  
         @Override
 125  
         public void addFieldToLayout(FieldElement field) {
 126  0
                 currentLine.add(field);
 127  
                 
 128  0
                 if(field.getFieldName() != null && !field.getFieldName().equals("")){
 129  0
                         lineHasTitles = true;
 130  
                 }
 131  
                 
 132  0
                 if(field.getInstructionText() != null && !field.getInstructionText().equals("")){
 133  0
                         lineHasDescriptions = true;
 134  
                 }
 135  
                 
 136  0
                 for(FieldElement f: currentLine){
 137  0
                         if(lineHasTitles && lineHasDescriptions){
 138  0
                                 f.setTitleDescLineHeight(LineNum.TRIPLE);
 139  
                         }
 140  0
                         else if(lineHasTitles || lineHasDescriptions){
 141  0
                                 f.setTitleDescLineHeight(LineNum.DOUBLE);
 142  
                         }
 143  
                         else{
 144  0
                                 f.setTitleDescLineHeight(LineNum.SINGLE);
 145  
                         }
 146  
                 }
 147  
         
 148  0
         fieldsPanel.add(field);
 149  0
         field.setValidationPanel(validationPanel);
 150  0
         field.setParentPanel(fieldContainer);
 151  
                 
 152  0
         }
 153  
 
 154  
         @Override
 155  
         public void addLayoutToLayout(FieldLayout fieldLayout) {
 156  0
                 layout.add(fieldLayout);
 157  0
                 fieldLayout.setParentLayout(this);
 158  0
         }
 159  
 
 160  
         @Override
 161  
         public void addWidgetToLayout(Widget widget) {
 162  0
                 layout.add(widget);
 163  
                 
 164  0
         }
 165  
 
 166  
         @Override
 167  
         public void removeFieldLayoutComponentFromLayout(
 168  
                         FieldLayoutComponent component) {
 169  0
                 if(component instanceof FieldElement){
 170  0
                         fieldsPanel.remove((FieldElement)component);
 171  
                 }
 172  0
                 else if(component instanceof FieldLayout){
 173  0
                         layout.remove((FieldLayout)component);
 174  
                 }
 175  
                 
 176  0
         }
 177  
 
 178  
         @Override
 179  
         public void removeWidgetFromLayout(Widget widget) {
 180  0
                 layout.remove(widget);
 181  
                 
 182  0
         }
 183  
 
 184  
         @Override
 185  
         public void setLayoutTitle(SectionTitle layoutTitle) {
 186  0
                 if(this.layoutTitle != null){
 187  0
                         layout.remove(this.layoutTitle);
 188  
                 }
 189  0
                 this.layoutTitle = layoutTitle;
 190  0
                 layout.insert(layoutTitle, 0);
 191  0
                 layoutTitle.addStyleName("ks-layout-header");
 192  0
         }
 193  
 
 194  
         @Override
 195  
         public void addButtonLayoutToLayout(ButtonLayout buttonLayout) {
 196  0
                 buttonArea.add(buttonLayout);
 197  0
         }
 198  
 
 199  
 }