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 | 0 | public TableCellWidget(Object value){ |
15 | 0 | if(value instanceof Boolean){ |
16 | 0 | defaultTableEditor = new CheckBox(); |
17 | |
}else { |
18 | 0 | defaultTableEditor = new EditableLabel(); |
19 | |
} |
20 | 0 | super.initWidget(defaultTableEditor); |
21 | 0 | } |
22 | |
public Object getCellEditorValue() { |
23 | 0 | if (defaultTableEditor instanceof EditableLabel) { |
24 | 0 | return ((EditableLabel)defaultTableEditor).getText(); |
25 | 0 | }else if(defaultTableEditor instanceof CheckBox){ |
26 | 0 | return ((CheckBox)defaultTableEditor).getValue(); |
27 | |
} |
28 | 0 | return ""; |
29 | |
} |
30 | |
public void setCellEditorValue(Object value) { |
31 | 0 | if (defaultTableEditor instanceof EditableLabel) { |
32 | 0 | if(value == null){ |
33 | 0 | ((EditableLabel)defaultTableEditor).setText(""); |
34 | |
}else{ |
35 | 0 | ((EditableLabel)defaultTableEditor).setText(value.toString()); |
36 | |
} |
37 | 0 | }else if(defaultTableEditor instanceof CheckBox){ |
38 | 0 | if(value == null){ |
39 | 0 | ((CheckBox)defaultTableEditor).setValue(false); |
40 | |
}else{ |
41 | 0 | ((CheckBox)defaultTableEditor).setValue((Boolean)value); |
42 | |
} |
43 | |
|
44 | |
} |
45 | |
|
46 | 0 | } |
47 | |
|
48 | |
@Override |
49 | |
public HandlerRegistration addClickHandler(ClickHandler handler) { |
50 | 0 | if(defaultTableEditor instanceof CheckBox){ |
51 | 0 | return ((CheckBox)defaultTableEditor).addClickHandler(handler) ; |
52 | 0 | }else if(defaultTableEditor instanceof EditableLabel) { |
53 | 0 | return ((EditableLabel)defaultTableEditor).addClickHandler(handler) ; |
54 | |
} |
55 | 0 | return null; |
56 | |
} |
57 | |
@Override |
58 | |
public HandlerRegistration addChangeHandler(ChangeHandler handler) { |
59 | |
|
60 | |
|
61 | |
|
62 | 0 | if(defaultTableEditor instanceof EditableLabel) { |
63 | 0 | return ((EditableLabel)defaultTableEditor).addChangeHandler(handler) ; |
64 | |
} |
65 | 0 | return null; |
66 | |
} |
67 | |
} |