intial source from ttp://www.sf.net/projects/wdte
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.js.core / src / net / sourceforge / phpeclipse / js / core / model / JSElementList.java
1 /*
2  * $RCSfile: JSElementList.java,v $
3  *
4  * Copyright 2002
5  * CH-1700 Fribourg, Switzerland
6  * All rights reserved.
7  *
8  *========================================================================
9  * Modifications history
10  *========================================================================
11  * $Log: not supported by cvs2svn $
12  * Revision 1.2  2004/02/27 18:28:10  cell
13  * Make model elements platform objects so they are automatically adapted
14  *
15  * Revision 1.1  2004/02/26 02:25:42  agfitzp
16  * renamed packages to match xml & css
17  *
18  * Revision 1.1  2004/02/05 03:10:08  agfitzp
19  * Initial Submission
20  *
21  * Revision 1.1.2.1  2003/12/12 21:37:24  agfitzp
22  * Experimental work for Classes view
23  *
24  * Revision 1.1  2003/05/30 20:53:08  agfitzp
25  * 0.0.2 : Outlining is now done as the user types. Some other bug fixes.
26  *
27  * Revision 1.1  2003/05/28 15:17:11  agfitzp
28  * net.sourceforge.phpeclipse.js.core 0.0.1 code base
29  *
30  *========================================================================
31 */
32
33 package net.sourceforge.phpeclipse.js.core.model;
34
35 import java.util.ArrayList;
36 import java.util.Iterator;
37 import java.util.List;
38
39 import org.eclipse.core.runtime.IAdaptable;
40 import org.eclipse.core.runtime.PlatformObject;
41
42 /**
43  * DOCUMENT ME!
44  * 
45  * @author Addi 
46  */
47 public class JSElementList extends PlatformObject
48 {
49         protected List children = new ArrayList();
50
51         /**
52          * Creates a new adaptable list with the given children.
53          */
54         public JSElementList()
55         {
56         }
57
58         /**
59          * Creates a new adaptable list with the given children.
60          * @param newChildren
61          */
62         public JSElementList(JSElement[] newChildren)
63         {
64                 for (int i = 0; i < newChildren.length; i++)
65                 {
66                         children.add(newChildren[i]);
67                 }
68         }
69
70         /**
71          * Creates a new adaptable list with the given children.
72          * @param newChildren
73          */
74         public JSElementList(List newChildren)
75         {
76                 for (int i = 0; i < newChildren.size(); i++)
77                 {
78                         children.add(newChildren.get(i));
79                 }
80         }
81
82         /**
83          * Adds all the adaptable objects in the given enumeration to this list. Returns this list.
84          * @param iterator
85          * 
86          * @return
87          */
88         public JSElementList add(Iterator iterator)
89         {
90                 while (iterator.hasNext())
91                 {
92                         add((JSElement) iterator.next());
93                 }
94
95                 return this;
96         }
97
98         /**
99          * Adds the given adaptable object to this list. Returns this list.
100          * @param adaptable
101          * 
102          * @return
103          */
104         public JSElementList add(JSElement anElement)
105         {
106                 children.add(anElement);
107
108                 return this;
109         }
110
111         /**
112          * Returns the elements in this list.
113          * @return
114          */
115         public Object[] getChildren()
116         {
117                 return children.toArray();
118         }
119
120         /**
121          *
122          *
123          * @param o 
124          *
125          * @return 
126          */
127         public Object[] getChildren(Object o)
128         {
129                 return children.toArray();
130         }
131
132         /**
133          *
134          *
135          * @param object 
136          *
137          * @return 
138          */
139         public String getLabel(Object object)
140         {
141                 return object == null ? "" : object.toString();
142         }
143
144         /**
145          *
146          *
147          * @param object 
148          *
149          * @return 
150          */
151         public Object getParent(Object object)
152         {
153                 return null;
154         }
155
156         /**
157          * Removes the given adaptable object from this list.
158          * @param adaptable
159          */
160         public void remove(JSElement anElement)
161         {
162                 children.remove(anElement);
163         }
164
165         /**
166          * Returns the number of items in the list
167          * @return
168          */
169         public int size()
170         {
171                 return children.size();
172         }
173
174         public JSElement findEquivilent(JSElement anElement)
175         {
176                 for(int i = 0; i < size();i++)
177                 {
178                         JSElement aCandidate = (JSElement) children.get(i);
179                         if(anElement.equals(aCandidate))
180                         {
181                                 return aCandidate;
182                         }
183                 }
184                 
185                 
186                 return null;
187         }
188
189         public JSElement get(int index)
190         {
191                 if(index >= size())
192                 {
193                         return null;
194                 }
195                 return (JSElement) children.get(index);
196         }
197
198         /**
199          * @return
200          */
201         public IAdaptable asAdaptable() {
202                 // TODO Auto-generated method stub
203                 return null;
204         }
205 }