KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
15 import org.eclipse.ui.internal.cheatsheets.composite.parser.ITaskParseStrategy;
16 import org.eclipse.ui.internal.cheatsheets.composite.parser.TaskGroupParseStrategy;
17 import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask;
18 import org.eclipse.ui.internal.provisional.cheatsheets.ITaskGroup;
19
20 public class TaskGroup extends AbstractTask implements ITaskGroup {
21     
22     public interface CompletionStrategy {
23         public int computeState(TaskGroup taskGroup);
24     }
25     
26     private ITaskParseStrategy parserStrategy;
27
28     private ArrayList JavaDoc subtasks;
29     
30     private CompletionStrategy completionStrategy;
31
32     public TaskGroup(CompositeCheatSheetModel model, String JavaDoc id, String JavaDoc name, String JavaDoc kind) {
33         super(model, id, name, kind);
34         if (kind == null) {
35             this.kind = ITaskGroup.SET;
36         }
37         parserStrategy = new TaskGroupParseStrategy();
38         completionStrategy = determineCompletionStrategy(kind);
39     }
40
41     private CompletionStrategy determineCompletionStrategy(String JavaDoc kind) {
42         if (ITaskGroup.CHOICE.equals(kind)) {
43             return new TaskChoiceCompletionStrategy();
44         }
45         return new TaskSetCompletionStrategy();
46     }
47
48     public ITaskParseStrategy getParserStrategy() {
49         return parserStrategy;
50     }
51     
52     public ICompositeCheatSheetTask[] getSubtasks() {
53         if (subtasks==null) return EMPTY;
54         return (ICompositeCheatSheetTask[])subtasks.toArray(new ICompositeCheatSheetTask[subtasks.size()]);
55     }
56     
57     public void addSubtask(ICompositeCheatSheetTask task) {
58         if (subtasks==null) {
59             subtasks = new ArrayList JavaDoc();
60         }
61         subtasks.add(task);
62         ((AbstractTask)task).setParent(this);
63     }
64     
65     /**
66      * Called when the state of a child has changed or when the model
67      * has been restored.
68      */

69     public void checkState() {
70         int newState = computeState();
71         if (newState != state) {
72             setStateNoNotify(newState);
73         }
74     }
75
76     /**
77      * Determine the state based on the state of the children, which
78      * will use a different computation depending on whether this is a set,
79      * sequence or choice.
80      */

81     public int computeState() {
82         return completionStrategy.computeState(this);
83     }
84
85 }
86
Popular Tags