KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > toc > TocNode


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.help.internal.toc;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Collections JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.help.internal.FilterableHelpElement;
19
20 /**
21  * Navigation Element. Common for all objects definable in toc.xml
22  */

23 abstract class TocNode extends FilterableHelpElement implements ITocNode {
24     protected List JavaDoc children;
25     protected List JavaDoc parents;
26
27     /**
28      * Adds another element as child of this element Modifies parents of a child
29      * as well
30      */

31     public void addChild(ITocNode child) {
32         if (children == null)
33             children = new ArrayList JavaDoc();
34         children.add(child);
35         if (child instanceof TocNode)
36             ((TocNode) child).addParent(this);
37     }
38     /**
39      * Adds parent parents of this element called by addChild method
40      */

41     protected void addParent(ITocNode parent) {
42         if (parents == null)
43             parents = new ArrayList JavaDoc();
44         parents.add(parent);
45     }
46
47     /**
48      * Obtains children
49      *
50      * @return ITocNode List
51      */

52     public List JavaDoc getChildren() {
53         if (children == null)
54             return Collections.EMPTY_LIST;
55         return children;
56     }
57     /**
58      * Obtains parents
59      *
60      * @return ITocNode List
61      */

62     protected List JavaDoc getParents() {
63         if (parents == null)
64             return Collections.EMPTY_LIST;
65         return parents;
66     }
67
68     /**
69      * @return ITopic list
70      */

71     public List JavaDoc getChildTopics() {
72         if (children == null)
73             return Collections.EMPTY_LIST;
74         List JavaDoc childTopics = new ArrayList JavaDoc(children.size());
75         for (Iterator JavaDoc childrenIt = children.iterator(); childrenIt.hasNext();) {
76             TocNode c = (TocNode) childrenIt.next();
77             if ((c instanceof Topic)) {
78                 childTopics.add(c);
79             } else {
80                 // it is a Toc, Anchor or Link,
81
// which may have children attached to it.
82
childTopics.addAll(c.getChildTopics());
83             }
84         }
85         return childTopics;
86     }
87 }
88
Popular Tags