Index: trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoder.java
===================================================================
--- trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoder.java	(revision 1294)
+++ trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoder.java	(revision 1325)
@@ -17,4 +17,6 @@
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 import java.util.regex.Matcher;
@@ -163,4 +165,86 @@
         String id = matcher.group(2);
         
+        // determine the children before creating this instance
+        List<ITaskInstance> children = new LinkedList<ITaskInstance>();
+        while (taskMatcher.find() && !"}".equals(taskMatcher.group(0))) {
+            children.add(parseTaskInstance(taskMatcher));
+        }
+        
+        // get the model
+        ITask task = getCreateTask(id, type, children);
+        
+        // create the respective instance
+        ITaskInstance instance;
+        
+        if (task instanceof ISequence) {
+            instance = taskFactory.createNewTaskInstance((ISequence) task);
+        }
+        else if (task instanceof ISelection) {
+            instance = taskFactory.createNewTaskInstance((ISelection) task);
+        }
+        else if (task instanceof IIteration) {
+            instance = taskFactory.createNewTaskInstance((IIteration) task);
+        }
+        else if (task instanceof IOptional) {
+            instance = taskFactory.createNewTaskInstance((IOptional) task);
+        }
+        else {
+            Event event = !task.getInstances().isEmpty() ?
+                ((IEventTaskInstance) task.getInstances().iterator().next()).getEvent() :
+                createUserInteractionEvent(type, id, matcher.group(4));
+                
+            instance = taskFactory.createNewTaskInstance((IEventTask) task, event);
+        }  
+        
+        // add the children to the instance
+        for (ITaskInstance childInstance : children) {
+            if (instance instanceof ISequenceInstance) {
+                taskBuilder.addChild((ISequenceInstance) instance, childInstance);
+            }
+            else if (instance instanceof ISelectionInstance) {
+                if (((ISelectionInstance) instance).getChild() == null) {
+                    taskBuilder.setChild((ISelectionInstance) instance, childInstance);
+                }
+                else {
+                    throw new IllegalArgumentException("can not add several children to one " +
+                                                       "selection instance");
+                }
+            }
+            else if (instance instanceof IIterationInstance) {
+                taskBuilder.addChild((IIterationInstance) instance, childInstance);
+            }
+            else if (instance instanceof IOptionalInstance) {
+                if (((IOptionalInstance) instance).getChild() == null) {
+                    taskBuilder.setChild((IOptionalInstance) instance, childInstance);
+                }
+                else {
+                    throw new IllegalArgumentException("can not add several children to one " +
+                                                       "optional instance");
+                }
+            }
+        }
+
+        // validate the instance
+        try {
+            new TaskTreeValidator().validate(instance);
+        }
+        catch (java.lang.AssertionError e) {
+            throw new IllegalArgumentException(e.getMessage(), e);
+        }
+        
+        return instance;
+    }
+
+    /**
+     * <p>
+     * TODO: comment
+     * </p>
+     *
+     * @param id
+     * @param type
+     * @param children
+     * @return
+     */
+    private ITask getCreateTask(String id, String type, List<ITaskInstance> children) {
         ITask task = tasks.get(id);
         
@@ -179,76 +263,61 @@
             }
             else {
-            	task = createUserInteractionTaskInstance(matcher).getTask();
+                task = taskFactory.createNewEventTask(type + " --> " + id);
             }  
             tasks.put(id, task);
