Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.

1 /*******************************************************************************2 * Copyright (c) 2006 IBM Corporation and others.3 * All rights reserved. This program and the accompanying materials4 * are made available under the terms of the Eclipse Public License v1.05 * which accompanies this distribution, and is available at6 * http://www.eclipse.org/legal/epl-v10.html7 *8 * Contributors:9 * IBM Corporation - initial API and implementation10 *******************************************************************************/11 12 package org.eclipse.ui.internal.cheatsheets.composite.model;13 14 importjava.util.HashSet;15 importjava.util.Iterator;16 importjava.util.Set;17 18 importorg.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask;19 20 publicclass BlockedTaskFinder {21 22 privateSet stateChangedTasks;23 privateSet impactedTasks;24 /**25 * Find which tasks have either become blocked or unblocked so that they26 * can be added to the list of change events.27 * @param stateChangedTasks The set of tasks which has changed28 * @return The set of tasks which have become blocked or unblocked by the29 * 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 other32 * 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 set37 * <li> Add the successor and its children to the list if not started38 */39 40 publicSet findBlockedTaskChanges(Set stateChangedTasks) {41 this.stateChangedTasks = stateChangedTasks;42 impactedTasks = newHashSet();43 visitChangedTasks();44 findSuccesors();45 return impactedTasks;46 }47 48 privatevoid visitChangedTasks() {49 for (Iterator iter = stateChangedTasks.iterator(); iter.hasNext(); ) {50 finalICompositeCheatSheetTask 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 started59 * add them to the list of impacted tasks.60 */61 privatevoid 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 before66 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 privatevoid findSuccesors() {76 for (Iterator iter = stateChangedTasks.iterator(); iter.hasNext(); ) {77 finalAbstractTask 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