1 package org.kuali.student.common.ui.client.widgets.table.scroll;
2
3 import com.google.gwt.event.dom.client.ChangeHandler;
4 import com.google.gwt.event.dom.client.ClickHandler;
5 import com.google.gwt.event.dom.client.HasChangeHandlers;
6 import com.google.gwt.event.dom.client.HasClickHandlers;
7 import com.google.gwt.event.shared.HandlerRegistration;
8 import com.google.gwt.user.client.ui.CheckBox;
9 import com.google.gwt.user.client.ui.Composite;
10 import com.google.gwt.user.client.ui.Widget;
11
12 public class TableCellWidget extends Composite implements HasClickHandlers, HasChangeHandlers {
13 Widget defaultTableEditor;
14 public TableCellWidget(Object value){
15 if(value instanceof Boolean){
16 defaultTableEditor = new CheckBox();
17 ((CheckBox)defaultTableEditor).setTabIndex(-1);
18 }else {
19 defaultTableEditor = new EditableLabel();
20 }
21 super.initWidget(defaultTableEditor);
22 }
23 public Object getCellEditorValue() {
24 if (defaultTableEditor instanceof EditableLabel) {
25 return ((EditableLabel)defaultTableEditor).getText();
26 }else if(defaultTableEditor instanceof CheckBox){
27 return ((CheckBox)defaultTableEditor).getValue();
28 }
29 return "";
30 }
31 public void setCellEditorValue(Object value) {
32 if (defaultTableEditor instanceof EditableLabel) {
33 if(value == null){
34 ((EditableLabel)defaultTableEditor).setText("");
35 }else{
36 ((EditableLabel)defaultTableEditor).setText(value.toString());
37 }
38 }else if(defaultTableEditor instanceof CheckBox){
39 if(value == null){
40 ((CheckBox)defaultTableEditor).setValue(false);
41 }else{
42 ((CheckBox)defaultTableEditor).setValue((Boolean)value);
43 }
44
45 }
46
47 }
48
49 @Override
50 public HandlerRegistration addClickHandler(ClickHandler handler) {
51 if(defaultTableEditor instanceof CheckBox){
52 return ((CheckBox)defaultTableEditor).addClickHandler(handler) ;
53 }else if(defaultTableEditor instanceof EditableLabel) {
54 return ((EditableLabel)defaultTableEditor).addClickHandler(handler) ;
55 }
56 return null;
57 }
58 @Override
59 public HandlerRegistration addChangeHandler(ChangeHandler handler) {
60
61
62
63 if(defaultTableEditor instanceof EditableLabel) {
64 return ((EditableLabel)defaultTableEditor).addChangeHandler(handler) ;
65 }
66 return null;
67 }
68
69 public Widget getDefaultTableEditor() {
70 return defaultTableEditor;
71 }
72 }