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