Coverage Report - org.kuali.student.common.ui.client.widgets.impl.KSButtonImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
KSButtonImpl
0%
0/53
0%
0/6
1.176
KSButtonImpl$SpanPanel
0%
0/7
N/A
1.176
 
 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.impl;
 17  
 
 18  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract;
 19  
 
 20  
 import com.google.gwt.event.dom.client.ClickHandler;
 21  
 import com.google.gwt.event.dom.client.MouseOutHandler;
 22  
 import com.google.gwt.event.dom.client.MouseOverHandler;
 23  
 import com.google.gwt.event.shared.HandlerRegistration;
 24  
 import com.google.gwt.user.client.DOM;
 25  
 import com.google.gwt.user.client.ui.Anchor;
 26  
 import com.google.gwt.user.client.ui.ComplexPanel;
 27  
 import com.google.gwt.user.client.ui.InlineLabel;
 28  
 import com.google.gwt.user.client.ui.Widget;
 29  
 
 30  0
 public class KSButtonImpl extends KSButtonAbstract{
 31  
 
 32  
 
 33  
         private static class SpanPanel extends ComplexPanel{
 34  
 
 35  0
                 public SpanPanel(){
 36  0
                         setElement(DOM.createSpan());
 37  0
                 }
 38  
 
 39  
                   /**
 40  
                    * Adds a new child widget to the panel.
 41  
                    *
 42  
                    * @param w the widget to be added
 43  
                    */
 44  
                   @Override
 45  
                   public void add(Widget w) {
 46  0
                     add(w, getElement());
 47  0
                   }
 48  
 
 49  
                   /**
 50  
                    * Inserts a widget before the specified index.
 51  
                    *
 52  
                    * @param w the widget to be inserted
 53  
                    * @param beforeIndex the index before which it will be inserted
 54  
                    * @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out of
 55  
                    *           range
 56  
                    */
 57  
                   public void insert(Widget w, int beforeIndex) {
 58  0
                     insert(w, getElement(), beforeIndex, true);
 59  0
                   }
 60  
         }
 61  
 
 62  0
         private SpanPanel panel = new SpanPanel();
 63  
         private Anchor anchor;
 64  0
         private InlineLabel disabledLabel = new InlineLabel();
 65  0
         private boolean enabled = true;
 66  
         private ButtonStyle currentStyle;
 67  
 
 68  
         public boolean isEnabled() {
 69  0
                 return enabled;
 70  
         }
 71  
 
 72  
         public void setEnabled(boolean enabled) {
 73  0
                 anchor.setEnabled(enabled);
 74  0
                 if(enabled){
 75  0
                         panel.remove(disabledLabel);
 76  0
                         panel.add(anchor);
 77  
                 }
 78  
                 else{
 79  0
                         panel.remove(anchor);
 80  0
                         panel.add(disabledLabel);
 81  
                 }
 82  0
         }
 83  
 
 84  
         @Override
 85  
         public HandlerRegistration addClickHandler(ClickHandler handler) {
 86  0
                 return anchor.addClickHandler(handler);
 87  
         }
 88  
 
 89  
         @Override
 90  
         public void setText(String text){
 91  0
                 anchor.setText(text);
 92  0
                 disabledLabel.setText(text);
 93  0
         }
 94  
 
 95  
         @Override
 96  
         public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
 97  0
                 return anchor.addMouseOverHandler(handler);
 98  
         }
 99  
 
 100  
         @Override
 101  
         public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
 102  0
                 return anchor.addMouseOutHandler(handler);
 103  
         }
 104  
 
 105  
         @Override
 106  
         public void init(String text) {
 107  0
                 init(text, ButtonStyle.PRIMARY);
 108  0
         }
 109  
 
 110  
         @Override
 111  
         public void init(String text, ButtonStyle style) {
 112  
 
 113  0
                 this.currentStyle = style;
 114  0
                 disabledLabel.setText(text);
 115  0
                 anchor = new Anchor();
 116  0
                 if(currentStyle.getStyle() != null){
 117  0
                         disabledLabel.setStyleName(currentStyle.getStyle());
 118  0
                         anchor.setStyleName(currentStyle.getStyle());
 119  
                 }
 120  0
                 String disabledStyle = currentStyle.getDisabledStyle();
 121  0
                 if(disabledStyle == null){
 122  0
                         disabledLabel.addStyleName("disabled");
 123  
                 }
 124  
                 else{
 125  0
                         disabledLabel.setStyleName(disabledStyle);
 126  
                 }
 127  0
                 anchor.setText(text);
 128  0
                 anchor.setHref("javascript:return false;");
 129  
 
 130  0
                 panel.add(anchor);
 131  0
                 anchor.setTabIndex(0);
 132  
 
 133  0
                 this.initWidget(panel);
 134  0
         }
 135  
         
 136  
         @Override
 137  
     public void addStyleName(String style) {
 138  0
         anchor.addStyleName(style);
 139  0
         disabledLabel.addStyleName(style);
 140  0
     }
 141  
 
 142  
     @Override
 143  
     public void removeStyleName(String style) {
 144  0
         anchor.removeStyleName(style);
 145  0
         disabledLabel.removeStyleName(style);        
 146  0
     }
 147  
 
 148  
     @Override
 149  
     public void setStyleName(String style) {
 150  0
         anchor.setStyleName(style);
 151  0
         disabledLabel.setStyleName(style);        
 152  0
     }
 153  
 
 154  
     @Override
 155  
         public void init() {
 156  0
                 init("", ButtonStyle.PRIMARY);
 157  0
         }
 158  
 
 159  
         @Override
 160  
         public void init(String text, ClickHandler handler) {
 161  0
                 init(text, ButtonStyle.PRIMARY);
 162  0
                 anchor.addClickHandler(handler);
 163  0
         }
 164  
 
 165  
     public void init(String text, ButtonStyle style, ClickHandler handler) {
 166  0
         init(text, style);
 167  0
         anchor.addClickHandler(handler);
 168  0
     }
 169  
 }