01: /*******************************************************************************
02: * Copyright (c) 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.cheatsheets.composite.model;
11:
12: import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask;
13:
14: public class TaskChoiceCompletionStrategy implements
15: TaskGroup.CompletionStrategy {
16:
17: /**
18: * Determine the state based on the state of the children, which is
19: * NOT_STARTED if all children are not started
20: * COMPLETED if one children is completed or skipped
21: * IN_PROGRESS otherwise
22: * @return
23: */
24: public int computeState(TaskGroup taskGroup) {
25: boolean noChildrenStarted = true;
26: boolean atLeastOneChildCompleted = false;
27: ICompositeCheatSheetTask[] children = taskGroup.getSubtasks();
28: for (int i = 0; i < children.length; i++) {
29: switch (children[i].getState()) {
30: case ICompositeCheatSheetTask.NOT_STARTED:
31: break;
32: case ICompositeCheatSheetTask.IN_PROGRESS:
33: noChildrenStarted = false;
34: break;
35: case ICompositeCheatSheetTask.SKIPPED:
36: case ICompositeCheatSheetTask.COMPLETED:
37: noChildrenStarted = false;
38: atLeastOneChildCompleted = true;
39: break;
40: }
41: }
42: if (atLeastOneChildCompleted || children.length == 0) {
43: return ICompositeCheatSheetTask.COMPLETED;
44: }
45: if (taskGroup.getState() == ICompositeCheatSheetTask.SKIPPED) {
46: return ICompositeCheatSheetTask.SKIPPED;
47: }
48: if (noChildrenStarted) {
49: return ICompositeCheatSheetTask.NOT_STARTED;
50: }
51: return ICompositeCheatSheetTask.IN_PROGRESS;
52: }
53: }
|