1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.ui.client.widgets.focus; |
17 |
|
|
18 |
|
import java.util.HashMap; |
19 |
|
import java.util.Map; |
20 |
|
|
21 |
|
import com.google.gwt.event.dom.client.BlurEvent; |
22 |
|
import com.google.gwt.event.dom.client.BlurHandler; |
23 |
|
import com.google.gwt.event.dom.client.FocusEvent; |
24 |
|
import com.google.gwt.event.dom.client.FocusHandler; |
25 |
|
import com.google.gwt.event.dom.client.HasBlurHandlers; |
26 |
|
import com.google.gwt.event.dom.client.HasFocusHandlers; |
27 |
|
import com.google.gwt.event.shared.GwtEvent; |
28 |
|
import com.google.gwt.event.shared.HandlerManager; |
29 |
|
import com.google.gwt.event.shared.HandlerRegistration; |
30 |
|
import com.google.gwt.event.shared.HasHandlers; |
31 |
|
import com.google.gwt.user.client.Command; |
32 |
|
import com.google.gwt.user.client.DeferredCommand; |
33 |
|
import com.google.gwt.user.client.ui.Widget; |
34 |
|
|
|
|
| 0% |
Uncovered Elements: 51 (51) |
Complexity: 18 |
Complexity Density: 0.64 |
|
35 |
|
public class FocusGroup implements HasBlurHandlers, HasFocusHandlers, HasHandlers { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: - |
|
36 |
|
private static class SyntheticBlurEvent extends BlurEvent { |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
37 |
0
|
public SyntheticBlurEvent() {... |
38 |
|
|
39 |
|
} |
40 |
|
} |
41 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: - |
|
42 |
|
private static class SyntheticFocusEvent extends FocusEvent { |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
43 |
0
|
public SyntheticFocusEvent() {... |
44 |
|
|
45 |
|
} |
46 |
|
} |
47 |
|
|
48 |
|
private final HandlerManager handlers; |
49 |
|
private final Map<Widget, Boolean> focusTrackers = new HashMap<Widget, Boolean>(); |
50 |
|
private boolean focusEventPending = false; |
51 |
|
private boolean suppressed = false; |
52 |
|
|
53 |
|
private boolean focused = false; |
54 |
|
|
55 |
|
private final Command checkFocusState = new Command() { |
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.45 |
|
56 |
0
|
@Override... |
57 |
|
public void execute() { |
58 |
0
|
focusEventPending = false; |
59 |
0
|
boolean nowFocused = false; |
60 |
0
|
for (final Boolean b : focusTrackers.values()) { |
61 |
0
|
if (b) { |
62 |
0
|
nowFocused = true; |
63 |
0
|
break; |
64 |
|
} |
65 |
|
} |
66 |
|
|
67 |
0
|
if (!suppressed && (focused ^ nowFocused)) { |
68 |
0
|
if (nowFocused) { |
69 |
|
|
70 |
|
|
71 |
0
|
handlers.fireEvent(new SyntheticFocusEvent()); |
72 |
|
} else { |
73 |
|
|
74 |
|
|
75 |
0
|
handlers.fireEvent(new SyntheticBlurEvent()); |
76 |
|
} |
77 |
|
} |
78 |
|
|
79 |
0
|
focused = nowFocused; |
80 |
|
} |
81 |
|
}; |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
0
|
public FocusGroup(final Widget parentWidget) {... |
84 |
0
|
this.handlers = new HandlerManager(parentWidget); |
85 |
|
} |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
87 |
0
|
@Override... |
88 |
|
public HandlerRegistration addBlurHandler(final BlurHandler handler) { |
89 |
0
|
return handlers.addHandler(BlurEvent.getType(), handler); |
90 |
|
} |
91 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
0
|
@Override... |
93 |
|
public HandlerRegistration addFocusHandler(final FocusHandler handler) { |
94 |
0
|
return handlers.addHandler(FocusEvent.getType(), handler); |
95 |
|
} |
96 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
97 |
0
|
public void addWidget(final Widget w) {... |
98 |
0
|
if (w instanceof HasBlurHandlers) { |
99 |
0
|
((HasBlurHandlers) w).addBlurHandler(new BlurHandler() { |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
100 |
0
|
@Override... |
101 |
|
public void onBlur(final BlurEvent event) { |
102 |
0
|
focusTrackers.put(w, false); |
103 |
0
|
queueCheckFocusState(); |
104 |
|
} |
105 |
|
}); |
106 |
|
} |
107 |
0
|
if (w instanceof HasFocusHandlers) { |
108 |
0
|
((HasFocusHandlers) w).addFocusHandler(new FocusHandler() { |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
109 |
0
|
@Override... |
110 |
|
public void onFocus(final FocusEvent event) { |
111 |
0
|
focusTrackers.put(w, true); |
112 |
0
|
queueCheckFocusState(); |
113 |
|
} |
114 |
|
}); |
115 |
|
} |
116 |
|
} |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
0
|
@Override... |
119 |
|
public void fireEvent(final GwtEvent<?> event) { |
120 |
0
|
handlers.fireEvent(event); |
121 |
|
} |
122 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
123 |
0
|
private void queueCheckFocusState() {... |
124 |
0
|
if (!focusEventPending) { |
125 |
0
|
focusEventPending = true; |
126 |
0
|
DeferredCommand.addCommand(checkFocusState); |
127 |
|
} |
128 |
|
} |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
0
|
public boolean isSuppressed() {... |
131 |
0
|
return suppressed; |
132 |
|
} |
133 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
134 |
0
|
public void setSuppressed(boolean suppressed) {... |
135 |
0
|
this.suppressed = suppressed; |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
} |