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 @Deprecated 18 public class EditableLabel extends SimplePanel implements HasClickHandlers, HasText, HasChangeHandlers { 19 Label label = new Label(); 20 TextBox textBox = new TextBox(); 21 22 public EditableLabel() { 23 super.setWidget(label); 24 textBox.addChangeHandler(new ChangeHandler() { 25 @Override 26 public void onChange(ChangeEvent event) { 27 label.setText(textBox.getText()); 28 } 29 }); 30 textBox.addClickHandler(new ClickHandler(){ 31 @Override 32 public void onClick(ClickEvent event) { 33 event.stopPropagation(); 34 } 35 36 }); 37 textBox.addBlurHandler(new BlurHandler() { 38 @Override 39 public void onBlur(BlurEvent event) { 40 label.setText(textBox.getText()); 41 EditableLabel.this.setWidget(label); 42 43 } 44 }); 45 label.addClickHandler(new ClickHandler() { 46 @Override 47 public void onClick(ClickEvent event) { 48 textBox.setText(label.getText()); 49 int width = label.getOffsetWidth(); 50 int height = label.getOffsetHeight()+3; 51 EditableLabel.this.setWidget(textBox); 52 textBox.setWidth(""+width+"px"); 53 textBox.setHeight(""+height+"px"); 54 textBox.selectAll(); 55 textBox.setFocus(true); 56 } 57 }); 58 } 59 60 @Override 61 public String getText() { 62 return label.getText(); 63 64 } 65 66 @Override 67 public void setText(String text) { 68 label.setText(text); 69 } 70 71 @Override 72 public HandlerRegistration addChangeHandler(ChangeHandler handler) { 73 return textBox.addChangeHandler(handler); 74 } 75 76 @Override 77 public HandlerRegistration addClickHandler(ClickHandler handler) { 78 return label.addClickHandler(handler); 79 } 80 }