1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.util.dialogrunner; |
22 |
|
|
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
@author |
34 |
|
|
35 |
|
@param |
36 |
|
|
37 |
|
|
38 |
|
|
|
|
| 1.8% |
Uncovered Elements: 107 (109) |
Complexity: 33 |
Complexity Density: 0.52 |
|
39 |
|
public class DialogRunner<T extends DialogRunnerI> implements DialogRunnerI |
40 |
|
{ |
41 |
|
|
42 |
|
private Map<Response, List<RunResponse>> callbacks = new java.util.HashMap<>(); |
43 |
|
|
44 |
|
public T dialog; |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
46 |
12 |
public DialogRunner(T ourDialog)... |
47 |
|
{ |
48 |
12 |
dialog = ourDialog; |
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
55 |
0 |
public void resetResponses()... |
56 |
|
{ |
57 |
0 |
for (List<RunResponse> lr : callbacks.values()) |
58 |
|
{ |
59 |
0 |
for (RunResponse response : lr) |
60 |
|
{ |
61 |
0 |
response.reset(); |
62 |
|
} |
63 |
|
} |
64 |
0 |
responses.clear(); |
65 |
0 |
if (defaultResponse != null) |
66 |
|
{ |
67 |
0 |
defaultResponse.reset(); |
68 |
|
} |
69 |
0 |
firstRunWasCalled = false; |
70 |
|
} |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
0 |
@Override... |
73 |
|
public T response(RunResponse action) |
74 |
|
{ |
75 |
0 |
return addResponse(false, action); |
76 |
|
} |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
@param |
83 |
|
@return |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
0 |
public T firstResponse(RunResponse action)... |
86 |
|
{ |
87 |
0 |
return addResponse(true, action); |
88 |
|
} |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
90 |
0 |
protected T addResponse(boolean prePend, RunResponse action)... |
91 |
|
{ |
92 |
0 |
List<RunResponse> laction = callbacks.get(action.ourTrigger); |
93 |
0 |
if (laction == null) |
94 |
|
{ |
95 |
0 |
laction = new ArrayList<>(); |
96 |
0 |
callbacks.put(action.ourTrigger, laction); |
97 |
|
} |
98 |
0 |
if (prePend) |
99 |
|
{ |
100 |
0 |
laction.add(0,action); |
101 |
|
} else { |
102 |
0 |
laction.add(action); |
103 |
|
} |
104 |
0 |
return dialog; |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
@param |
110 |
|
@return |
111 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
112 |
0 |
public boolean isRegistered(RunResponse action)... |
113 |
|
{ |
114 |
0 |
List<RunResponse> resp = callbacks.get(action.ourTrigger); |
115 |
0 |
if (resp != null) |
116 |
|
{ |
117 |
0 |
for (RunResponse r : resp) |
118 |
|
{ |
119 |
0 |
if (r == action) |
120 |
|
{ |
121 |
0 |
return true; |
122 |
|
} |
123 |
|
} |
124 |
|
} |
125 |
0 |
return false; |
126 |
|
} |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
@param |
131 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
132 |
0 |
public void run(int responseCode)... |
133 |
|
{ |
134 |
0 |
run(new Response(responseCode)); |
135 |
|
} |
136 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
137 |
0 |
public void run(String responseString)... |
138 |
|
{ |
139 |
0 |
run(new Response(responseString)); |
140 |
|
} |
141 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
0 |
public void run(Object responseObj)... |
143 |
|
{ |
144 |
0 |
run(new Response(responseObj)); |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
@param |
151 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
152 |
0 |
public void firstRun(int responseCode)... |
153 |
|
{ |
154 |
0 |
doFirstRun(new Response(responseCode)); |
155 |
|
} |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
0 |
public void firstRun(String responseString)... |
158 |
|
{ |
159 |
0 |
doFirstRun(new Response(responseString)); |
160 |
|
} |
161 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
162 |
0 |
public void firstRun(Object responseObj)... |
163 |
|
{ |
164 |
0 |
if (responseObj != null && !responseObj.equals(responseObj)) |
165 |
|
{ |
166 |
|
|
167 |
|
|
168 |
0 |
return; |
169 |
|
} |
170 |
0 |
doFirstRun(new Response(responseObj)); |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
boolean firstRunWasCalled = false; |
175 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
176 |
0 |
private void doFirstRun(Response response)... |
177 |
|
{ |
178 |
0 |
if (firstRunWasCalled) |
179 |
|
{ |
180 |
0 |
return; |
181 |
|
} |
182 |
0 |
firstRunWasCalled = true; |
183 |
0 |
run(response); |
184 |
|
} |
185 |
|
|
|
|
| 0% |
Uncovered Elements: 39 (39) |
Complexity: 9 |
Complexity Density: 0.36 |
|
186 |
0 |
private void run(Response response)... |
187 |
|
{ |
188 |
0 |
if (response.objresp != null |
189 |
|
&& !response.objresp.equals(response.objresp)) |
190 |
|
{ |
191 |
|
|
192 |
|
|
193 |
0 |
return; |
194 |
|
} |
195 |
0 |
responses.add(response); |
196 |
|
|
197 |
0 |
List<RunResponse> laction = response.isNull() ? null : callbacks.get(response); |
198 |
|
|
199 |
0 |
if (laction == null) |
200 |
|
{ |
201 |
0 |
if (defaultResponse != null) |
202 |
|
{ |
203 |
0 |
defaultResponse.ourTrigger = response; |
204 |
0 |
defaultResponse.wasRun = true; |
205 |
0 |
defaultResponse.run(); |
206 |
|
} |
207 |
|
else |
208 |
|
{ |
209 |
0 |
System.err.println("Doing nothing for " + response); |
210 |
|
} |
211 |
0 |
return; |
212 |
|
} |
213 |
0 |
boolean wasRun = false; |
214 |
0 |
int num = 0; |
215 |
0 |
for (RunResponse action : laction) |
216 |
|
{ |
217 |
0 |
num++; |
218 |
|
|
219 |
0 |
if (!action.wasRun) |
220 |
|
{ |
221 |
0 |
System.err |
222 |
|
.println("Executing action (" + num + ") for " + response); |
223 |
0 |
wasRun = true; |
224 |
0 |
action.wasRun = true; |
225 |
0 |
action.run(); |
226 |
0 |
if (action.returned != null) |
227 |
|
{ |
228 |
0 |
run(action.returned); |
229 |
|
} |
230 |
0 |
break; |
231 |
|
} |
232 |
|
} |
233 |
0 |
if (!wasRun) |
234 |
|
{ |
235 |
0 |
System.err.println("Did nothing for " + response); |
236 |
|
} |
237 |
|
} |
238 |
|
|
239 |
|
List<Response> responses = new ArrayList<>(); |
240 |
|
|
241 |
|
RunResponse defaultResponse = null; |
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
@param |
247 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
248 |
0 |
public void setDefaultResponse(Runnable runnable)... |
249 |
|
{ |
250 |
0 |
defaultResponse = new RunResponse(runnable) |
251 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
252 |
0 |
@Override... |
253 |
|
public void run() |
254 |
|
{ |
255 |
0 |
runnable.run(); |
256 |
|
} |
257 |
|
}; |
258 |
|
} |
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
@param |
265 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
266 |
0 |
public void setDefaultResponse(RunResponse runnable)... |
267 |
|
{ |
268 |
0 |
defaultResponse = runnable; |
269 |
|
} |
270 |
|
} |