Coverage Report - org.kuali.student.common.ui.client.widgets.table.scroll.EditableLabel
 
Classes in this File Line Coverage Branch Coverage Complexity
EditableLabel
0%
0/14
N/A
1
EditableLabel$1
0%
0/3
N/A
1
EditableLabel$2
0%
0/3
N/A
1
EditableLabel$3
0%
0/4
N/A
1
EditableLabel$4
0%
0/10
N/A
1
 
 1  
 package org.kuali.student.common.ui.client.widgets.table.scroll;
 2  
 
 3  
 import com.google.gwt.event.dom.client.BlurEvent;
 4  
 import com.google.gwt.event.dom.client.BlurHandler;
 5  
 import com.google.gwt.event.dom.client.ChangeEvent;
 6  
 import com.google.gwt.event.dom.client.ChangeHandler;
 7  
 import com.google.gwt.event.dom.client.ClickEvent;
 8  
 import com.google.gwt.event.dom.client.ClickHandler;
 9  
 import com.google.gwt.event.dom.client.HasChangeHandlers;
 10  
 import com.google.gwt.event.dom.client.HasClickHandlers;
 11  
 import com.google.gwt.event.shared.HandlerRegistration;
 12  
 import com.google.gwt.user.client.ui.HasText;
 13  
 import com.google.gwt.user.client.ui.Label;
 14  
 import com.google.gwt.user.client.ui.SimplePanel;
 15  
 import com.google.gwt.user.client.ui.TextBox;
 16  
 
 17  
 public class EditableLabel extends SimplePanel implements HasClickHandlers,  HasText, HasChangeHandlers {
 18  0
         Label label = new Label();
 19  0
         TextBox textBox = new TextBox();
 20  
 
 21  0
         public EditableLabel() {
 22  0
                 super.setWidget(label);
 23  0
                 textBox.addChangeHandler(new ChangeHandler() {
 24  
                         @Override
 25  
                         public void onChange(ChangeEvent event) {
 26  0
                                 label.setText(textBox.getText());
 27  0
                         }
 28  
                 });
 29  0
                 textBox.addClickHandler(new ClickHandler(){
 30  
                         @Override
 31  
                         public void onClick(ClickEvent event) {
 32  0
                                 event.stopPropagation();
 33  0
                         }
 34  
                         
 35  
                 });
 36  0
                 textBox.addBlurHandler(new BlurHandler() {
 37  
                         @Override
 38  
                         public void onBlur(BlurEvent event) {
 39  0
                                 label.setText(textBox.getText());
 40  0
                                 EditableLabel.this.setWidget(label);
 41  
                                         
 42  0
                         }
 43  
                 });
 44  0
                 label.addClickHandler(new ClickHandler() {
 45  
                         @Override
 46  
                         public void onClick(ClickEvent event) {
 47  0
                                 textBox.setText(label.getText());
 48  0
                                         int width = label.getOffsetWidth();
 49  0
                                         int height = label.getOffsetHeight()+3;
 50  0
                                         EditableLabel.this.setWidget(textBox);
 51  0
                                         textBox.setWidth(""+width+"px");
 52  0
                                         textBox.setHeight(""+height+"px");
 53  0
                                         textBox.selectAll();
 54  0
                                         textBox.setFocus(true);
 55  0
                         }
 56  
                 });
 57  0
         }
 58  
 
 59  
         @Override
 60  
         public String getText() {
 61  0
                 return label.getText();
 62  
 
 63  
         }
 64  
 
 65  
         @Override
 66  
         public void setText(String text) {
 67  0
                 label.setText(text);
 68  0
         }
 69  
 
 70  
         @Override
 71  
         public HandlerRegistration addChangeHandler(ChangeHandler handler) {
 72  0
                 return textBox.addChangeHandler(handler);
 73  
         }
 74  
 
 75  
         @Override
 76  
         public HandlerRegistration addClickHandler(ClickHandler handler) {
 77  0
                 return label.addClickHandler(handler);
 78  
         }
 79  
 }