1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.autoquest.tasktrees.treeimpl; |
---|
16 | |
---|
17 | import java.util.List; |
---|
18 | |
---|
19 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; |
---|
20 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; |
---|
21 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; |
---|
22 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; |
---|
23 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; |
---|
24 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; |
---|
25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; |
---|
26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; |
---|
27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; |
---|
29 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
30 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; |
---|
31 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; |
---|
32 | |
---|
33 | /** |
---|
34 | * <p> |
---|
35 | * this is the default implementation of the interface {@link ITaskBuilder}. It |
---|
36 | * does not do anything fancy except implementing the interface. In some situations, it performs |
---|
37 | * a check if the model or instances to be created a valid. However, this can not be done |
---|
38 | * in any situation of the creation process. |
---|
39 | * </p> |
---|
40 | * |
---|
41 | * @author Patrick Harms |
---|
42 | */ |
---|
43 | public class TaskBuilder implements ITaskBuilder { |
---|
44 | |
---|
45 | /* (non-Javadoc) |
---|
46 | * @see ITaskBuilder#addChild(ISequenceInstance, ITaskInstance) |
---|
47 | */ |
---|
48 | @Override |
---|
49 | public void addChild(ISequenceInstance instance, ITaskInstance child) |
---|
50 | throws IllegalArgumentException |
---|
51 | { |
---|
52 | if (!(instance instanceof SequenceInstance)) { |
---|
53 | throw new IllegalArgumentException |
---|
54 | ("illegal type of sequence instance provided: " + instance.getClass()); |
---|
55 | } |
---|
56 | |
---|
57 | if (!(child instanceof TaskInstance)) { |
---|
58 | throw new IllegalArgumentException |
---|
59 | ("illegal type of task instance provided: " + child.getClass()); |
---|
60 | } |
---|
61 | |
---|
62 | /*IStructuringTemporalRelationship parentTask = |
---|
63 | (IStructuringTemporalRelationship) parent.getTask(); |
---|
64 | |
---|
65 | for (ITask parentTaskChild : parentTask.getChildren()) { |
---|
66 | if (parentTaskChild.equals(child.getTask())) { |
---|
67 | foundChildTask = true; |
---|
68 | break; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | if (!foundChildTask) { |
---|
73 | throw new IllegalArgumentException |
---|
74 | ("the task of the child instance to be added does not belong to the children " + |
---|
75 | "of the task of the parent instance"); |
---|
76 | }*/ |
---|
77 | |
---|
78 | ((SequenceInstance) instance).addChild(child); |
---|
79 | } |
---|
80 | |
---|
81 | /* (non-Javadoc) |
---|
82 | * @see ITaskBuilder#addChild(ISequenceInstance, int, ITaskInstance) |
---|
83 | */ |
---|
84 | public void addChild(ISequenceInstance instance, int index, ITaskInstance child) |
---|
85 | throws IllegalArgumentException |
---|
86 | { |
---|
87 | if (!(instance instanceof SequenceInstance)) { |
---|
88 | throw new IllegalArgumentException |
---|
89 | ("illegal type of sequence instance provided: " + instance.getClass()); |
---|
90 | } |
---|
91 | |
---|
92 | if (!(child instanceof TaskInstance)) { |
---|
93 | throw new IllegalArgumentException |
---|
94 | ("illegal type of task instance provided: " + child.getClass()); |
---|
95 | } |
---|
96 | |
---|
97 | /*IStructuringTemporalRelationship parentTask = |
---|
98 | (IStructuringTemporalRelationship) parent.getTask(); |
---|
99 | |
---|
100 | for (ITask parentTaskChild : parentTask.getChildren()) { |
---|
101 | if (parentTaskChild.equals(child.getTask())) { |
---|
102 | foundChildTask = true; |
---|
103 | break; |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | if (!foundChildTask) { |
---|
108 | throw new IllegalArgumentException |
---|
109 | ("the task of the child instance to be added does not belong to the children " + |
---|
110 | "of the task of the parent instance"); |
---|
111 | }*/ |
---|
112 | |
---|
113 | ((SequenceInstance) instance).addChild(index, child); |
---|
114 | } |
---|
115 | |
---|
116 | /* (non-Javadoc) |
---|
117 | * @see ITaskBuilder#addChild(IIterationInstance, ITaskInstance) |
---|
118 | */ |
---|
119 | @Override |
---|
120 | public void addChild(IIterationInstance instance, ITaskInstance child) |
---|
121 | throws IllegalArgumentException |
---|
122 | { |
---|
123 | if (!(instance instanceof IterationInstance)) { |
---|
124 | throw new IllegalArgumentException |
---|
125 | ("illegal type of iteration instance provided: " + instance.getClass()); |
---|
126 | } |
---|
127 | |
---|
128 | if (!(child instanceof TaskInstance)) { |
---|
129 | throw new IllegalArgumentException |
---|
130 | ("illegal type of task instance provided: " + child.getClass()); |
---|
131 | } |
---|
132 | |
---|
133 | /*IStructuringTemporalRelationship parentTask = |
---|
134 | (IStructuringTemporalRelationship) parent.getTask(); |
---|
135 | |
---|
136 | IMarkingTemporalRelationship parentTask = |
---|
137 | (IMarkingTemporalRelationship) parent.getTask(); |
---|
138 | |
---|
139 | foundChildTask = parentTask.getMarkedTask() != null ? |
---|
140 | parentTask.getMarkedTask().equals(child.getTask()) : false; |
---|
141 | |
---|
142 | if (!foundChildTask) { |
---|
143 | throw new IllegalArgumentException |
---|
144 | ("the task of the child instance to be added does not belong to the children " + |
---|
145 | "of the task of the parent instance"); |
---|
146 | }*/ |
---|
147 | |
---|
148 | ((IterationInstance) instance).addChild(child); |
---|
149 | } |
---|
150 | |
---|
151 | /* (non-Javadoc) |
---|
152 | * @see ITaskBuilder#addChild(IIterationInstance, int, ITaskInstance) |
---|
153 | */ |
---|
154 | public void addChild(IIterationInstance instance, int index, ITaskInstance child) |
---|
155 | throws IllegalArgumentException |
---|
156 | { |
---|
157 | if (!(instance instanceof IterationInstance)) { |
---|
158 | throw new IllegalArgumentException |
---|
159 | ("illegal type of iteration instance provided: " + instance.getClass()); |
---|
160 | } |
---|
161 | |
---|
162 | if (!(child instanceof TaskInstance)) { |
---|
163 | throw new IllegalArgumentException |
---|
164 | ("illegal type of task instance provided: " + child.getClass()); |
---|
165 | } |
---|
166 | |
---|
167 | /*IStructuringTemporalRelationship parentTask = |
---|
168 | (IStructuringTemporalRelationship) parent.getTask(); |
---|
169 | |
---|
170 | IMarkingTemporalRelationship parentTask = |
---|
171 | (IMarkingTemporalRelationship) parent.getTask(); |
---|
172 | |
---|
173 | foundChildTask = parentTask.getMarkedTask() != null ? |
---|
174 | parentTask.getMarkedTask().equals(child.getTask()) : false; |
---|
175 | |
---|
176 | if (!foundChildTask) { |
---|
177 | throw new IllegalArgumentException |
---|
178 | ("the task of the child instance to be added does not belong to the children " + |
---|
179 | "of the task of the parent instance"); |
---|
180 | }*/ |
---|
181 | |
---|
182 | ((IterationInstance) instance).addChild(index, child); |
---|
183 | } |
---|
184 | |
---|
185 | /* (non-Javadoc) |
---|
186 | * @see ITaskBuilder#setChild(ISelectionInstance, ITaskInstance) |
---|
187 | */ |
---|
188 | @Override |
---|
189 | public void setChild(ISelectionInstance instance, ITaskInstance child) |
---|
190 | throws IllegalArgumentException |
---|
191 | { |
---|
192 | if (!(instance instanceof SelectionInstance)) { |
---|
193 | throw new IllegalArgumentException |
---|
194 | ("illegal type of selection instance provided: " + instance.getClass()); |
---|
195 | } |
---|
196 | |
---|
197 | if (!(child instanceof TaskInstance)) { |
---|
198 | throw new IllegalArgumentException("illegal type of task instance provided: " + |
---|
199 | (child == null ? null : child.getClass())); |
---|
200 | } |
---|
201 | |
---|
202 | /*IStructuringTemporalRelationship parentTask = |
---|
203 | (IStructuringTemporalRelationship) parent.getTask(); |
---|
204 | |
---|
205 | for (ITask parentTaskChild : parentTask.getChildren()) { |
---|
206 | if (parentTaskChild.equals(child.getTask())) { |
---|
207 | foundChildTask = true; |
---|
208 | break; |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | if (!foundChildTask) { |
---|
213 | throw new IllegalArgumentException |
---|
214 | ("the task of the child instance to be added does not belong to the children " + |
---|
215 | "of the task of the parent instance"); |
---|
216 | }*/ |
---|
217 | |
---|
218 | ((SelectionInstance) instance).setChild(child); |
---|
219 | } |
---|
220 | |
---|
221 | /* (non-Javadoc) |
---|
222 | * @see ITaskBuilder#setChild(IOptionalInstance, ITaskInstance) |
---|
223 | */ |
---|
224 | @Override |
---|
225 | public void setChild(IOptionalInstance instance, ITaskInstance child) |
---|
226 | throws IllegalArgumentException |
---|
227 | { |
---|
228 | if (!(instance instanceof OptionalInstance)) { |
---|
229 | throw new IllegalArgumentException |
---|
230 | ("illegal type of optional instance provided: " + instance.getClass()); |
---|
231 | } |
---|
232 | |
---|
233 | if (!(child instanceof TaskInstance)) { |
---|
234 | throw new IllegalArgumentException |
---|
235 | ("illegal type of task instance provided: " + child.getClass()); |
---|
236 | } |
---|
237 | |
---|
238 | /*IStructuringTemporalRelationship parentTask = |
---|
239 | (IStructuringTemporalRelationship) parent.getTask(); |
---|
240 | |
---|
241 | IMarkingTemporalRelationship parentTask = |
---|
242 | (IMarkingTemporalRelationship) parent.getTask(); |
---|
243 | |
---|
244 | foundChildTask = parentTask.getMarkedTask() != null ? |
---|
245 | parentTask.getMarkedTask().equals(child.getTask()) : false; |
---|
246 | |
---|
247 | if (!foundChildTask) { |
---|
248 | throw new IllegalArgumentException |
---|
249 | ("the task of the child instance to be added does not belong to the children " + |
---|
250 | "of the task of the parent instance"); |
---|
251 | }*/ |
---|
252 | |
---|
253 | ((OptionalInstance) instance).setChild(child); |
---|
254 | } |
---|
255 | |
---|
256 | /* (non-Javadoc) |
---|
257 | * @see ITaskBuilder#addExecutedTask(IUserSession, ITaskInstance) |
---|
258 | */ |
---|
259 | @Override |
---|
260 | public void addExecutedTask(IUserSession session, ITaskInstance taskInstance) { |
---|
261 | if (!(session instanceof UserSession)) { |
---|
262 | throw new IllegalArgumentException |
---|
263 | ("illegal type of session provided: " + session.getClass()); |
---|
264 | } |
---|
265 | |
---|
266 | if (!(taskInstance instanceof TaskInstance)) { |
---|
267 | throw new IllegalArgumentException |
---|
268 | ("illegal type of task instance provided: " + taskInstance.getClass()); |
---|
269 | } |
---|
270 | |
---|
271 | ((UserSession) session).addExecutedTask(taskInstance); |
---|
272 | } |
---|
273 | |
---|
274 | /* (non-Javadoc) |
---|
275 | * @see ITaskBuilder#addExecutedTask(IUserSession, int, ITaskInstance) |
---|
276 | */ |
---|
277 | public void addExecutedTask(IUserSession session, int index, ITaskInstance taskInstance) { |
---|
278 | if (!(session instanceof UserSession)) { |
---|
279 | throw new IllegalArgumentException |
---|
280 | ("illegal type of session provided: " + session.getClass()); |
---|
281 | } |
---|
282 | |
---|
283 | if (!(taskInstance instanceof TaskInstance)) { |
---|
284 | throw new IllegalArgumentException |
---|
285 | ("illegal type of task instance provided: " + taskInstance.getClass()); |
---|
286 | } |
---|
287 | |
---|
288 | ((UserSession) session).addExecutedTask(index, taskInstance); |
---|
289 | } |
---|
290 | |
---|
291 | /* (non-Javadoc) |
---|
292 | * @see ITaskBuilder#addTaskInstance(ITaskInstanceList, ITaskInstance) |
---|
293 | */ |
---|
294 | @Override |
---|
295 | public void addTaskInstance(ITaskInstanceList taskInstanceList, ITaskInstance taskInstance) { |
---|
296 | if (taskInstanceList instanceof SequenceInstance) { |
---|
297 | addChild((SequenceInstance) taskInstanceList, taskInstance); |
---|
298 | } |
---|
299 | else if (taskInstanceList instanceof IterationInstance) { |
---|
300 | addChild((IterationInstance) taskInstanceList, taskInstance); |
---|
301 | } |
---|
302 | else if (taskInstanceList instanceof UserSession) { |
---|
303 | addExecutedTask((UserSession) taskInstanceList, taskInstance); |
---|
304 | } |
---|
305 | else { |
---|
306 | throw new IllegalArgumentException |
---|
307 | ("illegal type of task instance list provided: " + taskInstanceList.getClass()); |
---|
308 | } |
---|
309 | } |
---|
310 | |
---|
311 | /* (non-Javadoc) |
---|
312 | * @see ITaskBuilder#addTaskInstance(ITaskInstanceList, int, ITaskInstance) |
---|
313 | */ |
---|
314 | @Override |
---|
315 | public void addTaskInstance(ITaskInstanceList taskInstanceList, |
---|
316 | int index, |
---|
317 | ITaskInstance taskInstance) |
---|
318 | { |
---|
319 | if (taskInstanceList instanceof SequenceInstance) { |
---|
320 | addChild((SequenceInstance) taskInstanceList, index, taskInstance); |
---|
321 | } |
---|
322 | else if (taskInstanceList instanceof IterationInstance) { |
---|
323 | addChild((IterationInstance) taskInstanceList, index, taskInstance); |
---|
324 | } |
---|
325 | else if (taskInstanceList instanceof UserSession) { |
---|
326 | addExecutedTask((UserSession) taskInstanceList, index, taskInstance); |
---|
327 | } |
---|
328 | else { |
---|
329 | throw new IllegalArgumentException |
---|
330 | ("illegal type of task instance list provided: " + taskInstanceList.getClass()); |
---|
331 | } |
---|
332 | } |
---|
333 | |
---|
334 | /* (non-Javadoc) |
---|
335 | * @see ITaskBuilder#setTaskInstance(ITaskInstanceList, int, ITaskInstance) |
---|
336 | */ |
---|
337 | @Override |
---|
338 | public void setTaskInstance(ITaskInstanceList taskInstanceList, |
---|
339 | int index, |
---|
340 | ITaskInstance taskInstance) |
---|
341 | { |
---|
342 | removeTaskInstance(taskInstanceList, index); |
---|
343 | addTaskInstance(taskInstanceList, index, taskInstance); |
---|
344 | } |
---|
345 | |
---|
346 | /* (non-Javadoc) |
---|
347 | * @see ITaskBuilder#setTask(ITaskInstance, ITask) |
---|
348 | */ |
---|
349 | @Override |
---|
350 | public void setTask(ITaskInstance taskInstance, ITask task) { |
---|
351 | if (!(taskInstance instanceof TaskInstance)) { |
---|
352 | throw new IllegalArgumentException |
---|
353 | ("illegal type of task instance provided: " + taskInstance.getClass()); |
---|
354 | } |
---|
355 | if (!(task instanceof Task)) { |
---|
356 | throw new IllegalArgumentException("illegal type of task provided: " + task.getClass()); |
---|
357 | } |
---|
358 | |
---|
359 | if (((TaskInstance) taskInstance).getTask() instanceof Task) { |
---|
360 | ((Task) ((TaskInstance) taskInstance).getTask()).removeInstance(taskInstance); |
---|
361 | } |
---|
362 | ((TaskInstance) taskInstance).setTask(task); |
---|
363 | |
---|
364 | ((Task) task).addInstance(taskInstance); |
---|
365 | } |
---|
366 | |
---|
367 | /* (non-Javadoc) |
---|
368 | * @see ITaskBuilder#addChild(ISequence, ITask) |
---|
369 | */ |
---|
370 | @Override |
---|
371 | public void addChild(ISequence parent, ITask child) { |
---|
372 | if (!(parent instanceof Sequence)) { |
---|
373 | throw new IllegalArgumentException |
---|
374 | ("illegal type of sequence provided: " + parent.getClass()); |
---|
375 | } |
---|
376 | |
---|
377 | addChildInternal((Sequence) parent, -1, child); |
---|
378 | } |
---|
379 | |
---|
380 | /* (non-Javadoc) |
---|
381 | * @see ITaskBuilder#addChild(ISequence, int, ITask) |
---|
382 | */ |
---|
383 | @Override |
---|
384 | public void addChild(ISequence parent, int index, ITask child) { |
---|
385 | if (!(parent instanceof Sequence)) { |
---|
386 | throw new IllegalArgumentException |
---|
387 | ("illegal type of sequence provided: " + parent.getClass()); |
---|
388 | } |
---|
389 | |
---|
390 | addChildInternal((Sequence) parent, index, child); |
---|
391 | } |
---|
392 | |
---|
393 | /* (non-Javadoc) |
---|
394 | * @see ITaskBuilder#setChild(ISequence, int, ITask) |
---|
395 | */ |
---|
396 | @Override |
---|
397 | public void setChild(ISequence parent, int index, ITask child) { |
---|
398 | if (!(parent instanceof Sequence)) { |
---|
399 | throw new IllegalArgumentException |
---|
400 | ("illegal type of sequence provided: " + parent.getClass()); |
---|
401 | } |
---|
402 | |
---|
403 | ((Sequence) parent).removeChild(index); |
---|
404 | addChildInternal((Sequence) parent, index, child); |
---|
405 | } |
---|
406 | |
---|
407 | /* (non-Javadoc) |
---|
408 | * @see ITaskBuilder#addChild(ISelection, ITask) |
---|
409 | */ |
---|
410 | @Override |
---|
411 | public void addChild(ISelection parent, ITask child) { |
---|
412 | if (!(parent instanceof Selection)) { |
---|
413 | throw new IllegalArgumentException |
---|
414 | ("illegal type of selection provided: " + parent.getClass()); |
---|
415 | } |
---|
416 | |
---|
417 | addChildInternal((Selection) parent, -1, child); |
---|
418 | } |
---|
419 | |
---|
420 | /* (non-Javadoc) |
---|
421 | * @see ITaskBuilder#setMarkedTask(IIteration, ITask) |
---|
422 | */ |
---|
423 | @Override |
---|
424 | public void setMarkedTask(IIteration iteration, ITask newChild) { |
---|
425 | if (!(iteration instanceof Iteration)) { |
---|
426 | throw new IllegalArgumentException |
---|
427 | ("illegal type of iteration provided: " + iteration.getClass()); |
---|
428 | } |
---|
429 | |
---|
430 | if (!(newChild instanceof Task)) { |
---|
431 | throw new IllegalArgumentException |
---|
432 | ("illegal type of task provided: " + newChild.getClass()); |
---|
433 | } |
---|
434 | |
---|
435 | ((Iteration) iteration).setMarkedTask(newChild); |
---|
436 | } |
---|
437 | |
---|
438 | /* (non-Javadoc) |
---|
439 | * @see ITaskTreeBuilder#setChild(IOptional, ITaskTreeNode) |
---|
440 | */ |
---|
441 | @Override |
---|
442 | public void setMarkedTask(IOptional optional, ITask newChild) { |
---|
443 | if (!(optional instanceof Optional)) { |
---|
444 | throw new IllegalArgumentException |
---|
445 | ("illegal type of optional provided: " + optional.getClass()); |
---|
446 | } |
---|
447 | |
---|
448 | if (!(newChild instanceof Task)) { |
---|
449 | throw new IllegalArgumentException |
---|
450 | ("illegal type of task provided: " + newChild.getClass()); |
---|
451 | } |
---|
452 | |
---|
453 | ((Optional) optional).setMarkedTask(newChild); |
---|
454 | } |
---|
455 | |
---|
456 | /* (non-Javadoc) |
---|
457 | * @see ITaskBuilder#removeChild(ISequence, int) |
---|
458 | */ |
---|
459 | @Override |
---|
460 | public void removeChild(ISequence parent, int index) { |
---|
461 | if (!(parent instanceof Sequence)) { |
---|
462 | throw new IllegalArgumentException |
---|
463 | ("illegal type of sequence provided: " + parent.getClass()); |
---|
464 | } |
---|
465 | |
---|
466 | ((Sequence) parent).removeChild(index); |
---|
467 | } |
---|
468 | |
---|
469 | /* (non-Javadoc) |
---|
470 | * @see ITaskBuilder#removeChild(ISelection, ITask) |
---|
471 | */ |
---|
472 | @Override |
---|
473 | public void removeChild(ISelection parent, ITask child) { |
---|
474 | if (!(parent instanceof Selection)) { |
---|
475 | throw new IllegalArgumentException |
---|
476 | ("illegal type of selection provided: " + parent.getClass()); |
---|
477 | } |
---|
478 | |
---|
479 | List<ITask> children = parent.getChildren(); |
---|
480 | |
---|
481 | for (int i = 0; i < children.size(); i++) { |
---|
482 | if ((children.get(i) == child) || |
---|
483 | ((children.get(i) != null) && (children.get(i).equals(child)))) |
---|
484 | { |
---|
485 | ((Selection) parent).removeChild(i); |
---|
486 | break; |
---|
487 | } |
---|
488 | } |
---|
489 | } |
---|
490 | |
---|
491 | /* (non-Javadoc) |
---|
492 | * @see ITaskBuilder#removeTaskInstance(ITaskInstanceList, int) |
---|
493 | */ |
---|
494 | @Override |
---|
495 | public void removeTaskInstance(ITaskInstanceList taskInstanceList, int index) { |
---|
496 | if (taskInstanceList instanceof SequenceInstance) { |
---|
497 | ((SequenceInstance) taskInstanceList).removeChild(index); |
---|
498 | } |
---|
499 | else if (taskInstanceList instanceof IterationInstance) { |
---|
500 | ((IterationInstance) taskInstanceList).removeChild(index); |
---|
501 | } |
---|
502 | else if (taskInstanceList instanceof UserSession) { |
---|
503 | ((UserSession) taskInstanceList).removeExecutedTask(index); |
---|
504 | } |
---|
505 | else { |
---|
506 | throw new IllegalArgumentException |
---|
507 | ("illegal type of task instance list provided: " + taskInstanceList.getClass()); |
---|
508 | } |
---|
509 | } |
---|
510 | |
---|
511 | /* (non-Javadoc) |
---|
512 | * @see ITaskTreeBuilder#replaceChild(ISelection, ITaskTreeNode, ITaskTreeNode) |
---|
513 | */ |
---|
514 | @Override |
---|
515 | public void replaceChild(ISelection parent, ITask oldChild, ITask newChild) { |
---|
516 | if (!(parent instanceof Selection)) { |
---|
517 | throw new IllegalArgumentException |
---|
518 | ("illegal type of selection provided: " + parent.getClass()); |
---|
519 | } |
---|
520 | |
---|
521 | List<ITask> children = parent.getChildren(); |
---|
522 | |
---|
523 | for (int i = 0; i < children.size(); i++) { |
---|
524 | if ((children.get(i) == oldChild) || |
---|
525 | ((children.get(i) != null) && (children.get(i).equals(oldChild)))) |
---|
526 | { |
---|
527 | ((Selection) parent).removeChild(i); |
---|
528 | ((Selection) parent).addChild(i, newChild); |
---|
529 | break; |
---|
530 | } |
---|
531 | } |
---|
532 | } |
---|
533 | |
---|
534 | /** |
---|
535 | * <p> |
---|
536 | * internal convenience method for adding children to a structuring temporal relationship |
---|
537 | * including a check for the child type. |
---|
538 | * </p> |
---|
539 | */ |
---|
540 | private void addChildInternal(StructuringTemporalRelationship parent, int index, ITask child) { |
---|
541 | if (!(child instanceof Task)) { |
---|
542 | throw new IllegalArgumentException |
---|
543 | ("illegal type of task provided: " + child.getClass()); |
---|
544 | } |
---|
545 | |
---|
546 | if (index > -1) { |
---|
547 | parent.addChild(index, child); |
---|
548 | } |
---|
549 | else { |
---|
550 | parent.addChild(child); |
---|
551 | } |
---|
552 | } |
---|
553 | |
---|
554 | } |
---|