KickJava   Java API By Example, From Geeks To Geeks.

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


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 TaskSetCompletionStrategy 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 all children are completed or skipped
22      * IN_PROGRESS otherwise
23      * @return
24      */

25     public int computeState(TaskGroup taskGroup) {
26         boolean noChildrenStarted = true;
27         boolean allChildrenCompleted = true;
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                    allChildrenCompleted = false;
33                    break;
34                case ICompositeCheatSheetTask.IN_PROGRESS:
35                    noChildrenStarted = false;
36                    allChildrenCompleted = false;
37                    break;
38                case ICompositeCheatSheetTask.COMPLETED:
39                case ICompositeCheatSheetTask.SKIPPED:
40                    noChildrenStarted = false;
41                    break;
42             }
43         }
44         if (allChildrenCompleted) {
45             return ICompositeCheatSheetTask.COMPLETED;
46         }
47         if (taskGroup.getState() == ICompositeCheatSheetTask.SKIPPED) {
48             return ICompositeCheatSheetTask.SKIPPED;
49         }
50         if (noChildrenStarted) {
51             return ICompositeCheatSheetTask.NOT_STARTED;
52         }
53         return ICompositeCheatSheetTask.IN_PROGRESS;
54     }
55 }
56
Popular Tags