KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > edit > tree > impl > TreeNodeImpl


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: TreeNodeImpl.java,v 1.3 2005/06/08 06:17:06 nickb Exp $
16  */

17 package org.eclipse.emf.edit.tree.impl;
18
19
20 import java.util.Collection JavaDoc;
21
22 import org.eclipse.emf.common.notify.Notification;
23 import org.eclipse.emf.common.notify.NotificationChain;
24 import org.eclipse.emf.common.util.EList;
25 import org.eclipse.emf.ecore.EClass;
26 import org.eclipse.emf.ecore.EObject;
27 import org.eclipse.emf.ecore.EStructuralFeature;
28 import org.eclipse.emf.ecore.InternalEObject;
29 import org.eclipse.emf.ecore.impl.ENotificationImpl;
30 import org.eclipse.emf.ecore.impl.EObjectImpl;
31 import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
32 import org.eclipse.emf.ecore.util.EcoreUtil;
33 import org.eclipse.emf.ecore.util.InternalEList;
34 import org.eclipse.emf.edit.tree.TreeNode;
35 import org.eclipse.emf.edit.tree.TreePackage;
36
37
38 /**
39  * <!-- begin-user-doc -->
40  * An implementation of the model object '<em><b>Node</b></em>'.
41  * <!-- end-user-doc -->
42  * <p>
43  * The following features are implemented:
44  * <ul>
45  * <li>{@link org.eclipse.emf.edit.tree.impl.TreeNodeImpl#getParent <em>Parent</em>}</li>
46  * <li>{@link org.eclipse.emf.edit.tree.impl.TreeNodeImpl#getChildren <em>Children</em>}</li>
47  * <li>{@link org.eclipse.emf.edit.tree.impl.TreeNodeImpl#getData <em>Data</em>}</li>
48  * </ul>
49  * </p>
50  *
51  * @generated
52  */

53 public class TreeNodeImpl extends EObjectImpl implements TreeNode
54 {
55   /**
56    * The cached value of the '{@link #getChildren() <em>Children</em>}' containment reference list.
57    * <!-- begin-user-doc -->
58    * <!-- end-user-doc -->
59    * @see #getChildren()
60    * @generated
61    * @ordered
62    */

63   protected EList children = null;
64
65   /**
66    * The cached value of the '{@link #getData() <em>Data</em>}' reference.
67    * <!-- begin-user-doc -->
68    * <!-- end-user-doc -->
69    * @see #getData()
70    * @generated
71    * @ordered
72    */

73   protected EObject data = null;
74
75   /**
76    * <!-- begin-user-doc -->
77    * <!-- end-user-doc -->
78    * @generated modifiable
79    */

80   protected TreeNodeImpl()
81   {
82     super();
83   }
84
85   /**
86    * <!-- begin-user-doc -->
87    * <!-- end-user-doc -->
88    * @generated
89    */

90   protected EClass eStaticClass()
91   {
92     return TreePackage.eINSTANCE.getTreeNode();
93   }
94
95   /**
96    * <!-- begin-user-doc -->
97    * <!-- end-user-doc -->
98    * @generated
99    */

100   public TreeNode getParent()
101   {
102     if (eContainerFeatureID != TreePackage.TREE_NODE__PARENT) return null;
103     return (TreeNode)eContainer;
104   }
105
106   /**
107    * <!-- begin-user-doc -->
108    * <!-- end-user-doc -->
109    * @generated
110    */

111   public void setParent(TreeNode newParent)
112   {
113     if (newParent != eContainer || (eContainerFeatureID != TreePackage.TREE_NODE__PARENT && newParent != null))
114     {
115       if (EcoreUtil.isAncestor(this, newParent))
116         throw new IllegalArgumentException JavaDoc("Recursive containment not allowed for " + toString());
117       NotificationChain msgs = null;
118       if (eContainer != null)
119         msgs = eBasicRemoveFromContainer(msgs);
120       if (newParent != null)
121         msgs = ((InternalEObject)newParent).eInverseAdd(this, TreePackage.TREE_NODE__CHILDREN, TreeNode.class, msgs);
122       msgs = eBasicSetContainer((InternalEObject)newParent, TreePackage.TREE_NODE__PARENT, msgs);
123       if (msgs != null) msgs.dispatch();
124     }
125     else if (eNotificationRequired())
126       eNotify(new ENotificationImpl(this, Notification.SET, TreePackage.TREE_NODE__PARENT, newParent, newParent));
127   }
128
129   /**
130    * <!-- begin-user-doc -->
131    * <!-- end-user-doc -->
132    * @generated
133    */

134   public EList getChildren()
135   {
136     if (children == null)
137     {
138       children = new EObjectContainmentWithInverseEList(TreeNode.class, this, TreePackage.TREE_NODE__CHILDREN, TreePackage.TREE_NODE__PARENT);
139     }
140     return children;
141   }
142
143   /**
144    * <!-- begin-user-doc -->
145    * <!-- end-user-doc -->
146    * @generated
147    */

148   public EObject getData()
149   {
150     if (data != null && data.eIsProxy())
151     {
152       EObject oldData = data;
153       data = (EObject)eResolveProxy((InternalEObject)data);
154       if (data != oldData)
155       {
156         if (eNotificationRequired())
157           eNotify(new ENotificationImpl(this, Notification.RESOLVE, TreePackage.TREE_NODE__DATA, oldData, data));
158       }
159     }
160     return data;
161   }
162
163   /**
164    * <!-- begin-user-doc -->
165    * <!-- end-user-doc -->
166    * @generated
167    */

168   public EObject basicGetData()
169   {
170     return data;
171   }
172
173   /**
174    * <!-- begin-user-doc -->
175    * <!-- end-user-doc -->
176    * @generated
177    */

178   public void setData(EObject newData)
179   {
180     EObject oldData = data;
181     data = newData;
182     if (eNotificationRequired())
183       eNotify(new ENotificationImpl(this, Notification.SET, TreePackage.TREE_NODE__DATA, oldData, data));
184   }
185
186   /**
187    * <!-- begin-user-doc -->
188    * <!-- end-user-doc -->
189    * @generated
190    */

191   public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
192   {
193     if (featureID >= 0)
194     {
195       switch (eDerivedStructuralFeatureID(featureID, baseClass))
196       {
197         case TreePackage.TREE_NODE__PARENT:
198           if (eContainer != null)
199             msgs = eBasicRemoveFromContainer(msgs);
200           return eBasicSetContainer(otherEnd, TreePackage.TREE_NODE__PARENT, msgs);
201         case TreePackage.TREE_NODE__CHILDREN:
202           return ((InternalEList)getChildren()).basicAdd(otherEnd, msgs);
203         default:
204           return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs);
205       }
206     }
207     if (eContainer != null)
208       msgs = eBasicRemoveFromContainer(msgs);
209     return eBasicSetContainer(otherEnd, featureID, msgs);
210   }
211
212   /**
213    * <!-- begin-user-doc -->
214    * <!-- end-user-doc -->
215    * @generated
216    */

