Ignore:
Timestamp:
04/04/13 16:06:07 (11 years ago)
Author:
pharms
Message:
  • complete refactoring of task tree model with a separation of task models and task instances
  • appropriate adaptation of task tree generation process
  • appropriate adaptation of commands and task tree visualization
File:
1 moved

Legend:

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

    r1126 r1146  
    1717import java.util.List; 
    1818 
     19import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
    1920import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
    2021import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 
    2122import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    2223import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    23 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder; 
    24 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 
     24import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     25import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 
     26import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
     27import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 
     28import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 
    2529 
    2630/** 
     
    3034 * @author 2012, last modified by $Author: patrick$ 
    3135 */ 
    32 public class TaskTreeBuilder implements ITaskTreeBuilder { 
     36public class TaskBuilder implements ITaskBuilder { 
     37 
     38    /* (non-Javadoc) 
     39     * @see ITaskBuilder#addChild(ITaskInstance, ITaskInstance) 
     40     */ 
     41    @Override 
     42    public void addChild(ITaskInstance parent, ITaskInstance child) throws IllegalArgumentException 
     43    { 
     44        if (!(parent instanceof TaskInstance)) { 
     45            throw new IllegalArgumentException 
     46                ("illegal type of task instance provided: " + parent.getClass()); 
     47        } 
     48 
     49        if (!(child instanceof TaskInstance)) { 
     50            throw new IllegalArgumentException 
     51                ("illegal type of task instance provided: " + parent.getClass()); 
     52        } 
     53         
     54        // check, that the correct number of children for the distinct types are added 
     55        ITask task = parent.getTask(); 
     56         
     57        if (task instanceof IEventTask) { 
     58            throw new IllegalArgumentException 
     59                ("can not add children to a task instance of an event task"); 
     60        } 
     61        else if (task instanceof ISelection) { 
     62            if (parent.getChildren().size() > 0) { 
     63                throw new IllegalArgumentException 
     64                    ("the instance of a selection must have at most one child"); 
     65            } 
     66        } 
     67        else if (task instanceof IOptional) { 
     68            if (parent.getChildren().size() > 1) { 
     69                throw new IllegalArgumentException 
     70                    ("the instance of an optional must have at most one child"); 
     71            } 
     72        } 
     73/*        else if (task instanceof IIteration) { 
     74            for (ITaskInstance childInstance : parent.getChildren()) { 
     75                if (!childInstance.getTask().equals(child.getTask())) { 
     76                    throw new IllegalArgumentException 
     77                        ("all children of an instance of an iteration must have exactly the " + 
     78                         "same type"); 
     79                } 
     80            } 
     81        } 
     82         
     83        boolean foundChildTask = false; 
     84        if (parent.getTask() instanceof IStructuringTemporalRelationship) { 
     85            IStructuringTemporalRelationship parentTask = 
     86                (IStructuringTemporalRelationship) parent.getTask(); 
     87         
     88            for (ITask parentTaskChild : parentTask.getChildren()) { 
     89                if (parentTaskChild.equals(child.getTask())) { 
     90                    foundChildTask = true; 
     91                    break; 
     92                } 
     93            } 
     94        } 
     95        else if (parent.getTask() instanceof IMarkingTemporalRelationship) { 
     96            IMarkingTemporalRelationship parentTask = 
     97                (IMarkingTemporalRelationship) parent.getTask(); 
     98             
     99            foundChildTask = parentTask.getMarkedTask() != null ? 
     100                parentTask.getMarkedTask().equals(child.getTask()) : false; 
     101        } 
     102         
     103        if (!foundChildTask) { 
     104            throw new IllegalArgumentException 
     105                ("the task of the child instance to be added does not belong to the children " + 
     106                 "of the task of the parent instance"); 
     107        }*/ 
     108 
     109        // finally, after all checks are positive, add the child 
     110        ((TaskInstance) parent).addChild(child); 
     111    } 
     112 
     113    /* (non-Javadoc) 
     114     * @see ITaskBuilder#addExecutedTask(IUserSession, ITaskInstance) 
     115     */ 
     116    @Override 
     117    public void addExecutedTask(IUserSession session, ITaskInstance taskInstance) { 
     118        if (!(session instanceof UserSession)) { 
     119            throw new IllegalArgumentException 
     120                ("illegal type of session provided: " + session.getClass()); 
     121        } 
     122 
     123        if (!(taskInstance instanceof TaskInstance)) { 
     124            throw new IllegalArgumentException 
     125                ("illegal type of task instance provided: " + taskInstance.getClass()); 
     126        } 
     127         
     128        ((UserSession) session).addExecutedTask(taskInstance); 
     129    } 
     130 
     131    /* (non-Javadoc) 
     132     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#addTaskInstance(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 
     133     */ 
     134    @Override 
     135    public void addTaskInstance(ITaskInstanceList taskInstanceList, ITaskInstance taskInstance) { 
     136        if (taskInstanceList instanceof TaskInstance) { 
     137            ((TaskInstance) taskInstanceList).addChild(taskInstance); 
     138        } 
     139        else if (taskInstanceList instanceof UserSession) { 
     140            ((UserSession) taskInstanceList).addExecutedTask(taskInstance); 
     141        } 
     142        else { 
     143            throw new IllegalArgumentException 
     144                ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 
     145        } 
     146    } 
     147 
     148    /* (non-Javadoc) 
     149     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#addTaskInstance(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList, int, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 
     150     */ 
     151    @Override 
     152    public void addTaskInstance(ITaskInstanceList taskInstanceList, 
     153                                int               index, 
     154                                ITaskInstance     taskInstance) 
     155    { 
     156        if (taskInstanceList instanceof TaskInstance) { 
     157            ((TaskInstance) taskInstanceList).addChild(index, taskInstance); 
     158        } 
     159        else if (taskInstanceList instanceof UserSession) { 
     160            ((UserSession) taskInstanceList).addExecutedTask(index, taskInstance); 
     161        } 
     162        else { 
     163            throw new IllegalArgumentException 
     164                ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 
     165        } 
     166    } 
     167 
     168    /* (non-Javadoc) 
     169     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#setTaskInstance(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList, int, de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance) 
     170     */ 
     171    @Override 
     172    public void setTaskInstance(ITaskInstanceList taskInstanceList, 
     173                                int               index, 
     174                                ITaskInstance     taskInstance) 
     175    { 
     176        if (taskInstanceList instanceof TaskInstance) { 
     177            ((TaskInstance) taskInstanceList).removeChild(index); 
     178            ((TaskInstance) taskInstanceList).addChild(index, taskInstance); 
     179        } 
     180        else if (taskInstanceList instanceof UserSession) { 
     181            ((UserSession) taskInstanceList).removeExecutedTask(index); 
     182            ((UserSession) taskInstanceList).addExecutedTask(index, taskInstance); 
     183        } 
     184        else { 
     185            throw new IllegalArgumentException 
     186                ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 
     187        } 
     188    } 
     189 
     190    /* (non-Javadoc) 
     191     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#setTask(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance, de.ugoe.cs.autoquest.tasktrees.treeifc.ITask) 
     192     */ 
     193    @Override 
     194    public void setTask(ITaskInstance taskInstance, ITask task) { 
     195        if (!(taskInstance instanceof TaskInstance)) { 
     196            throw new IllegalArgumentException 
     197                ("illegal type of task instance provided: " + taskInstance.getClass()); 
     198        } 
     199         
     200        ((TaskInstance) taskInstance).setTask(task); 
     201    } 
    33202 
    34203    /* 
     
    38207     */ 
    39208    @Override 
    40     public void addChild(ISequence parent, ITaskTreeNode child) { 
     209    public void addChild(ISequence parent, ITask child) { 
    41210        if (!(parent instanceof Sequence)) { 
    42211            throw new IllegalArgumentException 
    43                 ("illegal type of task tree node provided: " + parent.getClass()); 
    44         } 
    45  
    46         addChildInternal(parent, -1, child); 
     212                ("illegal type of sequence provided: " + parent.getClass()); 
     213        } 
     214 
     215        addChildInternal((Sequence) parent, -1, child); 
    47216    } 
    48217 
     
    53222     */ 
    54223    @Override 
    55     public void addChild(ISequence parent, int index, ITaskTreeNode child) { 
     224    public void addChild(ISequence parent, int index, ITask child) { 
    56225        if (!(parent instanceof Sequence)) { 
    57226            throw new IllegalArgumentException 
    58                 ("illegal type of task tree node provided: " + parent.getClass()); 
    59         } 
    60  
    61         addChildInternal(parent, index, child); 
     227                ("illegal type of sequence provided: " + parent.getClass()); 
     228        } 
     229 
     230        addChildInternal((Sequence) parent, index, child); 
    62231    } 
    63232 
     
    66235     */ 
    67236    @Override 
    68     public void setChild(ISequence parent, int index, ITaskTreeNode child) { 
     237    public void setChild(ISequence parent, int index, ITask child) { 
    69238        if (!(parent instanceof Sequence)) { 
    70239            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); 
     240                ("illegal type of sequence provided: " + parent.getClass()); 
     241        } 
     242 
     243        ((Sequence) parent).removeChild(index); 
     244        addChildInternal((Sequence) parent, index, child); 
    76245    } 
    77246 
     
    82251     */ 
    83252    @Override 
    84     public void addChild(ISelection parent, ITaskTreeNode child) { 
     253    public void addChild(ISelection parent, ITask child) { 
    85254        if (!(parent instanceof Selection)) { 
    86255            throw new IllegalArgumentException 
    87                 ("illegal type of task tree node provided: " + parent.getClass()); 
    88         } 
    89  
    90         addChildInternal(parent, -1, child); 
     256                ("illegal type of selection provided: " + parent.getClass()); 
     257        } 
     258 
     259        addChildInternal((Selection) parent, -1, child); 
    91260    } 
    92261 
     
    97266     */ 
    98267    @Override 
    99     public void setChild(IIteration iteration, ITaskTreeNode newChild) { 
     268    public void setMarkedTask(IIteration iteration, ITask newChild) { 
    100269        if (!(iteration instanceof Iteration)) { 
    101270            throw new IllegalArgumentException 
     
    103272        } 
    104273 
    105         if (!(newChild instanceof TaskTreeNode)) { 
    106             throw new IllegalArgumentException 
    107                 ("illegal type of task tree node provided: " + newChild.getClass()); 
    108         } 
    109  
    110         ((Iteration) iteration).setChild(newChild); 
     274        if (!(newChild instanceof Task)) { 
     275            throw new IllegalArgumentException 
     276                ("illegal type of task provided: " + newChild.getClass()); 
     277        } 
     278 
     279        ((Iteration) iteration).setMarkedTask(newChild); 
    111280    } 
    112281 
     
    115284     */ 
    116285    @Override 
    117     public void setChild(IOptional optional, ITaskTreeNode newChild) { 
     286    public void setMarkedTask(IOptional optional, ITask newChild) { 
    118287        if (!(optional instanceof Optional)) { 
    119288            throw new IllegalArgumentException 
     
    121290        } 
    122291 
    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); 
     292        if (!(newChild instanceof Task)) { 
     293            throw new IllegalArgumentException 
     294                ("illegal type of task provided: " + newChild.getClass()); 
     295        } 
     296 
     297        ((Optional) optional).setMarkedTask(newChild); 
    129298    } 
    130299 
     
    136305    @Override 
    137306    public void removeChild(ISequence parent, int index) { 
    138         if (!(parent instanceof TaskTreeNode)) { 
    139             throw new IllegalArgumentException 
    140                 ("illegal type of task tree node provided: " + parent.getClass()); 
    141         } 
    142  
    143         ((TaskTreeNode) parent).removeChild(index); 
     307        if (!(parent instanceof Sequence)) { 
     308            throw new IllegalArgumentException 
     309                ("illegal type of sequence provided: " + parent.getClass()); 
     310        } 
     311 
     312        ((Sequence) parent).removeChild(index); 
    144313    } 
    145314 
     
    150319     */ 
    151320    @Override 
    152     public void removeChild(ISelection parent, ITaskTreeNode child) { 
    153         if (!(parent instanceof TaskTreeNode)) { 
    154             throw new IllegalArgumentException 
    155                 ("illegal type of task tree node provided: " + parent.getClass()); 
    156         } 
    157  
    158         List<ITaskTreeNode> children = parent.getChildren(); 
     321    public void removeChild(ISelection parent, ITask child) { 
     322        if (!(parent instanceof Selection)) { 
     323            throw new IllegalArgumentException 
     324                ("illegal type of selection provided: " + parent.getClass()); 
     325        } 
     326 
     327        List<ITask> children = parent.getChildren(); 
    159328         
    160329        for (int i = 0; i < children.size(); i++) { 
     
    162331                ((children.get(i) != null) && (children.get(i).equals(child)))) 
    163332            { 
    164                 ((TaskTreeNode) parent).removeChild(i); 
     333                ((Selection) parent).removeChild(i); 
    165334                break; 
    166335            } 
     
    169338 
    170339    /* (non-Javadoc) 
     340     * @see de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder#removeTaskInstance(de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList, int) 
     341     */ 
     342    @Override 
     343    public void removeTaskInstance(ITaskInstanceList taskInstanceList, int index) { 
     344        if (taskInstanceList instanceof TaskInstance) { 
     345            ((TaskInstance) taskInstanceList).removeChild(index); 
     346        } 
     347        else if (taskInstanceList instanceof UserSession) { 
     348            ((UserSession) taskInstanceList).removeExecutedTask(index); 
     349        } 
     350        else { 
     351            throw new IllegalArgumentException 
     352                ("illegal type of task instance list provided: " + taskInstanceList.getClass()); 
     353        } 
     354    } 
     355 
     356    /* (non-Javadoc) 
    171357     * @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) 
    172358     */ 
    173359    @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(); 
     360    public void replaceChild(ISelection parent, ITask oldChild, ITask newChild) { 
     361        if (!(parent instanceof Selection)) { 
     362            throw new IllegalArgumentException 
     363                ("illegal type of selection provided: " + parent.getClass()); 
     364        } 
     365 
     366        List<ITask> children = parent.getChildren(); 
    181367         
    182368        for (int i = 0; i < children.size(); i++) { 
     
    184370                ((children.get(i) != null) && (children.get(i).equals(oldChild)))) 
    185371            { 
    186                 ((TaskTreeNode) parent).removeChild(i); 
    187                 ((TaskTreeNode) parent).addChild(i, newChild); 
     372                ((Selection) parent).removeChild(i); 
     373                ((Selection) parent).addChild(i, newChild); 
    188374                break; 
    189375            } 
     
    197383     */ 
    198384    @Override 
    199     public void setDescription(ITaskTreeNode parent, String description) { 
    200         if (!(parent instanceof TaskTreeNode)) { 
    201             throw new IllegalArgumentException 
    202                 ("illegal type of task tree node provided: " + parent.getClass()); 
    203         } 
    204  
    205         ((TaskTreeNode) parent).setDescription(description); 
     385    public void setDescription(ITask parent, String description) { 
     386        if (!(parent instanceof Task)) { 
     387            throw new IllegalArgumentException 
     388                ("illegal type of task provided: " + parent.getClass()); 
     389        } 
     390 
     391        ((Task) parent).setDescription(description); 
    206392    } 
    207393 
     
    209395     *  
    210396     */ 
    211     private void addChildInternal(ITaskTreeNode parent, int index, ITaskTreeNode child) { 
    212         if (!(child instanceof TaskTreeNode)) { 
    213             throw new IllegalArgumentException 
    214                 ("illegal type of task tree node provided: " + child.getClass()); 
     397    private void addChildInternal(StructuringTemporalRelationship parent, int index, ITask child) { 
     398        if (!(child instanceof Task)) { 
     399            throw new IllegalArgumentException 
     400                ("illegal type of task provided: " + child.getClass()); 
    215401        } 
    216402 
    217403        if (index > -1) { 
    218             ((TaskTreeNode) parent).addChild(index, child); 
     404            parent.addChild(index, child); 
    219405        } 
    220406        else { 
    221             ((TaskTreeNode) parent).addChild(child); 
     407            parent.addChild(child); 
    222408        } 
    223409    } 
Note: See TracChangeset for help on using the changeset viewer.