1 11 12 package org.eclipse.ui.internal.cheatsheets.composite.model; 13 14 import java.util.HashSet ; 15 import java.util.Iterator ; 16 import java.util.Set ; 17 18 import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask; 19 20 public class BlockedTaskFinder { 21 22 private Set stateChangedTasks; 23 private Set impactedTasks; 24 39 40 public Set findBlockedTaskChanges(Set stateChangedTasks) { 41 this.stateChangedTasks = stateChangedTasks; 42 impactedTasks = new HashSet (); 43 visitChangedTasks(); 44 findSuccesors(); 45 return impactedTasks; 46 } 47 48 private void visitChangedTasks() { 49 for (Iterator 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 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 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 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 |