Coverage Report - org.kuali.student.common.ui.client.widgets.field.layout.layouts.VerticalFieldLayout
 
Classes in this File Line Coverage Branch Coverage Complexity
VerticalFieldLayout
0%
0/79
0%
0/12
1.375
 
 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.HashMap;
 19  
 import java.util.Map;
 20  
 
 21  
 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
 22  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.ValidationMessagePanel;
 23  
 import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonLayout;
 24  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement;
 25  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel;
 26  
 
 27  
 import com.google.gwt.user.client.ui.FlowPanel;
 28  
 import com.google.gwt.user.client.ui.Widget;
 29  
 
 30  
 /**
 31  
  * A layout which lays out fields and other layouts vertically.  Fields and layouts added will appear
 32  
  * in the order they are added.  Validation will appear next to appropriate fields if hasValidation is true.
 33  
  * The title will appear above all elements and button layout below all elements.
 34  
  * 
 35  
  * @author Kuali Student Team
 36  
  *
 37  
  */
 38  
 public class VerticalFieldLayout extends FieldLayout {
 39  0
     private Map<String, FlowPanel> fieldContainers = new HashMap<String, FlowPanel>();
 40  
 
 41  0
     protected FlowPanel verticalLayout = new FlowPanel();
 42  0
     private SpanPanel buttonArea = new SpanPanel();
 43  
 
 44  
     public VerticalFieldLayout() {
 45  0
         super();
 46  0
         hasValidation = true;
 47  0
         init();
 48  0
     }
 49  
 
 50  
     public VerticalFieldLayout(boolean hasValidation) {
 51  0
         super();
 52  0
         this.hasValidation = hasValidation;
 53  0
         init();
 54  0
     }
 55  
 
 56  
     public VerticalFieldLayout(SectionTitle title) {
 57  0
         super();
 58  0
         this.setLayoutTitle(title);
 59  0
         this.hasValidation = true;
 60  0
         init();
 61  0
     }
 62  
 
 63  
     public VerticalFieldLayout(Widget titleWidget) {
 64  0
         super();
 65  0
         this.setTitleWidget(titleWidget);
 66  0
         this.hasValidation = true;
 67  0
         init();
 68  0
     }
 69  
 
 70  
     public VerticalFieldLayout(SectionTitle title, boolean hasValidation) {
 71  0
         super();
 72  0
         this.setLayoutTitle(title);
 73  0
         this.hasValidation = hasValidation;
 74  0
         init();
 75  0
     }
 76  
 
 77  
     private void init() {
 78  0
         instructions.setVisible(false);
 79  0
         this.add(verticalLayout);
 80  0
         verticalLayout.add(instructions);
 81  0
         verticalLayout.add(message);
 82  0
         this.add(buttonArea);
 83  0
         verticalLayout.setStyleName("ks-form-module");
 84  0
     }
 85  
 
 86  
 
 87  
     @Override
 88  
     public void addFieldToLayout(FieldElement field) {
 89  0
         FlowPanel fieldContainer = new FlowPanel();
 90  0
         FlowPanel fieldLayout = new FlowPanel();
 91  0
         fieldContainer.add(field);
 92  0
         fieldLayout.add(fieldContainer);
 93  0
         if (hasValidation) {
 94  0
             ValidationMessagePanel validationPanel = new ValidationMessagePanel();
 95  0
             fieldLayout.add(validationPanel);
 96  0
             field.setValidationPanel(validationPanel);
 97  0
             validationPanel.setStyleName("ks-form-module-validation-inline");
 98  
         }
 99  0
         field.setParentPanel(fieldLayout);
 100  0
         verticalLayout.add(fieldLayout);
 101  0
         fieldContainers.put(field.getKey(), fieldLayout);
 102  0
         fieldLayout.setStyleName("ks-form-module-group");
 103  0
         fieldLayout.addStyleName("clearfix");
 104  
         //field.addStyleName("ks-form-module-single-line-margin");
 105  0
         fieldContainer.setStyleName("ks-form-module-fields");
 106  0
     }
 107  
 
 108  
     @Override
 109  
     public void addLayoutToLayout(FieldLayout layout) {
 110  0
         verticalLayout.add(layout);
 111  0
         layout.setParentLayout(this);
 112  0
     }
 113  
 
 114  
     @Override
 115  
     public void addWidgetToLayout(Widget widget) {
 116  0
         widget.addStyleName("ks-section-widget");
 117  0
         verticalLayout.add(widget);
 118  0
     }
 119  
 
 120  
     @Override
 121  
     public void removeWidgetFromLayout(Widget widget) {
 122  0
         verticalLayout.remove(widget);
 123  0
     }
 124  
 
 125  
     @Override
 126  
     public void removeFieldLayoutComponentFromLayout(FieldLayoutComponent component) {
 127  0
         if (component instanceof FieldElement) {
 128  0
             FlowPanel panel = fieldContainers.get(component.getKey());
 129  0
             verticalLayout.remove(panel);
 130  0
             fieldContainers.remove(component.getKey());
 131  0
         } else if (component instanceof FieldLayout) {
 132  0
             verticalLayout.remove((FieldLayout) component);
 133  
         }
 134  0
     }
 135  
 
 136  
     @Override
 137  
     public void setLayoutTitle(SectionTitle layoutTitle) {
 138  0
         if (this.layoutTitle != null) {
 139  0
             verticalLayout.remove(this.layoutTitle);
 140  
         }
 141  0
         if (layoutTitle != null) {
 142  0
             this.layoutTitle = layoutTitle;
 143  0
             verticalLayout.insert(layoutTitle, 0);
 144  0
             layoutTitle.addStyleName("ks-layout-header");
 145  
         }
 146  0
     }
 147  
 
 148  
     public void setTitleWidget(Widget layoutTitle) {
 149  0
         if (this.layoutTitle != null) {
 150  0
             verticalLayout.remove(this.layoutTitle);
 151  
         }
 152  0
         verticalLayout.insert(layoutTitle, 0);
 153  0
     }
 154  
 
 155  
     @Override
 156  
     public void addButtonLayoutToLayout(ButtonLayout buttonLayout) {
 157  0
         buttonArea.add(buttonLayout);
 158  
 
 159  0
     }
 160  
 
 161  
     public Map<String, FlowPanel> getFieldContainers() {
 162  0
         return fieldContainers;
 163  
     }
 164  
 
 165  
         public FlowPanel getVerticalLayout() {
 166  0
                 return verticalLayout;
 167  
         }
 168  
 
 169  
 }