-        }
-        
-        ITaskInstance instance;
-        
-        if (task instanceof ISequence) {
-            instance = taskFactory.createNewTaskInstance((ISequence) task);
-        }
-        else if (task instanceof ISelection) {
-            instance = taskFactory.createNewTaskInstance((ISelection) task);
-        }
-        else if (task instanceof IIteration) {
-            instance = taskFactory.createNewTaskInstance((IIteration) task);
-        }
-        else if (task instanceof IOptional) {
-            instance = taskFactory.createNewTaskInstance((IOptional) task);
-        }
-        else {
-            instance = taskFactory.createNewTaskInstance
-                 ((IEventTask) task,
-                  ((IEventTaskInstance) task.getInstances().iterator().next()).getEvent());
-        }  
-        
-        while (taskMatcher.find() && !"}".equals(taskMatcher.group(0))) {
-            ITaskInstance childInstance = parseTaskInstance(taskMatcher);
-            
-            if (task instanceof ISequence) {
-                taskBuilder.addChild((ISequence) task, childInstance.getTask());
-            }
-            else if (task instanceof ISelection) {
-                taskBuilder.addChild((ISelection) task, childInstance.getTask());
-            }
-            else if (task instanceof IIteration) {
-                if (((IIteration) task).getMarkedTask() == null) {
-                    taskBuilder.setMarkedTask((IIteration) task, childInstance.getTask());
-                }
-                else if (!((IIteration) task).getMarkedTask().equals(childInstance.getTask())) {
-                    throw new IllegalArgumentException
-                        ("can not add more than one child to an iteration");
-                }
-            }
-            else if (task instanceof IOptional) {
-                if (((IOptional) task).getMarkedTask() == null) {
-                    taskBuilder.setMarkedTask((IOptional) task, childInstance.getTask());
-                }
-                else if (!((IOptional) task).getMarkedTask().equals(childInstance.getTask())) {
-                    throw new IllegalArgumentException
-                        ("can not add more than one child to an optional");
-                }
-            }
-            else {
-                throw new IllegalArgumentException("can not add children to something that is no " +
-                                                   "sequence, selection, iteration, or optional");
-            }
-            
-            if (instance instanceof ISequenceInstance) {
-                taskBuilder.addChild((ISequenceInstance) instance, childInstance);
-            }
-            else if (instance instanceof ISelectionInstance) {
-                taskBuilder.setChild((ISelectionInstance) instance, childInstance);
-            }
-            else if (instance instanceof IIterationInstance) {
-                taskBuilder.addChild((IIterationInstance) instance, childInstance);
-            }
-            else if (instance instanceof IOptionalInstance) {
-                taskBuilder.setChild((IOptionalInstance) instance, childInstance);
-            }
-        }
-
-        return instance;
+
+            for (ITaskInstance childInstance : children) {
+                if (task instanceof ISequence) {
+                    taskBuilder.addChild((ISequence) task, childInstance.getTask());
+                }
+                else if (task instanceof ISelection) {
+                    taskBuilder.addChild((ISelection) task, childInstance.getTask());
+                }
+                else if (task instanceof IIteration) {
+                    if (((IIteration) task).getMarkedTask() == null) {
+                        taskBuilder.setMarkedTask((IIteration) task, childInstance.getTask());
+                    }
+                    else if (!((IIteration) task).getMarkedTask().equals(childInstance.getTask())) {
+                        throw new IllegalArgumentException
+                            ("can not add more than one child to an iteration");
+                    }
+                }
+                else if (task instanceof IOptional) {
+                    if (((IOptional) task).getMarkedTask() == null) {
+                        taskBuilder.setMarkedTask((IOptional) task, childInstance.getTask());
+                    }
+                    else if (!((IOptional) task).getMarkedTask().equals(childInstance.getTask())) {
+                        throw new IllegalArgumentException
+                            ("can not add more than one child to an optional");
+                    }
+                }
+                else {
+                    throw new IllegalArgumentException("can not add children to something that " +
+                                                       "is no sequence, selection, iteration, or " +
+                                                       "optional");
+                }
+            }
+        }
+        else if ("Selection".equals(type)) {
+            // update the selection with further alternatives, if specified by the current
+            // child instance
+            if (children.size() == 1) {
+                ITask newChildTask = children.get(0).getTask();
+                
+                boolean found = false;
+                for (ITask childTask : ((ISelection) task).getChildren()) {
+                    if (childTask.equals(newChildTask)) {
+                        found = true;
+                        break;
+                    }
+                }
+                
+                if (!found) {
+                    taskBuilder.addChild((ISelection) task, newChildTask);
+                }
+            }
+        }
+
+        return task;
     }
 
@@ -260,16 +329,13 @@
      * @return
      */
-    private ITaskInstance createUserInteractionTaskInstance(Matcher matcher) {
-        String evenType = matcher.group(1);
-        String id = matcher.group(2);
-        IEventTarget eventTarget = targets.get(id);
+    private Event createUserInteractionEvent(String type, String targetId, String furtherInfo) {
+        IEventTarget eventTarget = targets.get(targetId);
         if (eventTarget == null) {
-            eventTarget = determineTarget(evenType, id, matcher.group(4));
-            targets.put(id, eventTarget);
-        }
-        IEventType eventType = determineType(evenType, matcher.group(4));
-        IEventTask task = taskFactory.createNewEventTask(eventType + " --> " + eventTarget);
-        
-        return taskFactory.createNewTaskInstance(task, new Event(eventType, eventTarget));
+            eventTarget = determineTarget(type, targetId, furtherInfo);
+            targets.put(targetId, eventTarget);
+        }
+        IEventType eventType = determineType(type, furtherInfo);
+        
+        return new Event(eventType, eventTarget);
     }
 
