Ignore:
Timestamp:
03/18/13 11:50:04 (11 years ago)
Author:
pharms
Message:
  • extended task tree model with support for optionalities
  • improved performance of task tree handling
  • improved visualization of task trees
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskTreeBuilder.java

    r1113 r1126  
    1515package de.ugoe.cs.autoquest.tasktrees.treeimpl; 
    1616 
     17import java.util.List; 
     18 
    1719import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
     20import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 
    1821import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    1922import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
     
    5962    } 
    6063 
     64    /* (non-Javadoc) 
     65     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder#setChild(de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence, int, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode) 
     66     */ 
     67    @Override 
     68    public void setChild(ISequence parent, int index, ITaskTreeNode child) { 
     69        if (!(parent instanceof Sequence)) { 
     70            throw new IllegalArgumentException 
     71                ("illegal type of task tree node provided: " + parent.getClass()); 
     72        } 
     73 
     74        ((TaskTreeNode) parent).removeChild(index); 
     75        addChildInternal(parent, index, child); 
     76    } 
     77 
    6178    /* 
    6279     * (non-Javadoc) 
     
    94111    } 
    95112 
     113    /* (non-Javadoc) 
     114     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder#setChild(de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode) 
     115     */ 
     116    @Override 
     117    public void setChild(IOptional optional, ITaskTreeNode newChild) { 
     118        if (!(optional instanceof Optional)) { 
     119            throw new IllegalArgumentException 
     120                ("illegal type of optional provided: " + optional.getClass()); 
     121        } 
     122 
     123        if (!(newChild instanceof TaskTreeNode)) { 
     124            throw new IllegalArgumentException 
     125                ("illegal type of task tree node provided: " + newChild.getClass()); 
     126        } 
     127 
     128        ((Optional) optional).setChild(newChild); 
     129    } 
     130 
    96131    /* 
    97132     * (non-Javadoc) 
     
    121156        } 
    122157 
    123         for (int i = 0; i < parent.getChildren().size(); i++) { 
    124             if ((parent.getChildren().get(i) == child) || 
    125                 ((parent.getChildren().get(i) != null) && 
    126                  (parent.getChildren().get(i).equals(child)))) 
     158        List<ITaskTreeNode> children = parent.getChildren(); 
     159         
     160        for (int i = 0; i < children.size(); i++) { 
     161            if ((children.get(i) == child) || 
     162                ((children.get(i) != null) && (children.get(i).equals(child)))) 
    127163            { 
    128164                ((TaskTreeNode) parent).removeChild(i); 
     
    132168    } 
    133169 
     170    /* (non-Javadoc) 
     171     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder#replaceChild(de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode) 
     172     */ 
     173    @Override 
     174    public void replaceChild(ISelection parent, ITaskTreeNode oldChild, ITaskTreeNode newChild) { 
     175        if (!(parent instanceof TaskTreeNode)) { 
     176            throw new IllegalArgumentException 
     177                ("illegal type of task tree node provided: " + parent.getClass()); 
     178        } 
     179 
     180        List<ITaskTreeNode> children = parent.getChildren(); 
     181         
     182        for (int i = 0; i < children.size(); i++) { 
     183            if ((children.get(i) == oldChild) || 
     184                ((children.get(i) != null) && (children.get(i).equals(oldChild)))) 
     185            { 
     186                ((TaskTreeNode) parent).removeChild(i); 
     187                ((TaskTreeNode) parent).addChild(i, newChild); 
     188                break; 
     189            } 
     190        } 
     191    } 
     192 
    134193    /* 
    135194     * (non-Javadoc) 
Note: See TracChangeset for help on using the changeset viewer.