001: /* Copyright 2002-2005 The Apache Software Foundation
002: *
003: * Licensed under the Apache License, Version 2.0 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software
010: * distributed under the License is distributed on an "AS IS" BASIS,
011: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: * See the License for the specific language governing permissions and
013: * limitations under the License.
014: */
015:
016: package org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel;
017:
018: import org.apache.ojb.tools.mapping.reversedb2.propertyEditors.EditableTreeNodeWithProperties;
019: import javax.swing.tree.TreeNode;
020:
021: /**
022: * Abstract implementation of a treenode representing a metadata object
023: * in a repository.
024: *
025: * @author <a href="mailto:bfl@florianbruckner.com">Florian Bruckner</a>
026: * @version $Id: OjbMetaTreeNode.java,v 1.1.2.1 2005/12/21 22:32:39 tomdz Exp $
027: *
028: */
029: public abstract class OjbMetaTreeNode extends
030: EditableTreeNodeWithProperties implements Comparable,
031: org.apache.ojb.tools.mapping.reversedb2.ActionTarget {
032: private OjbMetaTreeNode parent;
033: private org.apache.ojb.broker.metadata.DescriptorRepository repository;
034: private OjbMetaDataTreeModel treeModel;
035: protected java.util.ArrayList alChildren = new java.util.ArrayList();
036:
037: public OjbMetaTreeNode(
038: org.apache.ojb.broker.metadata.DescriptorRepository pRepository,
039: OjbMetaDataTreeModel pTreeModel, OjbMetaTreeNode pparent) {
040: this .parent = pparent;
041: this .repository = pRepository;
042: this .treeModel = pTreeModel;
043: }
044:
045: public org.apache.ojb.broker.metadata.DescriptorRepository getRepository() {
046: return this .repository;
047: }
048:
049: /**
050: * @see TreeNode#getChildAt(int)
051: */
052: public TreeNode getChildAt(int index) {
053: return (TreeNode) this .alChildren.get(index);
054: }
055:
056: /**
057: * @see TreeNode#getChildCount()
058: */
059: public int getChildCount() {
060: return this .alChildren.size();
061: }
062:
063: /**
064: * @see TreeNode#getParent()
065: */
066: public TreeNode getParent() {
067: return this .parent;
068: }
069:
070: /**
071: * @see TreeNode#getIndex(TreeNode)
072: */
073: public int getIndex(TreeNode o) {
074: return this .alChildren.indexOf(o);
075: }
076:
077: /**
078: * @see TreeNode#getAllowsChildren()
079: */
080: public abstract boolean getAllowsChildren();
081:
082: /**
083: * @see TreeNode#isLeaf()
084: */
085: public abstract boolean isLeaf();
086:
087: /**
088: * @see TreeNode#children()
089: */
090: public java.util.Enumeration children() {
091: return java.util.Collections.enumeration(this .alChildren);
092: }
093:
094: /**
095: * Access method for the TreeModel this node is associated to.
096: */
097: protected OjbMetaDataTreeModel getOjbMetaTreeModel() {
098: return treeModel;
099: }
100:
101: /**
102: * Purpose of this method is to fill the children of the node. It should
103: * replace all children in alChildren (the arraylist containing the children)
104: * of this node and notify the TreeModel that a change has occurred.
105: */
106: protected abstract boolean _load();
107:
108: /**
109: * Recursively loads the metadata for this node
110: */
111: public boolean load() {
112: _load();
113: java.util.Iterator it = this .alChildren.iterator();
114: while (it.hasNext()) {
115: Object o = it.next();
116: if (o instanceof OjbMetaTreeNode)
117: ((OjbMetaTreeNode) o).load();
118: }
119: return true;
120: }
121:
122: /**
123: * @see Comparable#compareTo(Object)
124: */
125: public int compareTo(Object arg0) {
126: return this .toString().compareTo(arg0.toString());
127: }
128:
129: /**
130: * Return the descriptor object this node is associated with. E.g. if the
131: * node displays a class descriptor, the ClassDescriptor describing the class
132: * should be returned. Used for creating a Transferable.
133: */
134: public abstract Object getAssociatedDescriptor();
135:
136: }
|