KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > views > wrappers > TreeNode


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20 package org.apache.directory.ldapstudio.schemas.view.views.wrappers;
21
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.eclipse.swt.graphics.Image;
28
29
30 /**
31  * This abstract class implements the ITreeNode Interface.
32  *
33  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
34  * @version $Rev$, $Date$
35  */

36 public abstract class TreeNode implements ITreeNode
37 {
38     /** The children */
39     protected List JavaDoc<ITreeNode> fChildren;
40
41     /** The parent */
42     protected ITreeNode fParent;
43
44
45     /**
46      * Creates a new instance of TreeNode.
47      *
48      * @param parent
49      * the parent element
50      */

51     public TreeNode( ITreeNode parent )
52     {
53         fParent = parent;
54     }
55
56
57     /* (non-Javadoc)
58      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode#getImage()
59      */

60     public Image getImage()
61     {
62         return null;
63     }
64
65
66     /* (non-Javadoc)
67      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode#hasChildren()
68      */

69     public boolean hasChildren()
70     {
71         if ( fChildren == null )
72         {
73             return true;
74         }
75
76         return !fChildren.isEmpty();
77     }
78
79
80     /* (non-Javadoc)
81      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode#getParent()
82      */

83     public ITreeNode getParent()
84     {
85         return fParent;
86     }
87
88
89     /* (non-Javadoc)
90      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode#setParent(org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode)
91      */

92     public void setParent( ITreeNode parent )
93     {
94         fParent = parent;
95     }
96
97
98     /* (non-Javadoc)
99      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode#getChildren()
100      */

101     public List JavaDoc<ITreeNode> getChildren()
102     {
103         if ( fChildren == null )
104         {
105             fChildren = new ArrayList JavaDoc<ITreeNode>();
106         }
107
108         return fChildren;
109     }
110
111
112     /* (non-Javadoc)
113      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode#addChild(org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode)
114      */

115     public void addChild( ITreeNode node )
116     {
117         if ( fChildren == null )
118         {
119             fChildren = new ArrayList JavaDoc<ITreeNode>();
120         }
121
122         if ( !fChildren.contains( node ) )
123         {
124             fChildren.add( node );
125         }
126     }
127
128
129     /* (non-Javadoc)
130      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode#removeChild(org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode)
131      */

132     /* (non-Javadoc)
133      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode#removeChild(org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode)
134      */

135     /* (non-Javadoc)
136      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode#removeChild(org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode)
137      */

138     public void removeChild( ITreeNode node )
139     {
140         if ( fChildren != null )
141         {
142             fChildren.remove( node );
143         }
144     }
145
146
147     /* (non-Javadoc)
148      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode#addAllChildren(java.util.Collection)
149      */

150     public boolean addAllChildren( Collection JavaDoc<? extends ITreeNode> c )
151     {
152         if ( fChildren == null )
153         {
154             fChildren = new ArrayList JavaDoc<ITreeNode>();
155         }
156
157         return fChildren.addAll( c );
158     }
159 }
160
Popular Tags