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/77
0%
0/12
1.429
 
 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  
 public class VerticalFieldLayout extends FieldLayout {
 31  0
     private Map<String, FlowPanel> fieldContainers = new HashMap<String, FlowPanel>();
 32  
 
 33  0
     protected FlowPanel verticalLayout = new FlowPanel();
 34  0
     private SpanPanel buttonArea = new SpanPanel();
 35  
 
 36  
     public VerticalFieldLayout() {
 37  0
         super();
 38  0
         hasValidation = true;
 39  0
         init();
 40  0
     }
 41  
 
 42  
     public VerticalFieldLayout(boolean hasValidation) {
 43  0
         super();
 44  0
         this.hasValidation = hasValidation;
 45  0
         init();
 46  0
     }
 47  
 
 48  
     public VerticalFieldLayout(SectionTitle title) {
 49  0
         super();
 50  0
         this.setLayoutTitle(title);
 51  0
         this.hasValidation = true;
 52  0
         init();
 53  0
     }
 54  
 
 55  
     public VerticalFieldLayout(Widget titleWidget) {
 56  0
         super();
 57  0
         this.setTitleWidget(titleWidget);
 58  0
         this.hasValidation = true;
 59  0
         init();
 60  0
     }
 61  
 
 62  
     public VerticalFieldLayout(SectionTitle title, boolean hasValidation) {
 63  0
         super();
 64  0
         this.setLayoutTitle(title);
 65  0
         this.hasValidation = hasValidation;
 66  0
         init();
 67  0
     }
 68  
 
 69  
     private void init() {
 70  0
         instructions.setVisible(false);
 71  0
         this.add(verticalLayout);
 72  0
         verticalLayout.add(instructions);
 73  0
         verticalLayout.add(message);
 74  0
         this.add(buttonArea);
 75  0
         verticalLayout.setStyleName("ks-form-module");
 76  0
     }
 77  
 
 78  
 
 79  
     @Override
 80  
     public void addFieldToLayout(FieldElement field) {
 81  0
         FlowPanel fieldContainer = new FlowPanel();
 82  0
         FlowPanel fieldLayout = new FlowPanel();
 83  0
         fieldContainer.add(field);
 84  0
         fieldLayout.add(fieldContainer);
 85  0
         if (hasValidation) {
 86  0
             ValidationMessagePanel validationPanel = new ValidationMessagePanel();
 87  0
             fieldLayout.add(validationPanel);
 88  0
             field.setValidationPanel(validationPanel);
 89  0
             validationPanel.setStyleName("ks-form-module-validation-inline");
 90  
         }
 91  0
         field.setParentPanel(fieldLayout);
 92  0
         verticalLayout.add(fieldLayout);
 93  0
         fieldContainers.put(field.getKey(), fieldLayout);
 94  0
         fieldLayout.setStyleName("ks-form-module-group");
 95  0
         fieldLayout.addStyleName("clearfix");
 96  
         //field.addStyleName("ks-form-module-single-line-margin");
 97  0
         fieldContainer.setStyleName("ks-form-module-fields");
 98  0
     }
 99  
 
 100  
     @Override
 101  
     public void addLayoutToLayout(FieldLayout layout) {
 102  0
         verticalLayout.add(layout);
 103  0
         layout.setParentLayout(this);
 104  0
     }
 105  
 
 106  
     @Override
 107  
     public void addWidgetToLayout(Widget widget) {
 108  0
         widget.addStyleName("ks-section-widget");
 109  0
         verticalLayout.add(widget);
 110  0
     }
 111  
 
 112  
     @Override
 113  
     public void removeWidgetFromLayout(Widget widget) {
 114  0
         verticalLayout.remove(widget);
 115  0
     }
 116  
 
 117  
     @Override
 118  
     public void removeFieldLayoutComponentFromLayout(FieldLayoutComponent component) {
 119  0
         if (component instanceof FieldElement) {
 120  0
             FlowPanel panel = fieldContainers.get(component.getKey());
 121  0
             verticalLayout.remove(panel);
 122  0
             fieldContainers.remove(component.getKey());
 123  0
         } else if (component instanceof FieldLayout) {
 124  0
             verticalLayout.remove((FieldLayout) component);
 125  
         }
 126  0
     }
 127  
 
 128  
     @Override
 129  
     public void setLayoutTitle(SectionTitle layoutTitle) {
 130  0
         if (this.layoutTitle != null) {
 131  0
             verticalLayout.remove(this.layoutTitle);
 132  
         }
 133  0
         if (layoutTitle != null) {
 134  0
             this.layoutTitle = layoutTitle;
 135  0
             verticalLayout.insert(layoutTitle, 0);
 136  0
             layoutTitle.addStyleName("ks-layout-header");
 137  
         }
 138  0
     }
 139  
 
 140  
     public void setTitleWidget(Widget layoutTitle) {
 141  0
         if (this.layoutTitle != null) {
 142  0
             verticalLayout.remove(this.layoutTitle);
 143  
         }
 144  0
         verticalLayout.insert(layoutTitle, 0);
 145  0
     }
 146  
 
 147  
     @Override
 148  
     public void addButtonLayoutToLayout(ButtonLayout buttonLayout) {
 149  0
         buttonArea.add(buttonLayout);
 150  
 
 151  0
     }
 152  
 
 153  
 }