1 | // Module : $RCSfile: TaskTreeBuilderImpl.java,v $ |
---|
2 | // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 21.02.2012 $ |
---|
3 | // Project : TaskTreeCreator |
---|
4 | // Creation : 2012 by patrick |
---|
5 | // Copyright : Patrick Harms, 2012 |
---|
6 | |
---|
7 | package de.ugoe.cs.quest.tasktrees.treeimpl; |
---|
8 | |
---|
9 | import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; |
---|
10 | import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; |
---|
11 | import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; |
---|
12 | import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; |
---|
13 | import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; |
---|
14 | import de.ugoe.cs.quest.tasktrees.treeifc.ITextInputEventTask; |
---|
15 | |
---|
16 | /** |
---|
17 | * TODO comment |
---|
18 | * |
---|
19 | * @version $Revision: $ $Date: 21.02.2012$ |
---|
20 | * @author 2012, last modified by $Author: patrick$ |
---|
21 | */ |
---|
22 | public class TaskTreeBuilder implements ITaskTreeBuilder { |
---|
23 | |
---|
24 | /* |
---|
25 | * (non-Javadoc) |
---|
26 | * |
---|
27 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, TaskTreeNode) |
---|
28 | */ |
---|
29 | @Override |
---|
30 | public void addChild(ISequence parent, ITaskTreeNode child) { |
---|
31 | if (!(parent instanceof Sequence)) { |
---|
32 | throw new IllegalArgumentException |
---|
33 | ("illegal type of task tree node provided: " + parent.getClass()); |
---|
34 | } |
---|
35 | |
---|
36 | addChildInternal(parent, -1, child); |
---|
37 | } |
---|
38 | |
---|
39 | /* |
---|
40 | * (non-Javadoc) |
---|
41 | * |
---|
42 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Sequence, int, TaskTreeNode) |
---|
43 | */ |
---|
44 | @Override |
---|
45 | public void addChild(ISequence parent, int index, ITaskTreeNode child) { |
---|
46 | if (!(parent instanceof Sequence)) { |
---|
47 | throw new IllegalArgumentException |
---|
48 | ("illegal type of task tree node provided: " + parent.getClass()); |
---|
49 | } |
---|
50 | |
---|
51 | addChildInternal(parent, index, child); |
---|
52 | } |
---|
53 | |
---|
54 | /* |
---|
55 | * (non-Javadoc) |
---|
56 | * |
---|
57 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(Selection, TaskTreeNode) |
---|
58 | */ |
---|
59 | @Override |
---|
60 | public void addChild(ISelection parent, ITaskTreeNode child) { |
---|
61 | if (!(parent instanceof Selection)) { |
---|
62 | throw new IllegalArgumentException |
---|
63 | ("illegal type of task tree node provided: " + parent.getClass()); |
---|
64 | } |
---|
65 | |
---|
66 | addChildInternal(parent, -1, child); |
---|
67 | } |
---|
68 | |
---|
69 | /* |
---|
70 | * (non-Javadoc) |
---|
71 | * |
---|
72 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#addChild(de.ugoe.cs.tasktree.treeifc. |
---|
73 | * TextInputEventTask, de.ugoe.cs.tasktree.treeifc.TaskTreeNode) |
---|
74 | */ |
---|
75 | @Override |
---|
76 | public void addChild(ITextInputEventTask parent, ITaskTreeNode child) { |
---|
77 | if (!(parent instanceof TextInputEventTask)) { |
---|
78 | throw new IllegalArgumentException |
---|
79 | ("illegal type of task tree node provided: " + parent.getClass()); |
---|
80 | } |
---|
81 | |
---|
82 | addChildInternal(parent, -1, child); |
---|
83 | } |
---|
84 | |
---|
85 | /* |
---|
86 | * (non-Javadoc) |
---|
87 | * |
---|
88 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setChild(Iteration, TaskTreeNode) |
---|
89 | */ |
---|
90 | @Override |
---|
91 | public void setChild(IIteration iteration, ITaskTreeNode newChild) { |
---|
92 | if (!(iteration instanceof Iteration)) { |
---|
93 | throw new IllegalArgumentException |
---|
94 | ("illegal type of iteration provided: " + iteration.getClass()); |
---|
95 | } |
---|
96 | |
---|
97 | if (!(newChild instanceof TaskTreeNode)) { |
---|
98 | throw new IllegalArgumentException |
---|
99 | ("illegal type of task tree node provided: " + newChild.getClass()); |
---|
100 | } |
---|
101 | |
---|
102 | ((Iteration) iteration).setChild(newChild); |
---|
103 | } |
---|
104 | |
---|
105 | /* |
---|
106 | * (non-Javadoc) |
---|
107 | * |
---|
108 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Sequence, int) |
---|
109 | */ |
---|
110 | @Override |
---|
111 | public void removeChild(ISequence parent, int index) { |
---|
112 | if (!(parent instanceof TaskTreeNode)) { |
---|
113 | throw new IllegalArgumentException |
---|
114 | ("illegal type of task tree node provided: " + parent.getClass()); |
---|
115 | } |
---|
116 | |
---|
117 | ((TaskTreeNode) parent).removeChild(index); |
---|
118 | } |
---|
119 | |
---|
120 | /* |
---|
121 | * (non-Javadoc) |
---|
122 | * |
---|
123 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#removeChild(Selection, TaskTreeNode) |
---|
124 | */ |
---|
125 | @Override |
---|
126 | public void removeChild(ISelection parent, ITaskTreeNode child) { |
---|
127 | if (!(parent instanceof TaskTreeNode)) { |
---|
128 | throw new IllegalArgumentException |
---|
129 | ("illegal type of task tree node provided: " + parent.getClass()); |
---|
130 | } |
---|
131 | |
---|
132 | for (int i = 0; i < parent.getChildren().size(); i++) { |
---|
133 | if ((parent.getChildren().get(i) == child) || |
---|
134 | ((parent.getChildren().get(i) != null) && |
---|
135 | (parent.getChildren().get(i).equals(child)))) |
---|
136 | { |
---|
137 | ((TaskTreeNode) parent).removeChild(i); |
---|
138 | break; |
---|
139 | } |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | /* |
---|
144 | * (non-Javadoc) |
---|
145 | * |
---|
146 | * @see de.ugoe.cs.tasktree.treeifc.TaskTreeBuilder#setDescription(TaskTreeNode, String) |
---|
147 | */ |
---|
148 | @Override |
---|
149 | public void setDescription(ITaskTreeNode parent, String description) { |
---|
150 | if (!(parent instanceof TaskTreeNode)) { |
---|
151 | throw new IllegalArgumentException |
---|
152 | ("illegal type of task tree node provided: " + parent.getClass()); |
---|
153 | } |
---|
154 | |
---|
155 | ((TaskTreeNode) parent).setDescription(description); |
---|
156 | } |
---|
157 | |
---|
158 | /** |
---|
159 | * |
---|
160 | */ |
---|
161 | private void addChildInternal(ITaskTreeNode parent, int index, ITaskTreeNode child) { |
---|
162 | if (!(child instanceof TaskTreeNode)) { |
---|
163 | throw new IllegalArgumentException |
---|
164 | ("illegal type of task tree node provided: " + child.getClass()); |
---|
165 | } |
---|
166 | |
---|
167 | if (index > -1) { |
---|
168 | ((TaskTreeNode) parent).addChild(index, child); |
---|
169 | } |
---|
170 | else { |
---|
171 | ((TaskTreeNode) parent).addChild(child); |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | } |
---|