217   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
218   {
219     if (featureID >= 0)
220     {
221       switch (eDerivedStructuralFeatureID(featureID, baseClass))
222       {
223         case TreePackage.TREE_NODE__PARENT:
224           return eBasicSetContainer(null, TreePackage.TREE_NODE__PARENT, msgs);
225         case TreePackage.TREE_NODE__CHILDREN:
226           return ((InternalEList)getChildren()).basicRemove(otherEnd, msgs);
227         default:
228           return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs);
229       }
230     }
231     return eBasicSetContainer(null, featureID, msgs);
232   }
233
234   /**
235    * <!-- begin-user-doc -->
236    * <!-- end-user-doc -->
237    * @generated
238    */

239   public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs)
240   {
241     if (eContainerFeatureID >= 0)
242     {
243       switch (eContainerFeatureID)
244       {
245         case TreePackage.TREE_NODE__PARENT:
246           return eContainer.eInverseRemove(this, TreePackage.TREE_NODE__CHILDREN, TreeNode.class, msgs);
247         default:
248           return eDynamicBasicRemoveFromContainer(msgs);
249       }
250     }
251     return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs);
252   }
253
254   /**
255    * <!-- begin-user-doc -->
256    * <!-- end-user-doc -->
257    * @generated
258    */

259   public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
260   {
261     switch (eDerivedStructuralFeatureID(eFeature))
262     {
263       case TreePackage.TREE_NODE__PARENT:
264         return getParent();
265       case TreePackage.TREE_NODE__CHILDREN:
266         return getChildren();
267       case TreePackage.TREE_NODE__DATA:
268         if (resolve) return getData();
269         return basicGetData();
270     }
271     return eDynamicGet(eFeature, resolve);
272   }
273
274   /**
275    * <!-- begin-user-doc -->
276    * <!-- end-user-doc -->
277    * @generated
278    */

279   public boolean eIsSet(EStructuralFeature eFeature)
280   {
281     switch (eDerivedStructuralFeatureID(eFeature))
282     {
283       case TreePackage.TREE_NODE__PARENT:
284         return getParent() != null;
285       case TreePackage.TREE_NODE__CHILDREN:
286         return children != null && !children.isEmpty();
287       case TreePackage.TREE_NODE__DATA:
288         return data != null;
289     }
290     return eDynamicIsSet(eFeature);
291   }
292
293   /**
294    * <!-- begin-user-doc -->
295    * <!-- end-user-doc -->
296    * @generated
297    */

298   public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
299   {
300     switch (eDerivedStructuralFeatureID(eFeature))
301     {
302       case TreePackage.TREE_NODE__PARENT:
303         setParent((TreeNode)newValue);
304         return;
305       case TreePackage.TREE_NODE__CHILDREN:
306         getChildren().clear();
307         getChildren().addAll((Collection JavaDoc)newValue);
308         return;
309       case TreePackage.TREE_NODE__DATA:
310         setData((EObject)newValue);
311         return;
312     }
313     eDynamicSet(eFeature, newValue);
314   }
315
316   /**
317    * <!-- begin-user-doc -->
318    * <!-- end-user-doc -->
319    * @generated
320    */

321   public void eUnset(EStructuralFeature eFeature)
322   {
323     switch (eDerivedStructuralFeatureID(eFeature))
324     {
325       case TreePackage.TREE_NODE__PARENT:
326         setParent((TreeNode)null);
327         return;
328       case TreePackage.TREE_NODE__CHILDREN:
329         getChildren().clear();
330         return;
331       case TreePackage.TREE_NODE__DATA:
332         setData((EObject)null);
333         return;
334     }
335     eDynamicUnset(eFeature);
336   }
337
338 } //TreeNodeImpl
339
Popular Tags