Skip to main content
summaryrefslogtreecommitdiffstats
blob: 07e95b0a3f511c291f1fbbea1147875f40a036b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*******************************************************************************
 * Copyright (c) 2006, 2015 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.ui.internal.cheatsheets.composite.parser;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.internal.cheatsheets.Messages;
import org.eclipse.ui.internal.cheatsheets.composite.model.AbstractTask;
import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask;
import org.eclipse.ui.internal.provisional.cheatsheets.ITaskGroup;
import org.w3c.dom.Node;

public class TaskGroupParseStrategy implements ITaskParseStrategy {


	public TaskGroupParseStrategy() {
	}

	@Override
	public void init() {
	}

	@Override
	public boolean parseElementNode(Node childNode, Node parentNode,
			AbstractTask parentTask, IStatusContainer status)
    {
		// Task children are handled by CompositeCheatSheetParser
		return false;
	}

	@Override
	public void parsingComplete(AbstractTask parentTask, IStatusContainer status) {
		String kind = parentTask.getKind();
		if (ITaskGroup.SEQUENCE.equals(kind)) {
			// Create dependencies between the children
			ICompositeCheatSheetTask[] children  = parentTask.getSubtasks();
			AbstractTask previous = null;
			AbstractTask next = null;
			for (int i = 0; i < children.length; i++) {
				previous = next;
				next = (AbstractTask)children[i];
				if (previous != null) {
					next.addRequiredTask(previous);
				}
			}
			checkForChildren(parentTask, status);
		} else if (ITaskGroup.SET.equals(kind)) {
			checkForChildren(parentTask, status);
		} else if (ITaskGroup.CHOICE.equals(kind)) {
			checkForChildren(parentTask, status);
		} else {
			String message = NLS.bind(
					Messages.ERROR_PARSING_TASK_INVALID_KIND,
					(new Object[] { parentTask.getKind(), ICompositeCheatsheetTags.TASK_GROUP, parentTask.getName()}));
		    status.addStatus(IStatus.ERROR, message, null);
		}
	}

	private void checkForChildren(AbstractTask parentTask, IStatusContainer status) {
		if (parentTask.getSubtasks().length < 1) {
			String message = NLS.bind(
					Messages.ERROR_PARSING_CHILDLESS_TASK_GROUP,
					(new Object[] { parentTask.getName()}));
		    status.addStatus(IStatus.ERROR, message, null);
		}
	}


}

Back to the top