[439] | 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 |
---|
[557] | 6 | |
---|
[439] | 7 | package de.ugoe.cs.quest.tasktrees.treeimpl; |
---|
| 8 | |
---|
[557] | 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; |
---|
[439] | 15 | |
---|
| 16 | /** |
---|
| 17 | * TODO comment |
---|
| 18 | * |
---|
| 19 | * @version $Revision: $ $Date: 21.02.2012$ |
---|
| 20 | * @author 2012, last modified by $Author: patrick$ |
---|
| 21 | */ |
---|
[557] | 22 | public class TaskTreeBuilder implements ITaskTreeBuilder { |
---|
[439] | 23 | |
---|
[557] | 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 | } |
---|
[439] | 35 | |
---|
[557] | 36 | addChildInternal(parent, -1, child); |
---|
[439] | 37 | } |
---|
| 38 | |
---|
[557] | 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 | } |
---|
[439] | 50 | |
---|
[557] | 51 | addChildInternal(parent, index, child); |
---|
[439] | 52 | } |
---|
| 53 | |
---|
[557] | 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 | } |
---|
[439] | 65 | |
---|
[557] | 66 | addChildInternal(parent, -1, child); |
---|
[439] | 67 | } |
---|
| 68 | |
---|
[557] | 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 | } |
---|
[439] | 81 | |
---|
[557] | 82 | addChildInternal(parent, -1, child); |
---|
[439] | 83 | } |
---|
| 84 | |
---|
[557] | 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 | } |
---|
[439] | 96 | |
---|
[557] | 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); |
---|
[439] | 103 | } |
---|
| 104 | |
---|
[557] | 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 | } |
---|
[439] | 116 | |
---|
[557] | 117 | ((TaskTreeNode) parent).removeChild(index); |
---|
[439] | 118 | } |
---|
| 119 | |
---|
[557] | 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 | } |
---|
[439] | 141 | } |
---|
| 142 | |
---|
[557] | 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); |
---|
[439] | 156 | } |
---|
| 157 | |
---|
[557] | 158 | /** |
---|
[439] | 159 | * |
---|
| 160 | */ |
---|
[557] | 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 | } |
---|
[439] | 166 | |
---|
[557] | 167 | if (index > -1) { |
---|
| 168 | ((TaskTreeNode) parent).addChild(index, child); |
---|
| 169 | } |
---|
| 170 | else { |
---|
| 171 | ((TaskTreeNode) parent).addChild(child); |
---|
| 172 | } |
---|
[439] | 173 | } |
---|
| 174 | |
---|
| 175 | } |
---|