1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.common.ui.client.widgets.table;
17
18 import org.kuali.student.common.ui.client.widgets.rules.Token;
19
20 import com.google.gwt.core.client.GWT;
21 import com.google.gwt.dom.client.EventTarget;
22 import com.google.gwt.dom.client.NativeEvent;
23 import com.google.gwt.event.logical.shared.ValueChangeEvent;
24 import com.google.gwt.event.logical.shared.ValueChangeHandler;
25 import com.google.gwt.event.shared.HandlerRegistration;
26 import com.google.gwt.user.client.DOM;
27 import com.google.gwt.user.client.Element;
28 import com.google.gwt.user.client.Event;
29 import com.google.gwt.user.client.Event.NativePreviewEvent;
30 import com.google.gwt.user.client.Event.NativePreviewHandler;
31 import com.google.gwt.user.client.ui.CheckBox;
32 import com.google.gwt.user.client.ui.HTML;
33 import com.google.gwt.user.client.ui.HasVerticalAlignment;
34 import com.google.gwt.user.client.ui.SimplePanel;
35 import com.google.gwt.user.client.ui.VerticalPanel;
36
37 public class NodeWidget extends SimplePanel implements NativePreviewHandler {
38 private Node node;
39 HTML html = new HTML();
40 CheckBox checkBox = new CheckBox();
41 HandlerRegistration handlerRegistration;
42 VerticalPanel verticalPanel = new VerticalPanel();
43 public NodeWidget(Node<Token> n) {
44 Event.addNativePreviewHandler(this);
45
46 node = n;
47 super.setWidth("100%");
48 super.setHeight("100%");
49 setNode(n);
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 checkBox.addValueChangeHandler(new ValueChangeHandler(){
88 @Override
89 public void onValueChange(ValueChangeEvent event) {
90 if(checkBox.getValue() == true){
91 DOM.setStyleAttribute(NodeWidget.this.getElement(), "background", "#ffeeff");
92 }else{
93 DOM.setStyleAttribute(NodeWidget.this.getElement(), "background", "#ffffff");
94 }
95 }
96
97 });
98 }
99 @Override
100 public void onPreviewNativeEvent(NativePreviewEvent pevent) {
101 NativeEvent event = pevent.getNativeEvent();
102 EventTarget target = event.getEventTarget();
103
104 if(checkBox.getElement().isOrHasChild(Element.as(target))){
105 return;
106 }else if(this.getElement().is(Element.as(target)) &&
107 Event.as(event).getTypeInt() == Event.ONMOUSEDOWN ){
108 GWT.log("doing", null);
109 boolean before = checkBox.getValue();
110 checkBox.setValue(!before);
111 ValueChangeEvent.fireIfNotEqual(checkBox, before,checkBox.getValue());
112
113
114
115 }
116
117 }
118 public Node getNode() {
119 return node;
120 }
121
122 public void installCheckBox() {
123 verticalPanel.clear();
124 verticalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
125 verticalPanel.setWidth("100%");
126 verticalPanel.setHeight("100%");
127 verticalPanel.add(checkBox);
128 super.setWidget(verticalPanel);
129
130 }
131
132 public boolean isSelected() {
133 return checkBox.getValue() == true;
134 }
135
136 public void addSelectionHandler(ValueChangeHandler<Boolean> ch) {
137 if (handlerRegistration != null) {
138 handlerRegistration.removeHandler();
139 }
140 handlerRegistration = checkBox.addValueChangeHandler(ch);
141 }
142
143 public void setNode(Node n) {
144 node = n;
145 html.setHTML(node.getUserObject().toString());
146 checkBox.setHTML(node.getUserObject().toString());
147 }
148 }