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.parser;
11:
12: import org.eclipse.core.runtime.IStatus;
13: import org.eclipse.osgi.util.NLS;
14: import org.eclipse.ui.internal.cheatsheets.Messages;
15: import org.eclipse.ui.internal.cheatsheets.composite.model.AbstractTask;
16: import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask;
17: import org.eclipse.ui.internal.provisional.cheatsheets.ITaskGroup;
18: import org.w3c.dom.Node;
19:
20: public class TaskGroupParseStrategy implements ITaskParseStrategy {
21:
22: public TaskGroupParseStrategy() {
23: }
24:
25: public void init() {
26: }
27:
28: public boolean parseElementNode(Node childNode, Node parentNode,
29: AbstractTask parentTask, IStatusContainer status) {
30: // Task children are handled by CompositeCheatSheetParser
31: return false;
32: }
33:
34: public void parsingComplete(AbstractTask parentTask,
35: IStatusContainer status) {
36: String kind = parentTask.getKind();
37: if (ITaskGroup.SEQUENCE.equals(kind)) {
38: // Create dependencies between the children
39: ICompositeCheatSheetTask[] children = parentTask
40: .getSubtasks();
41: AbstractTask previous = null;
42: AbstractTask next = null;
43: for (int i = 0; i < children.length; i++) {
44: previous = next;
45: next = (AbstractTask) children[i];
46: if (previous != null) {
47: next.addRequiredTask(previous);
48: }
49: }
50: checkForChildren(parentTask, status);
51: } else if (ITaskGroup.SET.equals(kind)) {
52: checkForChildren(parentTask, status);
53: } else if (ITaskGroup.CHOICE.equals(kind)) {
54: checkForChildren(parentTask, status);
55: } else {
56: String message = NLS.bind(
57: Messages.ERROR_PARSING_TASK_INVALID_KIND,
58: (new Object[] { parentTask.getKind(),
59: ICompositeCheatsheetTags.TASK_GROUP,
60: parentTask.getName() }));
61: status.addStatus(IStatus.ERROR, message, null);
62: }
63: }
64:
65: private void checkForChildren(AbstractTask parentTask,
66: IStatusContainer status) {
67: if (parentTask.getSubtasks().length < 1) {
68: String message = NLS.bind(
69: Messages.ERROR_PARSING_CHILDLESS_TASK_GROUP,
70: (new Object[] { parentTask.getName() }));
71: status.addStatus(IStatus.ERROR, message, null);
72: }
73: }
74:
75: }
|