KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask;
15
16 public class TaskChoiceCompletionStrategy implements TaskGroup.CompletionStrategy {
17
18     /**
19      * Determine the state based on the state of the children, which is
20      * NOT_STARTED if all children are not started
21      * COMPLETED if one children is completed or skipped
22      * IN_PROGRESS otherwise
23      * @return
24      */

25     public int computeState(TaskGroup taskGroup) {
26         boolean noChildrenStarted = true;
27         boolean atLeastOneChildCompleted = false;
28         ICompositeCheatSheetTask[] children = taskGroup.getSubtasks();
29         for (int i = 0; i < children.length; i++) {
30             switch(children[i].getState()) {
31                case ICompositeCheatSheetTask.NOT_STARTED:
32                    break;
33                case ICompositeCheatSheetTask.IN_PROGRESS:
34                    noChildrenStarted = false;
35                    break;
36                case ICompositeCheatSheetTask.SKIPPED:
37                case ICompositeCheatSheetTask.COMPLETED:
38                    noChildrenStarted = false;
39                    atLeastOneChildCompleted = true;
40                    break;
41             }
42         }
43         if (atLeastOneChildCompleted || children.length == 0) {
44             return ICompositeCheatSheetTask.COMPLETED;
45         }
46         if (taskGroup.getState() == ICompositeCheatSheetTask.SKIPPED) {
47             return ICompositeCheatSheetTask.SKIPPED;
48         }
49         if (noChildrenStarted) {
50             return ICompositeCheatSheetTask.NOT_STARTED;
51         }
52         return ICompositeCheatSheetTask.IN_PROGRESS;
53     }
54 }
55
Popular Tags