1 package org.objectweb.kilim.tools; 2 3 import java.util.Iterator ; 4 5 import javax.swing.event.TreeModelListener ; 6 import javax.swing.tree.TreeModel ; 7 import javax.swing.tree.TreePath ; 8 9 import org.objectweb.kilim.KilimException; 10 import org.objectweb.kilim.description.Instance; 11 import org.objectweb.kilim.description.Slot; 12 import org.objectweb.kilim.description.TemplateDescription; 13 14 22 public class KilimTemplateTreeModel implements TreeModel { 23 24 private TemplateDescription template; 25 26 30 public KilimTemplateTreeModel(TemplateDescription tmplt) { 31 super(); 32 template = tmplt; 33 } 34 35 38 public Object getRoot() { 39 return template; 40 } 41 42 45 public Object getChild(Object parent, int index) { 46 TemplateDescription tmplt_t_b_dsplyd; 47 48 if (parent instanceof TemplateDescription) { 49 tmplt_t_b_dsplyd = (TemplateDescription) parent; 50 } else if (parent instanceof Instance) { 51 tmplt_t_b_dsplyd = ((Instance) parent).getTemplate(); 52 } else if (parent instanceof Slot) { 53 return getChildOfSlot((Slot) parent, index); 54 } else { 55 return null; 56 } 57 try { 58 59 Iterator prts = tmplt_t_b_dsplyd.getPorts(false); 60 Iterator prvdrs = tmplt_t_b_dsplyd.getProviders(false); 61 Iterator trnsfrmrs = tmplt_t_b_dsplyd.getTransformers(false); 62 Iterator bndgs = tmplt_t_b_dsplyd.getBindings(false); 63 Iterator trggrs = tmplt_t_b_dsplyd.getTriggers(false); 64 Iterator prprts = tmplt_t_b_dsplyd.getProperties(false); 65 Iterator instncs = tmplt_t_b_dsplyd.getInstances(false); 66 Iterator slts = tmplt_t_b_dsplyd.getSlots(false); 67 Iterator plgs = tmplt_t_b_dsplyd.getPlugs(false); 68 69 int cntr = 0; 70 for (; prts.hasNext(); cntr++) { 71 Object prt = prts.next(); 72 if (cntr == index) { 73 return prt; 74 } 75 } 76 for (; prvdrs.hasNext(); cntr++) { 77 Object prvdr = prvdrs.next(); 78 if (cntr == index) { 79 return prvdr; 80 } 81 } 82 for (; trnsfrmrs.hasNext(); cntr++) { 83 Object trnsfrmr = trnsfrmrs.next(); 84 if (cntr == index) { 85 return trnsfrmr; 86 } 87 } 88 for (; bndgs.hasNext(); cntr++) { 89 Object bndg = bndgs.next(); 90 if (cntr == index) { 91 return bndg; 92 } 93 } 94 for (; trggrs.hasNext(); cntr++) { 95 Object trggr = trggrs.next(); 96 if (cntr == index) { 97 return trggr; 98 } 99 } 100 for (; prprts.hasNext(); cntr++) { 101 Object prprt = prprts.next(); 102 if (cntr == index) { 103 return prprt; 104 } 105 } 106 for (; instncs.hasNext(); cntr++) { 107 Object instnc = instncs.next(); 108 if (cntr == index) { 109 return instnc; 110 } 111 } 112 for (; slts.hasNext(); cntr++) { 113 Object slt = slts.next(); 114 if (cntr == index) { 115 return slt; 116 } 117 } 118 for (; plgs.hasNext(); cntr++) { 119 Object plg = plgs.next(); 120 if (cntr == index) { 121 return plg; 122 } 123 } 124 } catch (KilimException exp) { 125 exp.printStackTrace(); 126 return null; 127 } 128 129 return null; 130 } 131 132 private Object getChildOfSlot(Slot slt, int index) { 133 Iterator prts = slt.getPorts(); 134 int cntr = 0; 135 for (; prts.hasNext(); cntr++) { 136 Object prt = prts.next(); 137 if (cntr == index) { 138 return prt; 139 } 140 } 141 return null; 142 } 143 144 147 public int getChildCount(Object parent) { 148 149 TemplateDescription tmplt_t_b_dsplyd; 150 151 if (parent instanceof TemplateDescription) { 152 tmplt_t_b_dsplyd = (TemplateDescription) parent; 153 } else if (parent instanceof Instance) { 154 tmplt_t_b_dsplyd = ((Instance) parent).getTemplate(); 155 } else if (parent instanceof Slot) { 156 return getChildCountOfSlot((Slot) parent); 157 } else { 158 return 0; 159 } 160 int cntr = 0; 161 162 try { 163 164 Iterator prts = tmplt_t_b_dsplyd.getPorts(false); 165 Iterator prvdrs = tmplt_t_b_dsplyd.getProviders(false); 166 Iterator trnsfrmrs = tmplt_t_b_dsplyd.getTransformers(false); 167 Iterator bndgs = tmplt_t_b_dsplyd.getBindings(false); 168 Iterator trggrs = tmplt_t_b_dsplyd.getTriggers(false); 169 Iterator prprts = tmplt_t_b_dsplyd.getProperties(false); 170 Iterator instncs = tmplt_t_b_dsplyd.getInstances(false); 171 Iterator slts = tmplt_t_b_dsplyd.getSlots(false); 172 Iterator plgs = tmplt_t_b_dsplyd.getPlugs(false); 173 174 for (; prts.hasNext(); cntr++) { 175 Object prt = prts.next(); 176 } 177 for (; prvdrs.hasNext(); cntr++) { 178 Object prvdr = prvdrs.next(); 179 } 180 for (; trnsfrmrs.hasNext(); cntr++) { 181 Object trnsfrmr = trnsfrmrs.next(); 182 } 183 for (; bndgs.hasNext(); cntr++) { 184 Object bndg = bndgs.next(); 185 } 186 for (; trggrs.hasNext(); cntr++) { 187 Object trggr = trggrs.next(); 188 } 189 for (; prprts.hasNext(); cntr++) { 190 Object prprt = prprts.next(); 191 } 192 for (; instncs.hasNext(); cntr++) { 193 Object instnc = instncs.next(); 194 } 195 for (; slts.hasNext(); cntr++) { 196 Object slt = slts.next(); 197 } 198 for (; plgs.hasNext(); cntr++) { 199 Object plg = plgs.next(); 200 } 201 } catch (KilimException exp) { 202 exp.printStackTrace(); 203 return cntr; 204 } 205 206 return cntr; 207 } 208 209 private int getChildCountOfSlot(Slot slt) { 210 Iterator prts = slt.getPorts(); 211 int cntr = 0; 212 for (; prts.hasNext(); cntr++) { 213 Object prt = prts.next(); 214 } 215 return cntr; 216 } 217 218 221 public boolean isLeaf(Object node) { 222 return (!((node instanceof TemplateDescription) || (node instanceof Instance) || (node instanceof Slot))); 223 } 224 225 228 public void valueForPathChanged(TreePath path, Object newValue) { 229 } 230 231 234 public int getIndexOfChild(Object parent, Object child) { 235 TemplateDescription tmplt_t_b_dsplyd; 236 237 if (parent instanceof TemplateDescription) { 238 tmplt_t_b_dsplyd = (TemplateDescription) parent; 239 } else if (parent instanceof Instance) { 240 tmplt_t_b_dsplyd = ((Instance) parent).getTemplate(); 241 } else if (parent instanceof Slot) { 242 return getIndexOfChildInSlot((Slot) parent, child); 243 } else { 244 return -1; 245 } 246 try { 247 248 Iterator prts = tmplt_t_b_dsplyd.getPorts(false); 249 Iterator prvdrs = tmplt_t_b_dsplyd.getProviders(false); 250 Iterator trnsfrmrs = tmplt_t_b_dsplyd.getTransformers(false); 251 Iterator bndgs = tmplt_t_b_dsplyd.getBindings(false); 252 Iterator trggrs = tmplt_t_b_dsplyd.getTriggers(false); 253 Iterator prprts = tmplt_t_b_dsplyd.getProperties(false); 254 Iterator instncs = tmplt_t_b_dsplyd.getInstances(false); 255 Iterator slts = tmplt_t_b_dsplyd.getSlots(false); 256 Iterator plgs = tmplt_t_b_dsplyd.getPlugs(false); 257 258 int cntr = 0; 259 for (; prts.hasNext(); cntr++) { 260 Object prt = prts.next(); 261 if (prt == child) { 262 return cntr; 263 } 264 } 265 for (; prvdrs.hasNext(); cntr++) { 266 Object prvdr = prvdrs.next(); 267 if (prvdr == child) { 268 return cntr; 269 } 270 } 271 for (; trnsfrmrs.hasNext(); cntr++) { 272 Object trnsfrmr = trnsfrmrs.next(); 273 if (trnsfrmr == child) { 274 return cntr; 275 } 276 } 277 for (; bndgs.hasNext(); cntr++) { 278 Object bndg = bndgs.next(); 279 if (bndg == child) { 280 return cntr; 281 } 282 } 283 for (; trggrs.hasNext(); cntr++) { 284 Object trggr = trggrs.next(); 285 if (trggr == child) { 286 return cntr; 287 } 288 } 289 for (; prprts.hasNext(); cntr++) { 290 Object prprt = prprts.next(); 291 if (prprt == child) { 292 return cntr; 293 } 294 } 295 for (; instncs.hasNext(); cntr++) { 296 Object instnc = instncs.next(); 297 if (instnc == child) { 298 return cntr; 299 } 300 } 301 for (; slts.hasNext(); cntr++) { 302 Object slt = slts.next(); 303 if (slt == child) { 304 return cntr; 305 } 306 } 307 for (; plgs.hasNext(); cntr++) { 308 Object plg = plgs.next(); 309 if (plg == child) { 310 return cntr; 311 } 312 } 313 } catch (KilimException exp) { 314 exp.printStackTrace(); 315 return -1; 316 } 317 318 return -1; 319 } 320 321 private int getIndexOfChildInSlot(Slot slot, Object child) { 322 Iterator prts = slot.getPorts(); 323 int cntr = 0; 324 for (; prts.hasNext(); cntr++) { 325 Object prt = prts.next(); 326 if (prt == child) { 327 return cntr; 328 } 329 } 330 return -1; 331 } 332 333 336 public void addTreeModelListener(TreeModelListener l) { 337 } 338 339 342 public void removeTreeModelListener(TreeModelListener l) { 343 } 344 345 } 346 | Popular Tags |