1 package org.objectweb.kilim.tools; 2 3 import java.util.Iterator ; 4 import javax.swing.event.TreeModelListener ; 5 import javax.swing.tree.TreeModel ; 6 import javax.swing.tree.TreePath ; 7 8 import org.objectweb.kilim.model.Component; 9 import org.objectweb.kilim.model.ComponentSlot; 10 11 19 public class KilimComponentTreeModel implements TreeModel { 20 21 private Component component; 22 23 27 public KilimComponentTreeModel(Component cmpnnt) { 28 super(); 29 component = cmpnnt; 30 } 31 32 35 public Object getRoot() { 36 return component; 37 } 38 39 42 public Object getChild(Object parent, int index) { 43 44 if (parent instanceof Component) { 45 46 Component cmpnnt = (Component) parent; 47 Iterator intfcs = cmpnnt.getInterfaces(); 48 Iterator sbcmpnnts = cmpnnt.getSubComponents(); 49 Iterator slts = cmpnnt.getSlots(); 50 int crt_indx = 0; 51 for (; intfcs.hasNext(); crt_indx++) { 52 Object nxt = intfcs.next(); 53 if (crt_indx == index) { 54 return nxt; 55 } 56 } 57 for (; sbcmpnnts.hasNext(); crt_indx++) { 58 Object nxt = sbcmpnnts.next(); 59 if (crt_indx == index) { 60 return nxt; 61 } 62 } 63 for (; slts.hasNext(); crt_indx++) { 64 Object nxt = slts.next(); 65 if (crt_indx == index) { 66 return nxt; 67 } 68 } 69 return null; 70 71 } else if (parent instanceof ComponentSlot) { 72 ComponentSlot slt = (ComponentSlot) parent; 73 int crt_indx = 0; 74 Iterator plgs = slt.getPlugIns(); 75 for (; plgs.hasNext(); crt_indx++) { 76 Object nxt = plgs.next(); 77 if (crt_indx == index) { 78 return nxt; 79 } 80 } 81 82 } 83 84 return null; 85 } 86 87 90 public int getChildCount(Object parent) { 91 92 if (parent instanceof Component) { 93 94 Component cmpnnt = (Component) parent; 95 Iterator intfcs = cmpnnt.getInterfaces(); 96 Iterator sbcmpnnts = cmpnnt.getSubComponents(); 97 Iterator slts = cmpnnt.getSlots(); 98 int crt_indx = 0; 99 for (; intfcs.hasNext(); crt_indx++) { 100 intfcs.next(); 101 } 102 for (; sbcmpnnts.hasNext(); crt_indx++) { 103 sbcmpnnts.next(); 104 } 105 for (; slts.hasNext(); crt_indx++) { 106 slts.next(); 107 } 108 return crt_indx; 109 110 } else if (parent instanceof ComponentSlot) { 111 112 Iterator plgs = ((ComponentSlot) parent).getPlugIns(); 113 int crt_indx = 0; 114 for (; plgs.hasNext(); crt_indx++) { 115 plgs.next(); 116 } 117 return crt_indx; 118 119 } 120 121 return 0; 122 } 123 124 127 public boolean isLeaf(Object node) { 128 return (getChildCount(node) == 0); 129 } 130 131 134 public void valueForPathChanged(TreePath path, Object newValue) { 135 } 136 137 140 public int getIndexOfChild(Object parent, Object child) { 141 if (parent instanceof Component) { 142 143 Component cmpnnt = (Component) parent; 144 Iterator intfcs = cmpnnt.getInterfaces(); 145 Iterator sbcmpnnts = cmpnnt.getSubComponents(); 146 Iterator slts = cmpnnt.getSlots(); 147 int crt_indx = 0; 148 for (; intfcs.hasNext(); crt_indx++) { 149 Object nxt = intfcs.next(); 150 if (nxt == child) { 151 return crt_indx; 152 } 153 } 154 for (; sbcmpnnts.hasNext(); crt_indx++) { 155 Object nxt = sbcmpnnts.next(); 156 if (nxt == child) { 157 return crt_indx; 158 } 159 } 160 for (; slts.hasNext(); crt_indx++) { 161 Object nxt = slts.next(); 162 if (nxt == child) { 163 return crt_indx; 164 } 165 } 166 return -1; 167 168 } else if (parent instanceof ComponentSlot) { 169 170 ComponentSlot slt = (ComponentSlot) parent; 171 Iterator plgs = slt.getPlugIns(); 172 int crt_indx = 0; 173 for (; plgs.hasNext(); crt_indx++) { 174 Object nxt = plgs.next(); 175 if (nxt == child) { 176 return crt_indx; 177 } 178 } 179 } 180 return -1; 181 } 182 183 186 public void addTreeModelListener(TreeModelListener l) { 187 } 188 189 192 public void removeTreeModelListener(TreeModelListener l) { 193 } 194 195 } 196 | Popular Tags |