18
18
import java .util .Collection ;
19
19
import java .util .logging .Logger ;
20
20
21
+ import com .google .gwt .core .client .Scheduler ;
21
22
import com .google .gwt .dom .client .BrowserEvents ;
22
23
import com .google .gwt .dom .client .Element ;
23
24
import com .google .gwt .event .dom .client .KeyCodes ;
24
25
import com .google .gwt .user .client .Event ;
25
26
import com .google .web .bindery .event .shared .HandlerRegistration ;
26
- import com .vaadin .client .communication . StateChangeEvent ;
27
+ import com .vaadin .client .annotations . OnStateChange ;
27
28
import com .vaadin .client .connectors .grid .GridConnector ;
28
29
import com .vaadin .client .renderers .ClickableRenderer ;
29
30
import com .vaadin .client .renderers .HierarchyRenderer ;
43
44
44
45
/**
45
46
* A connector class for the TreeGrid component.
46
- *
47
+ *
47
48
* @author Vaadin Ltd
48
49
* @since 8.1
49
50
*/
@@ -67,13 +68,18 @@ public TreeGridState getState() {
67
68
return (TreeGridState ) super .getState ();
68
69
}
69
70
70
- @ Override
71
- public void onStateChanged (StateChangeEvent stateChangeEvent ) {
72
- super .onStateChanged (stateChangeEvent );
73
-
74
- if (stateChangeEvent .hasPropertyChanged ("hierarchyColumnId" )
75
- || stateChangeEvent .hasPropertyChanged ("columns" )) {
76
-
71
+ /**
72
+ * This method has been scheduled finally to avoid possible race conditions
73
+ * between state change handling for the Grid and its columns. The renderer
74
+ * of the column is set in a state change handler, and might not be
75
+ * available when this method is executed.
76
+ * <p>
77
+ * TODO: This might need some clean up if we decide to allow setting a new
78
+ * renderer for hierarchy columns.
79
+ */
80
+ @ OnStateChange ("hierarchyColumnId" )
81
+ void updateHierarchyColumn () {
82
+ Scheduler .get ().scheduleFinally (() -> {
77
83
// Id of old hierarchy column
78
84
String oldHierarchyColumnId = this .hierarchyColumnId ;
79
85
@@ -111,7 +117,7 @@ public void onStateChanged(StateChangeEvent stateChangeEvent) {
111
117
Logger .getLogger (TreeGridConnector .class .getName ()).warning (
112
118
"Couldn't find column: " + newHierarchyColumnId );
113
119
}
114
- }
120
+ });
115
121
}
116
122
117
123
private HierarchyRenderer getHierarchyRenderer () {
@@ -159,18 +165,21 @@ public void onUnregister() {
159
165
}
160
166
161
167
private native void replaceCellFocusEventHandler (Grid <?> grid ,
162
- GridEventHandler <?> eventHandler )/*-{
168
+ GridEventHandler <?> eventHandler )
169
+ /*-{
163
170
var browserEventHandlers = [email protected] ::browserEventHandlers;
164
-
171
+
165
172
// FocusEventHandler is initially 5th in the list of browser event handlers
166
173
[email protected] ::set(*)(5, eventHandler);
167
174
}-*/ ;
168
175
169
- private native void replaceClickEvent (Grid <?> grid , GridClickEvent event )/*-{
176
+ private native void replaceClickEvent (Grid <?> grid , GridClickEvent event )
177
+ /*-{
170
178
[email protected] ::clickEvent = event;
171
179
}-*/ ;
172
180
173
- private native EventCellReference <?> getEventCell (Grid <?> grid )/*-{
181
+ private native EventCellReference <?> getEventCell (Grid <?> grid )
182
+ /*-{
174
183
return [email protected] ::eventCell;
175
184
}-*/ ;
176
185
@@ -213,13 +222,15 @@ public void onEvent(Grid.GridEvent<JsonObject> event) {
213
222
}
214
223
}
215
224
216
- private native Collection <String > getNavigationEvents (Grid <?> grid )/*-{
217
- return [email protected] ::cellFocusHandler
218
- [email protected] ::getNavigationEvents()();
225
+ private native Collection <String > getNavigationEvents (Grid <?> grid )
226
+ /*-{
227
+ return [email protected] ::cellFocusHandler
228
+ [email protected] ::getNavigationEvents()();
219
229
}-*/ ;
220
230
221
231
private native void handleNavigationEvent (Grid <?> grid ,
222
- Grid .GridEvent <JsonObject > event )/*-{
232
+ Grid .GridEvent <JsonObject > event )
233
+ /*-{
223
234
[email protected] ::cellFocusHandler
224
235
[email protected] ::handleNavigationEvent(*)(
225
236
[email protected] ::getDomEvent()(),
0 commit comments