1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.core.statement.ui.client.widgets.table; |
17 | |
|
18 | |
import org.kuali.student.core.statement.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 | 0 | HTML html = new HTML(); |
40 | 0 | CheckBox checkBox = new CheckBox(); |
41 | |
HandlerRegistration handlerRegistration; |
42 | 0 | VerticalPanel verticalPanel = new VerticalPanel(); |
43 | 0 | public NodeWidget(Node<Token> n) { |
44 | 0 | Event.addNativePreviewHandler(this); |
45 | |
|
46 | 0 | node = n; |
47 | 0 | super.setWidth("100%"); |
48 | 0 | super.setHeight("100%"); |
49 | 0 | 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 | 0 | checkBox.addValueChangeHandler(new ValueChangeHandler(){ |
88 | |
@Override |
89 | |
public void onValueChange(ValueChangeEvent event) { |
90 | 0 | if(checkBox.getValue() == true){ |
91 | 0 | DOM.setStyleAttribute(NodeWidget.this.getElement(), "background", "#ffeeff"); |
92 | |
}else{ |
93 | 0 | DOM.setStyleAttribute(NodeWidget.this.getElement(), "background", "#ffffff"); |
94 | |
} |
95 | 0 | } |
96 | |
|
97 | |
}); |
98 | 0 | } |
99 | |
@Override |
100 | |
public void onPreviewNativeEvent(NativePreviewEvent pevent) { |
101 | 0 | NativeEvent event = pevent.getNativeEvent(); |
102 | 0 | EventTarget target = event.getEventTarget(); |
103 | |
|
104 | 0 | if(checkBox.getElement().isOrHasChild(Element.as(target))){ |
105 | 0 | return; |
106 | 0 | }else if(this.getElement().is(Element.as(target)) && |
107 | |
Event.as(event).getTypeInt() == Event.ONMOUSEDOWN ){ |
108 | 0 | GWT.log("doing", null); |
109 | 0 | boolean before = checkBox.getValue(); |
110 | 0 | checkBox.setValue(!before); |
111 | 0 | ValueChangeEvent.fireIfNotEqual(checkBox, before,checkBox.getValue()); |
112 | |
|
113 | |
|
114 | |
|
115 | |
} |
116 | |
|
117 | 0 | } |
118 | |
public Node getNode() { |
119 | 0 | return node; |
120 | |
} |
121 | |
|
122 | |
public void installCheckBox() { |
123 | 0 | verticalPanel.clear(); |
124 | 0 | verticalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); |
125 | 0 | verticalPanel.setWidth("100%"); |
126 | 0 | verticalPanel.setHeight("100%"); |
127 | 0 | verticalPanel.add(checkBox); |
128 | 0 | super.setWidget(verticalPanel); |
129 | |
|
130 | 0 | } |
131 | |
|
132 | |
public boolean isSelected() { |
133 | 0 | return checkBox.getValue() == true; |
134 | |
} |
135 | |
|
136 | |
public void addSelectionHandler(ValueChangeHandler<Boolean> ch) { |
137 | 0 | if (handlerRegistration != null) { |
138 | 0 | handlerRegistration.removeHandler(); |
139 | |
} |
140 | 0 | handlerRegistration = checkBox.addValueChangeHandler(ch); |
141 | 0 | } |
142 | |
|
143 | |
public void setNode(Node n) { |
144 | 0 | node = n; |
145 | 0 | html.setHTML(node.getUserObject().toString()); |
146 | 0 | checkBox.setHTML(node.getUserObject().toString()); |
147 | 0 | } |
148 | |
} |