1 11 12 package org.eclipse.ui.internal.cheatsheets.composite.model; 13 14 import java.util.ArrayList ; 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 subtasks; 29 30 private CompletionStrategy completionStrategy; 31 32 public TaskGroup(CompositeCheatSheetModel model, String id, String name, String 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 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 (); 60 } 61 subtasks.add(task); 62 ((AbstractTask)task).setParent(this); 63 } 64 65 69 public void checkState() { 70 int newState = computeState(); 71 if (newState != state) { 72 setStateNoNotify(newState); 73 } 74 } 75 76 81 public int computeState() { 82 return completionStrategy.computeState(this); 83 } 84 85 } 86 | Popular Tags |