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