1 17 package org.eclipse.emf.edit.tree.impl; 18 19 20 import java.util.Collection ; 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 53 public class TreeNodeImpl extends EObjectImpl implements TreeNode 54 { 55 63 protected EList children = null; 64 65 73 protected EObject data = null; 74 75 80 protected TreeNodeImpl() 81 { 82 super(); 83 } 84 85 90 protected EClass eStaticClass() 91 { 92 return TreePackage.eINSTANCE.getTreeNode(); 93 } 94 95 100 public TreeNode getParent() 101 { 102 if (eContainerFeatureID != TreePackage.TREE_NODE__PARENT) return null; 103 return (TreeNode)eContainer; 104 } 105 106 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 ("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 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 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 168 public EObject basicGetData() 169 { 170 return data; 171 } 172 173 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 191 public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class 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 217 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class 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 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 259 public Object 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 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 298 public void eSet(EStructuralFeature eFeature, Object 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 )newValue); 308 return; 309 case TreePackage.TREE_NODE__DATA: 310 setData((EObject)newValue); 311 return; 312 } 313 eDynamicSet(eFeature, newValue); 314 } 315 316 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 } | Popular Tags |