KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > composite > parser > TaskGroupParseStrategy


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