Coverage Report - org.kuali.student.common.ui.client.widgets.field.layout.layouts.HorizontalLayout
 
Classes in this File Line Coverage Branch Coverage Complexity
HorizontalLayout
0%
0/66
0%
0/14
1.538
 
 1  
 package org.kuali.student.common.ui.client.widgets.field.layout.layouts;
 2  
 
 3  
 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
 4  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.ValidationMessagePanel;
 5  
 import org.kuali.student.common.ui.client.widgets.field.layout.button.ButtonLayout;
 6  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement;
 7  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel;
 8  
 
 9  
 import com.google.gwt.user.client.ui.FlexTable;
 10  
 import com.google.gwt.user.client.ui.HasVerticalAlignment;
 11  
 import com.google.gwt.user.client.ui.Widget;
 12  
 
 13  
 /**
 14  
  * A layout which lays out fields and other layouts horizontally in a table.  Fields and layouts added will appear
 15  
  * in the order they are added.  Calling nextIndex will begin the next row in the table.
 16  
  * Validation will appear above the horizontal layout if hasValidation is true.
 17  
  * The title will appear above all elements and button layout below all elements.
 18  
  * 
 19  
  * @author Kuali Student Team
 20  
  *
 21  
  */
 22  
 public class HorizontalLayout extends FieldLayout{
 23  0
         private FlexTable horizontalArea = new FlexTable();
 24  0
         private ValidationMessagePanel validationPanel = new ValidationMessagePanel();
 25  0
         private SpanPanel fieldArea = new SpanPanel();
 26  
         private SpanPanel buttonArea;
 27  0
         private int currentRow = 0;
 28  0
         private int currentColumn = 0;
 29  
         
 30  
         public HorizontalLayout(){
 31  0
                 super();
 32  0
                 hasValidation = true;
 33  0
                 init();
 34  0
         }
 35  
         
 36  
         public HorizontalLayout(boolean hasValidation){
 37  0
                 super();
 38  0
                 this.hasValidation = hasValidation;
 39  0
                 init();
 40  0
         }
 41  
         
 42  
         public HorizontalLayout(SectionTitle title){
 43  0
                 super();
 44  0
                 this.setLayoutTitle(title);
 45  0
                 hasValidation = true;
 46  0
                 init();
 47  0
         }
 48  
         
 49  
         public HorizontalLayout(SectionTitle title, boolean hasValidation){
 50  0
                 super();
 51  0
                 this.setLayoutTitle(title);
 52  0
                 this.hasValidation = hasValidation;
 53  0
                 init();
 54  
 
 55  0
         }
 56  
         
 57  
         private void init(){
 58  0
                 instructions.setVisible(false);
 59  0
                 this.add(instructions);
 60  0
                 this.add(message);
 61  0
                 if(hasValidation){
 62  0
                         this.add(validationPanel);
 63  
                 }
 64  0
                 this.add(horizontalArea);
 65  0
         }
 66  
 
 67  
         @Override
 68  
         public void addButtonLayoutToLayout(ButtonLayout buttonLayout) {
 69  0
                 if(buttonArea == null){
 70  0
                         buttonArea = new SpanPanel();
 71  0
                         this.add(buttonArea);
 72  
                 }
 73  0
                 buttonArea.add(buttonLayout);
 74  0
         }
 75  
 
 76  
         @Override
 77  
         public void addFieldToLayout(FieldElement field) {
 78  0
                 horizontalArea.setWidget(currentRow, currentColumn, field);
 79  0
                 horizontalArea.getFlexCellFormatter().setVerticalAlignment(currentRow, currentColumn, HasVerticalAlignment.ALIGN_TOP);
 80  
 
 81  0
                 if(hasValidation){
 82  0
                         field.setValidationPanel(validationPanel);
 83  
                 }
 84  0
                 currentColumn++;
 85  0
         }
 86  
 
 87  
         @Override
 88  
         public void addLayoutToLayout(FieldLayout layout) {
 89  0
                 horizontalArea.setWidget(currentRow, currentColumn, layout);
 90  0
                 horizontalArea.getFlexCellFormatter().setVerticalAlignment(currentRow, currentColumn, HasVerticalAlignment.ALIGN_TOP);
 91  0
                 currentColumn++;
 92  0
         }
 93  
 
 94  
         @Override
 95  
         public void addWidgetToLayout(Widget widget) {
 96  0
                 horizontalArea.setWidget(currentRow, currentColumn, widget);
 97  0
                 horizontalArea.getFlexCellFormatter().setVerticalAlignment(currentRow, currentColumn, HasVerticalAlignment.ALIGN_TOP);
 98  0
                 currentColumn++;
 99  0
         }
 100  
         
 101  
         public void nextRow(){
 102  0
                 currentRow++;
 103  0
                 currentColumn = 0;
 104  0
         }
 105  
 
 106  
         @Override
 107  
         public void removeFieldLayoutComponentFromLayout(
 108  
                         FieldLayoutComponent component) {
 109  0
                 if(component instanceof FieldElement){
 110  0
                         horizontalArea.remove((FieldElement)component);
 111  
                 }
 112  0
                 else if(component instanceof FieldLayout){
 113  0
                         horizontalArea.remove((FieldLayout)component);
 114  
                 }
 115  
                 
 116  0
         }
 117  
 
 118  
         @Override
 119  
         public void removeWidgetFromLayout(Widget widget) {
 120  0
                 horizontalArea.remove(widget);        
 121  0
         }
 122  
 
 123  
         @Override
 124  
         public void setLayoutTitle(SectionTitle layoutTitle) {
 125  0
                 if(this.layoutTitle != null){
 126  0
                         this.remove(this.layoutTitle);
 127  
                 }
 128  0
                 if(layoutTitle != null){
 129  0
                         this.layoutTitle = layoutTitle;
 130  0
                         this.insert(layoutTitle, 0);
 131  0
                         layoutTitle.addStyleName("ks-layout-header");
 132  
                 }
 133  
                 
 134  0
         }
 135  
 
 136  
 }