KickJava   Java API By Example, From Geeks To Geeks.

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


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
28 /**
29  * This class is used to represent the root entry of the TreeViewer used in the Schema Elements View.
30  *
31  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
32  * @version $Rev$, $Date$
33  */

34 public class SchemaElementsViewRoot extends TreeNode
35 {
36     /** The AT children */
37     private List JavaDoc<AttributeTypeWrapper> aTChildren;
38
39     /** The OC children */
40     private List JavaDoc<ObjectClassWrapper> ocChildren;
41
42
43     /**
44      * Creates a new instance of SchemasViewRoot.
45      *
46      */

47     public SchemaElementsViewRoot()
48     {
49         super( null );
50     }
51
52
53     /* (non-Javadoc)
54      * @see java.lang.Object#toString()
55      */

56     public String JavaDoc toString()
57     {
58         return "SchemaElementsViewRoot"; //$NON-NLS-1$
59
}
60
61
62     /**
63      * Adds an Attribute Type Wrapper to the list of children.
64      *
65      * @param atw
66      * the Attribute Type Wrapper to add
67      */

68     public void addAttributeType( AttributeTypeWrapper atw )
69     {
70         if ( aTChildren == null )
71         {
72             aTChildren = new ArrayList JavaDoc<AttributeTypeWrapper>();
73         }
74
75         if ( !aTChildren.contains( atw ) )
76         {
77             aTChildren.add( atw );
78         }
79     }
80
81
82     /**
83      * Adds an Object Class Wrapper to the list of children.
84      *
85      * @param ocw
86      * the Object Class Wrapper to add
87      */

88     public void addObjectClass( ObjectClassWrapper ocw )
89     {
90         if ( ocChildren == null )
91         {
92             ocChildren = new ArrayList JavaDoc<ObjectClassWrapper>();
93         }
94
95         if ( !ocChildren.contains( ocw ) )
96         {
97             ocChildren.add( ocw );
98         }
99     }
100
101
102     /**
103      * Gets the children Attribute Type Wrappers.
104      *
105      * @return
106      * the children Attribute Type Wrappers
107      */

108     public List JavaDoc<AttributeTypeWrapper> getAttributeTypes()
109     {
110         if ( aTChildren == null )
111         {
112             aTChildren = new ArrayList JavaDoc<AttributeTypeWrapper>();
113         }
114
115         return aTChildren;
116     }
117
118
119     /**
120      * Gets the children Object Class Wrappers.
121      *
122      * @return
123      * the children Object Class Wrappers
124      */

125     public List JavaDoc<ObjectClassWrapper> getObjectClasses()
126     {
127         if ( ocChildren == null )
128         {
129             ocChildren = new ArrayList JavaDoc<ObjectClassWrapper>();
130         }
131
132         return ocChildren;
133     }
134
135
136     /* (non-Javadoc)
137      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.TreeNode#addChild(org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode)
138      */

139     public void addChild( ITreeNode node )
140     {
141         if ( node instanceof AttributeTypeWrapper )
142         {
143             addAttributeType( ( AttributeTypeWrapper ) node );
144         }
145         else if ( node instanceof ObjectClassWrapper )
146         {
147             addObjectClass( ( ObjectClassWrapper ) node );
148         }
149     }
150
151
152     /* (non-Javadoc)
153      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.TreeNode#addAllChildren(java.util.Collection)
154      */

155     public boolean addAllChildren( Collection JavaDoc<? extends ITreeNode> c )
156     {
157         for ( ITreeNode child : c )
158         {
159             addChild( child );
160         }
161         return true;
162     }
163
164
165     /* (non-Javadoc)
166      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.TreeNode#removeChild(org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.ITreeNode)
167      */

168     public void removeChild( ITreeNode node )
169     {
170         if ( node instanceof AttributeTypeWrapper )
171         {
172             removeAttributeType( ( AttributeTypeWrapper ) node );
173         }
174         else if ( node instanceof ObjectClassWrapper )
175         {
176             removeObjectClass( ( ObjectClassWrapper ) node );
177         }
178     }
179
180
181     /**
182      * Removes an Attribute Type Wrapper.
183      *
184      * @param wrapper
185      * the Attribute Type Wrapper to remove
186      */

187     private void removeAttributeType( AttributeTypeWrapper wrapper )
188     {
189         if ( aTChildren != null )
190         {
191             aTChildren.remove( wrapper );
192         }
193     }
194
195
196     /**
197      * Removes an Object Class Wrapper.
198      *
199      * @param wrapper
200      * the Object Class Wrapper to remove
201      */

202     private void removeObjectClass( ObjectClassWrapper wrapper )
203     {
204         if ( ocChildren != null )
205         {
206             ocChildren.remove( wrapper );
207         }
208     }
209
210
211     /* (non-Javadoc)
212      * @see org.apache.directory.ldapstudio.schemas.view.viewers.wrappers.TreeNode#getChildren()
213      */

214     public List JavaDoc<ITreeNode> getChildren()
215     {
216         List JavaDoc<ITreeNode> children = new ArrayList JavaDoc<ITreeNode>();
217         children.addAll( getAttributeTypes() );
218         children.addAll( getObjectClasses() );
219         return children;
220     }
221 }
222
Popular Tags