KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > tools > KilimTemplateTreeModel


1 package org.objectweb.kilim.tools;
2
3 import java.util.Iterator JavaDoc;
4
5 import javax.swing.event.TreeModelListener JavaDoc;
6 import javax.swing.tree.TreeModel JavaDoc;
7 import javax.swing.tree.TreePath JavaDoc;
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 /**
15  * @author delpiano
16  *
17  * To change this generated comment edit the template variable "typecomment":
18  * Window>Preferences>Java>Templates.
19  * To enable and disable the creation of type comments go to
20  * Window>Preferences>Java>Code Generation.
21  */

22 public class KilimTemplateTreeModel implements TreeModel JavaDoc {
23
24     private TemplateDescription template;
25
26     /**
27      * Method KilimTemplateTreeModel.
28      * @param tmplt :
29      */

30     public KilimTemplateTreeModel(TemplateDescription tmplt) {
31         super();
32         template = tmplt;
33     }
34
35     /**
36      * @see javax.swing.tree.TreeModel#getRoot()
37      */

38     public Object JavaDoc getRoot() {
39         return template;
40     }
41
42     /**
43      * @see javax.swing.tree.TreeModel#getChild(Object, int)
44      */

45     public Object JavaDoc getChild(Object JavaDoc 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 JavaDoc prts = tmplt_t_b_dsplyd.getPorts(false);
60             Iterator JavaDoc prvdrs = tmplt_t_b_dsplyd.getProviders(false);
61             Iterator JavaDoc trnsfrmrs = tmplt_t_b_dsplyd.getTransformers(false);
62             Iterator JavaDoc bndgs = tmplt_t_b_dsplyd.getBindings(false);
63             Iterator JavaDoc trggrs = tmplt_t_b_dsplyd.getTriggers(false);
64             Iterator JavaDoc prprts = tmplt_t_b_dsplyd.getProperties(false);
65             Iterator JavaDoc instncs = tmplt_t_b_dsplyd.getInstances(false);
66             Iterator JavaDoc slts = tmplt_t_b_dsplyd.getSlots(false);
67             Iterator JavaDoc plgs = tmplt_t_b_dsplyd.getPlugs(false);
68             
69             int cntr = 0;
70             for (; prts.hasNext(); cntr++) {
71                 Object JavaDoc prt = prts.next();
72                 if (cntr == index) {
73                     return prt;
74                 }
75             }
76             for (; prvdrs.hasNext(); cntr++) {
77                 Object JavaDoc prvdr = prvdrs.next();
78                 if (cntr == index) {
79                     return prvdr;
80                 }
81             }
82             for (; trnsfrmrs.hasNext(); cntr++) {
83                 Object JavaDoc trnsfrmr = trnsfrmrs.next();
84                 if (cntr == index) {
85                     return trnsfrmr;
86                 }
87             }
88             for (; bndgs.hasNext(); cntr++) {
89                 Object JavaDoc bndg = bndgs.next();
90                 if (cntr == index) {
91                     return bndg;
92                 }
93             }
94             for (; trggrs.hasNext(); cntr++) {
95                 Object JavaDoc trggr = trggrs.next();
96                 if (cntr == index) {
97                     return trggr;
98                 }
99             }
100             for (; prprts.hasNext(); cntr++) {
101                 Object JavaDoc prprt = prprts.next();
102                 if (cntr == index) {
103                         return prprt;
104                 }
105             }
106             for (; instncs.hasNext(); cntr++) {
107                 Object JavaDoc instnc = instncs.next();
108                 if (cntr == index) {
109                     return instnc;
110                 }
111             }
112             for (; slts.hasNext(); cntr++) {
113                 Object JavaDoc slt = slts.next();
114                 if (cntr == index) {
115                     return slt;
116                 }
117             }
118             for (; plgs.hasNext(); cntr++) {
119                 Object JavaDoc 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 JavaDoc getChildOfSlot(Slot slt, int index) {
133             Iterator JavaDoc prts = slt.getPorts();
134             int cntr = 0;
135             for (; prts.hasNext(); cntr++) {
136                 Object JavaDoc prt = prts.next();
137                 if (cntr == index) {
138                     return prt;
139                 }
140             }
141             return null;
142     }
143
144     /**
145      * @see javax.swing.tree.TreeModel#getChildCount(Object)
146      */

147     public int getChildCount(Object JavaDoc 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 JavaDoc prts = tmplt_t_b_dsplyd.getPorts(false);
165             Iterator JavaDoc prvdrs = tmplt_t_b_dsplyd.getProviders(false);
166             Iterator JavaDoc trnsfrmrs = tmplt_t_b_dsplyd.getTransformers(false);
167             Iterator JavaDoc bndgs = tmplt_t_b_dsplyd.getBindings(false);
168             Iterator JavaDoc trggrs = tmplt_t_b_dsplyd.getTriggers(false);
169             Iterator JavaDoc prprts = tmplt_t_b_dsplyd.getProperties(false);
170             Iterator JavaDoc instncs = tmplt_t_b_dsplyd.getInstances(false);
171             Iterator JavaDoc slts = tmplt_t_b_dsplyd.getSlots(false);
172             Iterator JavaDoc plgs = tmplt_t_b_dsplyd.getPlugs(false);
173             
174             for (; prts.hasNext(); cntr++) {
175                 Object JavaDoc prt = prts.next();
176             }
177             for (; prvdrs.hasNext(); cntr++) {
178                 Object JavaDoc prvdr = prvdrs.next();
179             }
180             for (; trnsfrmrs.hasNext(); cntr++) {
181                 Object JavaDoc trnsfrmr = trnsfrmrs.next();
182             }
183             for (; bndgs.hasNext(); cntr++) {
184                 Object JavaDoc bndg = bndgs.next();
185             }
186             for (; trggrs.hasNext(); cntr++) {
187                 Object JavaDoc trggr = trggrs.next();
188             }
189             for (; prprts.hasNext(); cntr++) {
190                 Object JavaDoc prprt = prprts.next();
191             }
192             for (; instncs.hasNext(); cntr++) {
193                 Object JavaDoc instnc = instncs.next();
194             }
195             for (; slts.hasNext(); cntr++) {
196                 Object JavaDoc slt = slts.next();
197             }
198             for (; plgs.hasNext(); cntr++) {
199                 Object JavaDoc 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 JavaDoc prts = slt.getPorts();
211             int cntr = 0;
212             for (; prts.hasNext(); cntr++) {
213                 Object JavaDoc prt = prts.next();
214             }
215             return cntr;
216     }
217
218     /**
219      * @see javax.swing.tree.TreeModel#isLeaf(Object)
220      */

221     public boolean isLeaf(Object JavaDoc node) {
222         return (!((node instanceof TemplateDescription) || (node instanceof Instance) || (node instanceof Slot)));
223     }
224
225     /**
226      * @see javax.swing.tree.TreeModel#valueForPathChanged(TreePath, Object)
227      */

228     public void valueForPathChanged(TreePath JavaDoc path, Object JavaDoc newValue) {
229     }
230
231     /**
232      * @see javax.swing.tree.TreeModel#getIndexOfChild(Object, Object)
233      */

234     public int getIndexOfChild(Object JavaDoc parent, Object JavaDoc 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 JavaDoc prts = tmplt_t_b_dsplyd.getPorts(false);
249             Iterator JavaDoc prvdrs = tmplt_t_b_dsplyd.getProviders(false);
250             Iterator JavaDoc trnsfrmrs = tmplt_t_b_dsplyd.getTransformers(false);
251             Iterator JavaDoc bndgs = tmplt_t_b_dsplyd.getBindings(false);
252             Iterator JavaDoc trggrs = tmplt_t_b_dsplyd.getTriggers(false);
253             Iterator JavaDoc prprts = tmplt_t_b_dsplyd.getProperties(false);
254             Iterator JavaDoc instncs = tmplt_t_b_dsplyd.getInstances(false);
255             Iterator JavaDoc slts = tmplt_t_b_dsplyd.getSlots(false);
256             Iterator JavaDoc plgs = tmplt_t_b_dsplyd.getPlugs(false);
257             
258             int cntr = 0;
259             for (; prts.hasNext(); cntr++) {
260                 Object JavaDoc prt = prts.next();
261                 if (prt == child) {
262                     return cntr;
263                 }
264             }
265             for (; prvdrs.hasNext(); cntr++) {
266                 Object JavaDoc prvdr = prvdrs.next();
267                 if (prvdr == child) {
268                     return cntr;
269                 }
270             }
271             for (; trnsfrmrs.hasNext(); cntr++) {
272                 Object JavaDoc trnsfrmr = trnsfrmrs.next();
273                 if (trnsfrmr == child) {
274                     return cntr;
275                 }
276             }
277             for (; bndgs.hasNext(); cntr++) {
278                 Object JavaDoc bndg = bndgs.next();
279                 if (bndg == child) {
280                     return cntr;
281                 }
282             }
283             for (; trggrs.hasNext(); cntr++) {
284                 Object JavaDoc trggr = trggrs.next();
285                 if (trggr == child) {
286                     return cntr;
287                 }
288             }
289             for (; prprts.hasNext(); cntr++) {
290                 Object JavaDoc prprt = prprts.next();
291                 if (prprt == child) {
292                     return cntr;
293                 }
294             }
295             for (; instncs.hasNext(); cntr++) {
296                 Object JavaDoc instnc = instncs.next();
297                 if (instnc == child) {
298                     return cntr;
299                 }
300             }
301             for (; slts.hasNext(); cntr++) {
302                 Object JavaDoc slt = slts.next();
303                 if (slt == child) {
304                     return cntr;
305                 }
306             }
307             for (; plgs.hasNext(); cntr++) {
308                 Object JavaDoc 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 JavaDoc child) {
322             Iterator JavaDoc prts = slot.getPorts();
323             int cntr = 0;
324             for (; prts.hasNext(); cntr++) {
325                 Object JavaDoc prt = prts.next();
326                 if (prt == child) {
327                     return cntr;
328                 }
329             }
330             return -1;
331     }
332
333     /**
334      * @see javax.swing.tree.TreeModel#addTreeModelListener(TreeModelListener)
335      */

336     public void addTreeModelListener(TreeModelListener JavaDoc l) {
337     }
338
339     /**
340      * @see javax.swing.tree.TreeModel#removeTreeModelListener(TreeModelListener)
341      */

342     public void removeTreeModelListener(TreeModelListener JavaDoc l) {
343     }
344
345 }
346
Popular Tags