Ignore:
Timestamp:
07/25/13 14:47:05 (11 years ago)
Author:
pharms
Message:
  • improved displaying of task trees
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/ShowTaskTreeDialog.java

    r1185 r1262  
    1616 
    1717import java.util.Collection; 
     18import java.util.Collections; 
     19import java.util.Comparator; 
    1820import java.util.HashSet; 
     21import java.util.LinkedList; 
    1922import java.util.List; 
    2023import java.util.Set; 
     
    197200         
    198201        TreeItem root = new TreeItem(modelTree, SWT.NULL); 
    199         root.setText(tasks.size() + " tasks in model"); 
     202        root.setText(tasks.size() + " tasks in model (showing only root tasks)"); 
    200203        root.setData(taskModel); 
    201204 
    202         tasks = determineRootTasks(tasks); 
     205        tasks = createSortedTaskList(tasks); 
    203206         
    204207        for (ITask task : tasks) { 
     
    226229     * 
    227230     */ 
    228     private Collection<ITask> determineRootTasks(Collection<ITask> tasks) { 
    229         Set<ITask> result = new HashSet<ITask>(tasks); 
     231    private List<ITask> createSortedTaskList(Collection<ITask> tasks) { 
     232        Set<ITask> resultSet = new HashSet<ITask>(tasks); 
    230233         
    231234        for (ITask task : tasks) { 
    232             removeChildren(task, result); 
    233         } 
     235            removeChildren(task, resultSet); 
     236        } 
     237         
     238        List<ITask> result = new LinkedList<ITask>(resultSet); 
     239         
     240        Collections.sort(result, new Comparator<ITask>() { 
     241            @Override 
     242            public int compare(ITask task1, ITask task2) { 
     243                return depth(task1) - depth(task2); 
     244            } 
     245 
     246            private int depth(ITask task) { 
     247                int maxChildDepth = 0; 
     248                if (task instanceof IStructuringTemporalRelationship) { 
     249                    for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) { 
     250                        maxChildDepth = Math.max(maxChildDepth, depth(child)); 
     251                    } 
     252                } 
     253                else if (task instanceof IMarkingTemporalRelationship) { 
     254                    maxChildDepth = Math.max 
     255                        (maxChildDepth, depth(((IMarkingTemporalRelationship) task).getMarkedTask())); 
     256                } 
     257                return maxChildDepth + 1; 
     258            } 
     259        }); 
    234260         
    235261        return result; 
     
    243269            for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) { 
    244270                result.remove(child); 
     271                //removeChildren(child, result); 
    245272            } 
    246273        } 
    247274        else if (task instanceof IMarkingTemporalRelationship) { 
    248275            result.remove(((IMarkingTemporalRelationship) task).getMarkedTask()); 
     276            //removeChildren(((IMarkingTemporalRelationship) task).getMarkedTask(), result); 
    249277        } 
    250278    } 
Note: See TracChangeset for help on using the changeset viewer.