KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb2 > ojbmetatreemodel > OjbMetaTreeNode


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

15
16 package org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel;
17
18 import org.apache.ojb.tools.mapping.reversedb2.propertyEditors.EditableTreeNodeWithProperties;
19 import javax.swing.tree.TreeNode JavaDoc;
20
21
22
23 /**
24  * Abstract implementation of a treenode representing a metadata object
25  * in a repository.
26  *
27  * @author <a HREF="mailto:bfl@florianbruckner.com">Florian Bruckner</a>
28  * @version $Id: OjbMetaTreeNode.java,v 1.1.2.1 2005/12/21 22:32:39 tomdz Exp $
29  *
30  */

31 public abstract class OjbMetaTreeNode extends EditableTreeNodeWithProperties
32     implements Comparable JavaDoc,
33                org.apache.ojb.tools.mapping.reversedb2.ActionTarget
34 {
35     private OjbMetaTreeNode parent;
36     private org.apache.ojb.broker.metadata.DescriptorRepository repository;
37     private OjbMetaDataTreeModel treeModel;
38     protected java.util.ArrayList JavaDoc alChildren = new java.util.ArrayList JavaDoc();
39         
40     public OjbMetaTreeNode(org.apache.ojb.broker.metadata.DescriptorRepository pRepository, OjbMetaDataTreeModel pTreeModel, OjbMetaTreeNode pparent)
41     {
42         this.parent = pparent;
43         this.repository = pRepository;
44         this.treeModel = pTreeModel;
45     }
46     
47     public org.apache.ojb.broker.metadata.DescriptorRepository getRepository()
48     {
49         return this.repository;
50     }
51         
52     /**
53      * @see TreeNode#getChildAt(int)
54      */

55     public TreeNode JavaDoc getChildAt(int index)
56     {
57         return (TreeNode JavaDoc)this.alChildren.get(index);
58     }
59     
60     /**
61      * @see TreeNode#getChildCount()
62      */

63     public int getChildCount()
64     {
65         return this.alChildren.size();
66     }
67     
68     /**
69      * @see TreeNode#getParent()
70      */

71     public TreeNode JavaDoc getParent()
72     {
73         return this.parent;
74     }
75     
76     /**
77      * @see TreeNode#getIndex(TreeNode)
78      */

79     public int getIndex(TreeNode JavaDoc o)
80     {
81         return this.alChildren.indexOf(o);
82     }
83     
84     /**
85      * @see TreeNode#getAllowsChildren()
86      */

87     public abstract boolean getAllowsChildren();
88     
89     /**
90      * @see TreeNode#isLeaf()
91      */

92     public abstract boolean isLeaf();
93     
94     /**
95      * @see TreeNode#children()
96      */

97     public java.util.Enumeration JavaDoc children ()
98     {
99         return java.util.Collections.enumeration(this.alChildren);
100     }
101     
102     /**
103      * Access method for the TreeModel this node is associated to.
104      */

105     protected OjbMetaDataTreeModel getOjbMetaTreeModel()
106     {
107         return treeModel;
108     }
109     
110     /**
111      * Purpose of this method is to fill the children of the node. It should
112      * replace all children in alChildren (the arraylist containing the children)
113      * of this node and notify the TreeModel that a change has occurred.
114      */

115     protected abstract boolean _load();
116     
117     /**
118      * Recursively loads the metadata for this node
119      */

120     public boolean load()
121     {
122         _load();
123         java.util.Iterator JavaDoc it = this.alChildren.iterator();
124         while (it.hasNext())
125         {
126             Object JavaDoc o = it.next();
127             if (o instanceof OjbMetaTreeNode) ((OjbMetaTreeNode)o).load();
128         }
129         return true;
130     }
131     
132     /**
133      * @see Comparable#compareTo(Object)
134      */

135     public int compareTo(Object JavaDoc arg0)
136     {
137         return this.toString().compareTo(arg0.toString());
138     }
139     
140     /**
141      * Return the descriptor object this node is associated with. E.g. if the
142      * node displays a class descriptor, the ClassDescriptor describing the class
143      * should be returned. Used for creating a Transferable.
144      */

145     public abstract Object JavaDoc getAssociatedDescriptor();
146     
147 }
148
Popular Tags