Coverage Report - org.kuali.student.common.ui.client.widgets.impl.KSButtonImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
KSButtonImpl
0%
0/57
0%
0/8
1.222
KSButtonImpl$SpanPanel
0%
0/7
N/A
1.222
 
 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.util.DebugIdUtils;
 19  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract;
 20  
 
 21  
 import com.google.gwt.event.dom.client.ClickHandler;
 22  
 import com.google.gwt.event.dom.client.MouseOutHandler;
 23  
 import com.google.gwt.event.dom.client.MouseOverHandler;
 24  
 import com.google.gwt.event.shared.HandlerRegistration;
 25  
 import com.google.gwt.user.client.DOM;
 26  
 import com.google.gwt.user.client.ui.Anchor;
 27  
 import com.google.gwt.user.client.ui.ComplexPanel;
 28  
 import com.google.gwt.user.client.ui.InlineLabel;
 29  
 import com.google.gwt.user.client.ui.Widget;
 30  
 
 31  0
 public class KSButtonImpl extends KSButtonAbstract {
 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 range
 55  
          */
 56  
         public void insert(Widget w, int beforeIndex) {
 57  0
             insert(w, getElement(), beforeIndex, true);
 58  0
         }
 59  
     }
 60  
 
 61  0
     private SpanPanel panel = new SpanPanel();
 62  
     private Anchor anchor;
 63  0
     private InlineLabel disabledLabel = new InlineLabel();
 64  0
     private boolean enabled = true;
 65  
     private ButtonStyle currentStyle;
 66  
 
 67  
     public boolean isEnabled() {
 68  0
         return enabled;
 69  
     }
 70  
 
 71  
     public void setEnabled(boolean enabled) {
 72  0
         anchor.setEnabled(enabled);
 73  0
         if (enabled) {
 74  0
             panel.remove(disabledLabel);
 75  0
             panel.add(anchor);
 76  
         } else {
 77  0
             panel.remove(anchor);
 78  0
             panel.add(disabledLabel);
 79  
         }
 80  0
     }
 81  
 
 82  
     @Override
 83  
     public HandlerRegistration addClickHandler(ClickHandler handler) {
 84  0
         return anchor.addClickHandler(handler);
 85  
     }
 86  
 
 87  
     @Override
 88  
     public void setText(String text) {
 89  0
         anchor.setText(text);
 90  0
         disabledLabel.setText(text);
 91  0
     }
 92  
 
 93  
     @Override
 94  
     public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
 95  0
         return anchor.addMouseOverHandler(handler);
 96  
     }
 97  
 
 98  
     @Override
 99  
     public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
 100  0
         return anchor.addMouseOutHandler(handler);
 101  
     }
 102  
 
 103  
     @Override
 104  
     public void init(String text) {
 105  0
         init(text, ButtonStyle.PRIMARY);
 106  0
     }
 107  
 
 108  
     @Override
 109  
     public void init(String text, ButtonStyle style) {
 110  
 
 111  0
         this.currentStyle = style;
 112  0
         disabledLabel.setText(text);
 113  0
         anchor = new Anchor();
 114  0
         if (currentStyle.getStyle() != null) {
 115  0
             disabledLabel.setStyleName(currentStyle.getStyle());
 116  0
             anchor.setStyleName(currentStyle.getStyle());
 117  
         }
 118  0
         String disabledStyle = currentStyle.getDisabledStyle();
 119  0
         if (disabledStyle == null) {
 120  0
             disabledLabel.addStyleName("disabled");
 121  
         } else {
 122  0
             disabledLabel.setStyleName(disabledStyle);
 123  
         }
 124  0
         anchor.setText(text);
 125  0
         anchor.setHref("javascript:return false;");
 126  
 
 127  0
         panel.add(anchor);
 128  0
         anchor.setTabIndex(0);
 129  
 
 130  0
         this.initWidget(panel);
 131  0
     }
 132  
 
 133  
     @Override
 134  
     public void addStyleName(String style) {
 135  0
         anchor.addStyleName(style);
 136  0
         disabledLabel.addStyleName(style);
 137  0
     }
 138  
 
 139  
     @Override
 140  
     public void removeStyleName(String style) {
 141  0
         anchor.removeStyleName(style);
 142  0
         disabledLabel.removeStyleName(style);
 143  0
     }
 144  
 
 145  
     @Override
 146  
     public void setStyleName(String style) {
 147  0
         anchor.setStyleName(style);
 148  0
         disabledLabel.setStyleName(style);
 149  0
     }
 150  
 
 151  
     @Override
 152  
     public void init() {
 153  0
         init("", ButtonStyle.PRIMARY);
 154  0
     }
 155  
 
 156  
     @Override
 157  
     public void init(String text, ClickHandler handler) {
 158  0
         init(text, ButtonStyle.PRIMARY);
 159  0
         anchor.addClickHandler(handler);
 160  0
     }
 161  
 
 162  
     public void init(String text, ButtonStyle style, ClickHandler handler) {
 163  0
         init(text, style);
 164  0
         anchor.addClickHandler(handler);
 165  0
     }
 166  
 
 167  
     @Override
 168  
     protected void onEnsureDebugId(String baseID) {
 169  0
         super.onEnsureDebugId(baseID);
 170  0
         if (anchor != null) {
 171  0
             anchor.ensureDebugId(DebugIdUtils.createWebDriverSafeDebugId(baseID + "-anchor"));
 172  
         }
 173  0
     }
 174  
 
 175  
 }