KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.objectweb.kilim.tools;
2
3 import java.util.Iterator JavaDoc;
4 import javax.swing.event.TreeModelListener JavaDoc;
5 import javax.swing.tree.TreeModel JavaDoc;
6 import javax.swing.tree.TreePath JavaDoc;
7
8 import org.objectweb.kilim.model.Component;
9 import org.objectweb.kilim.model.ComponentSlot;
10
11 /**
12  * @author delpiano
13  *
14  * To change this generated comment edit the template variable "typecomment":
15  * Window>Preferences>Java>Templates.
16  * To enable and disable the creation of type comments go to
17  * Window>Preferences>Java>Code Generation.
18  */

19 public class KilimComponentTreeModel implements TreeModel JavaDoc {
20
21     private Component component;
22
23     /**
24      * Method KilimComponentTreeModel.
25      * @param cmpnnt :
26      */

27     public KilimComponentTreeModel(Component cmpnnt) {
28         super();
29         component = cmpnnt;
30     }
31
32     /**
33      * @see javax.swing.tree.TreeModel#getRoot()
34      */

35     public Object JavaDoc getRoot() {
36         return component;
37     }
38
39     /**
40      * @see javax.swing.tree.TreeModel#getChild(Object, int)
41      */

42     public Object JavaDoc getChild(Object JavaDoc parent, int index) {
43         
44         if (parent instanceof Component) {
45
46             Component cmpnnt = (Component) parent;
47             Iterator JavaDoc intfcs = cmpnnt.getInterfaces();
48             Iterator JavaDoc sbcmpnnts = cmpnnt.getSubComponents();
49             Iterator JavaDoc slts = cmpnnt.getSlots();
50             int crt_indx = 0;
51             for (; intfcs.hasNext(); crt_indx++) {
52                 Object JavaDoc nxt = intfcs.next();
53                 if (crt_indx == index) {
54                     return nxt;
55                 }
56             }
57             for (; sbcmpnnts.hasNext(); crt_indx++) {
58                 Object JavaDoc nxt = sbcmpnnts.next();
59                 if (crt_indx == index) {
60                     return nxt;
61                 }
62             }
63             for (; slts.hasNext(); crt_indx++) {
64                 Object JavaDoc 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 JavaDoc plgs = slt.getPlugIns();
75             for (; plgs.hasNext(); crt_indx++) {
76                 Object JavaDoc nxt = plgs.next();
77                 if (crt_indx == index) {
78                     return nxt;
79                 }
80             }
81             
82         }
83         
84         return null;
85     }
86
87     /**
88      * @see javax.swing.tree.TreeModel#getChildCount(Object)
89      */

90     public int getChildCount(Object JavaDoc parent) {
91         
92         if (parent instanceof Component) {
93
94             Component cmpnnt = (Component) parent;
95             Iterator JavaDoc intfcs = cmpnnt.getInterfaces();
96             Iterator JavaDoc sbcmpnnts = cmpnnt.getSubComponents();
97             Iterator JavaDoc 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 JavaDoc 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     /**
125      * @see javax.swing.tree.TreeModel#isLeaf(Object)
126      */

127     public boolean isLeaf(Object JavaDoc node) {
128         return (getChildCount(node) == 0);
129     }
130
131     /**
132      * @see javax.swing.tree.TreeModel#valueForPathChanged(TreePath, Object)
133      */

134     public void valueForPathChanged(TreePath JavaDoc path, Object JavaDoc newValue) {
135     }
136
137     /**
138      * @see javax.swing.tree.TreeModel#getIndexOfChild(Object, Object)
139      */

140     public int getIndexOfChild(Object JavaDoc parent, Object JavaDoc child) {
141         if (parent instanceof Component) {
142
143             Component cmpnnt = (Component) parent;
144             Iterator JavaDoc intfcs = cmpnnt.getInterfaces();
145             Iterator JavaDoc sbcmpnnts = cmpnnt.getSubComponents();
146             Iterator JavaDoc slts = cmpnnt.getSlots();
147             int crt_indx = 0;
148             for (; intfcs.hasNext(); crt_indx++) {
149                 Object JavaDoc nxt = intfcs.next();
150                 if (nxt == child) {
151                     return crt_indx;
152                 }
153             }
154             for (; sbcmpnnts.hasNext(); crt_indx++) {
155                 Object JavaDoc nxt = sbcmpnnts.next();
156                 if (nxt == child) {
157                     return crt_indx;
158                 }
159             }
160             for (; slts.hasNext(); crt_indx++) {
161                 Object JavaDoc 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 JavaDoc plgs = slt.getPlugIns();
172             int crt_indx = 0;
173             for (; plgs.hasNext(); crt_indx++) {
174                 Object JavaDoc nxt = plgs.next();
175                 if (nxt == child) {
176                     return crt_indx;
177                 }
178             }
179         }
180         return -1;
181     }
182
183     /**
184      * @see javax.swing.tree.TreeModel#addTreeModelListener(TreeModelListener)
185      */

186     public void addTreeModelListener(TreeModelListener JavaDoc l) {
187     }
188
189     /**
190      * @see javax.swing.tree.TreeModel#removeTreeModelListener(TreeModelListener)
191      */

192     public void removeTreeModelListener(TreeModelListener JavaDoc l) {
193     }
194
195 }
196
Popular Tags