KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > composite > model > BlockedTaskFinder


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.cheatsheets.composite.model;
13
14 import java.util.HashSet JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.Set JavaDoc;
17
18 import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask;
19
20 public class BlockedTaskFinder {
21     
22     private Set JavaDoc stateChangedTasks;
23     private Set JavaDoc impactedTasks;
24     /**
25      * Find which tasks have either become blocked or unblocked so that they
26      * can be added to the list of change events.
27      * @param stateChangedTasks The set of tasks which has changed
28      * @return The set of tasks which have become blocked or unblocked by the
29      * change of state and were not in the original set. The algorithm will sometimes add tasks to
30      * the result set which were not actually impacted but this is not a major problem
31      * since it only means that extra events get sent to the explorer. For updates other
32      * than resets the number of extra events is very low.
33      *
34      * This takes several steps.
35      * <li> If a group is completed, skipped or reset add any non-started children.
36      * <li> Determine all successors of tasks whose state has changed that are not in the change set
37      * <li> Add the successor and its children to the list if not started
38      */

39     
40     public Set JavaDoc findBlockedTaskChanges(Set JavaDoc stateChangedTasks) {
41         this.stateChangedTasks = stateChangedTasks;
42         impactedTasks = new HashSet JavaDoc();
43         visitChangedTasks();
44         findSuccesors();
45         return impactedTasks;
46     }
47
48     private void visitChangedTasks() {
49         for (Iterator JavaDoc iter = stateChangedTasks.iterator(); iter.hasNext(); ) {
50             final ICompositeCheatSheetTask nextTask = (ICompositeCheatSheetTask)iter.next();
51             if (nextTask.getState() != ICompositeCheatSheetTask.IN_PROGRESS) {
52                 findUnstartedChildren(nextTask);
53             }
54         }
55     }
56
57     /*
58      * Look for children which we have not seen elsewhere and if they are not started
59      * add them to the list of impacted tasks.
60      */

61     private void findUnstartedChildren(ICompositeCheatSheetTask task) {
62         ICompositeCheatSheetTask[] children = task.getSubtasks();
63         for (int i = 0; i < children.length; i++) {
64             ICompositeCheatSheetTask nextChild = children[i];
65             // Ignore if this task has been seen before
66
if ((!stateChangedTasks.contains(nextChild)) && !impactedTasks.contains(nextChild)) {
67                 if (nextChild.getState() == ICompositeCheatSheetTask.NOT_STARTED) {
68                    impactedTasks.add(nextChild);
69                 }
70                 findUnstartedChildren(nextChild);
71             }
72         }
73     }
74
75     private void findSuccesors() {
76         for (Iterator JavaDoc iter = stateChangedTasks.iterator(); iter.hasNext(); ) {
77             final AbstractTask nextTask = (AbstractTask)iter.next();
78             ICompositeCheatSheetTask[] successors = nextTask.getSuccessorTasks();
79             for (int i = 0; i < successors.length; i++) {
80                 ICompositeCheatSheetTask nextSuccessor = successors[i];
81                 if (nextSuccessor.getState() == ICompositeCheatSheetTask.NOT_STARTED) {
82                     impactedTasks.add(nextSuccessor);
83                 }
84                 findUnstartedChildren(nextSuccessor);
85             }
86         }
87     }
88
89 }
90
Popular Tags