1 15 16 package org.apache.ojb.tools.mapping.reversedb2.dbmetatreemodel; 17 18 import javax.swing.tree.TreeNode ; 19 import org.apache.ojb.tools.mapping.reversedb2.propertyEditors.EditableTreeNodeWithProperties; 20 21 22 28 public abstract class ReverseDbTreeNode extends EditableTreeNodeWithProperties 29 implements java.io.Serializable 30 { 31 transient private java.sql.DatabaseMetaData dbMeta; 32 private DatabaseMetaDataTreeModel dbMetaTreeModel; 33 34 37 protected java.util.ArrayList alChildren = new java.util.ArrayList (); 38 39 private boolean isFilled = false; 40 41 transient private Object populationLock = new Object (); 42 private boolean populationInProgress = false; 43 44 private ReverseDbTreeNode parent = null; 45 46 public ReverseDbTreeNode( 47 java.sql.DatabaseMetaData pdbMeta, 48 DatabaseMetaDataTreeModel pdbMetaTreeModel, 49 ReverseDbTreeNode pparent) 50 { 51 this.dbMeta = pdbMeta; 52 this.dbMetaTreeModel = pdbMetaTreeModel; 53 this.parent = pparent; 54 alChildren.add(new javax.swing.tree.DefaultMutableTreeNode ("...")); 55 } 56 57 60 public TreeNode getChildAt(int index) 61 { 62 if (!this.isFilled) this.load(false, false, true); 63 return (TreeNode )this.alChildren.get(index); 64 } 65 66 69 public int getChildCount() 70 { 71 return this.alChildren.size(); 72 } 73 74 77 public TreeNode getParent() 78 { 79 return this.parent; 80 } 81 82 85 public int getIndex(TreeNode o) 86 { 87 return this.alChildren.indexOf(o); 88 } 89 90 93 public abstract boolean getAllowsChildren(); 94 95 98 public abstract boolean isLeaf(); 99 100 103 public java.util.Enumeration children () 104 { 105 if (!this.isFilled) this.load(false, false, true); 106 return java.util.Collections.enumeration(this.alChildren); 107 } 108 109 118 public void load(final boolean recursive, final boolean replace, final boolean inNewThread) 119 { 120 if (inNewThread) 121 { 122 new Thread () 123 { 124 public void run() 125 { 126 load(recursive, replace, false); 127 } 128 }.start(); 129 return; 130 } 131 if (!populationInProgress) 132 { 133 synchronized (this.populationLock) 134 { 135 this.populationInProgress = true; 136 if (replace || !this.isFilled) 137 { 138 this.isFilled = _load(); 139 } 140 this.populationInProgress = false; 141 } 142 if (!recursive) 143 this.getDbMetaTreeModel ().setStatusBarMessage ("Done"); 144 } 145 if (recursive) 146 { 147 java.util.Enumeration e = this.children(); 148 while (e.hasMoreElements()) 149 { 150 Object o = e.nextElement(); 151 if (o instanceof ReverseDbTreeNode) 152 ((ReverseDbTreeNode) o).load(recursive, replace, false); 153 } 154 this.getDbMetaTreeModel ().setStatusBarMessage ("Done"); 155 } 156 } 157 158 165 public void loadWait( 166 final boolean recursive, 167 final boolean replace, 168 final boolean inNewThread) 169 { 170 if (inNewThread) 171 { 172 new Thread () 173 { 174 public void run() 175 { 176 loadWait(recursive, replace, false); 177 } 178 }.start(); 179 return; 180 } 181 182 synchronized (this.populationLock) 183 { 184 this.populationInProgress = true; 185 if (replace || !this.isFilled) 186 { 187 this.isFilled = _load(); 188 } 189 if (recursive) 190 { 191 java.util.Enumeration e = this.children(); 192 while (e.hasMoreElements()) 193 { 194 Object o = e.nextElement(); 195 if (o instanceof ReverseDbTreeNode) 196 ((ReverseDbTreeNode)o).loadWait(recursive, replace, false); 197 } 198 } 199 this.populationInProgress = false; 200 } 201 this.getDbMetaTreeModel ().setStatusBarMessage("Done"); 202 } 203 204 207 protected java.sql.DatabaseMetaData getDbMeta() 208 { 209 return dbMeta; 210 } 211 212 215 protected DatabaseMetaDataTreeModel getDbMetaTreeModel() 216 { 217 return dbMetaTreeModel; 218 } 219 220 225 protected abstract boolean _load(); 226 227 } 228 | Popular Tags |