1 17 package org.eclipse.emf.ecore.provider; 18 19 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 23 import org.eclipse.emf.common.notify.Adapter; 24 import org.eclipse.emf.common.notify.Notification; 25 import org.eclipse.emf.common.notify.Notifier; 26 import org.eclipse.emf.ecore.util.EcoreAdapterFactory; 27 import org.eclipse.emf.edit.provider.ChangeNotifier; 28 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; 29 import org.eclipse.emf.edit.provider.ComposedAdapterFactory; 30 import org.eclipse.emf.edit.provider.IChangeNotifier; 31 import org.eclipse.emf.edit.provider.IDisposable; 32 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; 33 import org.eclipse.emf.edit.provider.IItemLabelProvider; 34 import org.eclipse.emf.edit.provider.IItemPropertySource; 35 import org.eclipse.emf.edit.provider.INotifyChangedListener; 36 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; 37 import org.eclipse.emf.edit.provider.ITreeItemContentProvider; 38 import org.eclipse.emf.edit.provider.ReflectiveItemProvider; 39 40 41 50 public class EcoreItemProviderAdapterFactory extends EcoreAdapterFactory implements ComposeableAdapterFactory, IChangeNotifier, IDisposable 51 { 52 58 protected ComposedAdapterFactory parentAdapterFactory; 59 60 66 protected IChangeNotifier changeNotifier = new ChangeNotifier(); 67 68 74 protected Collection supportedTypes = new ArrayList (); 75 76 82 public EcoreItemProviderAdapterFactory() 83 { 84 supportedTypes.add(IEditingDomainItemProvider.class); 85 supportedTypes.add(IStructuredItemContentProvider.class); 86 supportedTypes.add(ITreeItemContentProvider.class); 87 supportedTypes.add(IItemLabelProvider.class); 88 supportedTypes.add(IItemPropertySource.class); 89 } 90 91 97 protected EAttributeItemProvider eAttributeItemProvider; 98 99 105 public Adapter createEAttributeAdapter() 106 { 107 if (eAttributeItemProvider == null) 108 { 109 eAttributeItemProvider = new EAttributeItemProvider(this); 110 } 111 112 return eAttributeItemProvider; 113 } 114 115 121 protected EAnnotationItemProvider eAnnotationItemProvider; 122 123 129 public Adapter createEAnnotationAdapter() 130 { 131 if (eAnnotationItemProvider == null) 132 { 133 eAnnotationItemProvider = new EAnnotationItemProvider(this); 134 } 135 136 return eAnnotationItemProvider; 137 } 138 139 145 protected EClassItemProvider eClassItemProvider; 146 147 153 public Adapter createEClassAdapter() 154 { 155 if (eClassItemProvider == null) 156 { 157 eClassItemProvider = new EClassItemProvider(this); 158 } 159 160 return eClassItemProvider; 161 } 162 163 169 protected EDataTypeItemProvider eDataTypeItemProvider; 170 171 177 public Adapter createEDataTypeAdapter() 178 { 179 if (eDataTypeItemProvider == null) 180 { 181 eDataTypeItemProvider = new EDataTypeItemProvider(this); 182 } 183 184 return eDataTypeItemProvider; 185 } 186 187 193 protected EEnumItemProvider eEnumItemProvider; 194 195 201 public Adapter createEEnumAdapter() 202 { 203 if (eEnumItemProvider == null) 204 { 205 eEnumItemProvider = new EEnumItemProvider(this); 206 } 207 208 return eEnumItemProvider; 209 } 210 211 217 protected EEnumLiteralItemProvider eEnumLiteralItemProvider; 218 219 225 public Adapter createEEnumLiteralAdapter() 226 { 227 if (eEnumLiteralItemProvider == null) 228 { 229 eEnumLiteralItemProvider = new EEnumLiteralItemProvider(this); 230 } 231 232 return eEnumLiteralItemProvider; 233 } 234 235 241 protected EFactoryItemProvider eFactoryItemProvider; 242 243 249 public Adapter createEFactoryAdapter() 250 { 251 if (eFactoryItemProvider == null) 252 { 253 eFactoryItemProvider = new EFactoryItemProvider(this); 254 } 255 256 return eFactoryItemProvider; 257 } 258 259 265 protected ReflectiveItemProvider eObjectItemProvider; 266 267 273 public Adapter createEObjectAdapter() 274 { 275 if (eObjectItemProvider == null) 276 { 277 eObjectItemProvider = new ReflectiveItemProvider(this); 278 } 279 280 return eObjectItemProvider; 281 } 282 283 289 protected EOperationItemProvider eOperationItemProvider; 290 291 297 public Adapter createEOperationAdapter() 298 { 299 if (eOperationItemProvider == null) 300 { 301 eOperationItemProvider = new EOperationItemProvider(this); 302 } 303 304 return eOperationItemProvider; 305 } 306 307 313 protected EPackageItemProvider ePackageItemProvider; 314 315 321 public Adapter createEPackageAdapter() 322 { 323 if (ePackageItemProvider == null) 324 { 325 ePackageItemProvider = new EPackageItemProvider(this); 326 } 327 328 return ePackageItemProvider; 329 } 330 331 337 protected EParameterItemProvider eParameterItemProvider; 338 339 345 public Adapter createEParameterAdapter() 346 { 347 if (eParameterItemProvider == null) 348 { 349 eParameterItemProvider = new EParameterItemProvider(this); 350 } 351 352 return eParameterItemProvider; 353 } 354 355 361 protected EReferenceItemProvider eReferenceItemProvider; 362 363 369 public Adapter createEReferenceAdapter() 370 { 371 if (eReferenceItemProvider == null) 372 { 373 eReferenceItemProvider = new EReferenceItemProvider(this); 374 } 375 376 return eReferenceItemProvider; 377 } 378 379 385 protected EStringToStringMapEntryItemProvider eStringToStringMapEntryItemProvider; 386 387 393 public Adapter createEStringToStringMapEntryAdapter() 394 { 395 if (eStringToStringMapEntryItemProvider == null) 396 { 397 eStringToStringMapEntryItemProvider = new EStringToStringMapEntryItemProvider(this); 398 } 399 400 return eStringToStringMapEntryItemProvider; 401 } 402 403 409 public ComposeableAdapterFactory getRootAdapterFactory() 410 { 411 return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory(); 412 } 413 414 420 public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) 421 { 422 this.parentAdapterFactory = parentAdapterFactory; 423 } 424 425 430 public boolean isFactoryForType(Object type) 431 { 432 return supportedTypes.contains(type) || super.isFactoryForType(type); 433 } 434 435 441 public Adapter adapt(Notifier notifier, Object type) 442 { 443 return super.adapt(notifier, this); 444 } 445 446 451 public Object adapt(Object object, Object type) 452 { 453 if (isFactoryForType(type)) 454 { 455 Object adapter = super.adapt(object, type); 456 if (!(type instanceof Class ) || (((Class )type).isInstance(adapter))) 457 { 458 return adapter; 459 } 460 } 461 462 return null; 463 } 464 465 471 public void addListener(INotifyChangedListener notifyChangedListener) 472 { 473 changeNotifier.addListener(notifyChangedListener); 474 } 475 476 482 public void removeListener(INotifyChangedListener notifyChangedListener) 483 { 484 changeNotifier.removeListener(notifyChangedListener); 485 } 486 487 493 public void fireNotifyChanged(Notification notification) 494 { 495 changeNotifier.fireNotifyChanged(notification); 496 497 if (parentAdapterFactory != null) 498 { 499 parentAdapterFactory.fireNotifyChanged(notification); 500 } 501 } 502 503 509 public void dispose() 510 { 511 if (eAttributeItemProvider != null) eAttributeItemProvider.dispose(); 512 if (eAnnotationItemProvider != null) eAnnotationItemProvider.dispose(); 513 if (eClassItemProvider != null) eClassItemProvider.dispose(); 514 if (eDataTypeItemProvider != null) eDataTypeItemProvider.dispose(); 515 if (eEnumItemProvider != null) eEnumItemProvider.dispose(); 516 if (eEnumLiteralItemProvider != null) eEnumLiteralItemProvider.dispose(); 517 if (eFactoryItemProvider != null) eFactoryItemProvider.dispose(); 518 if (eObjectItemProvider != null) eObjectItemProvider.dispose(); 519 if (eOperationItemProvider != null) eOperationItemProvider.dispose(); 520 if (ePackageItemProvider != null) ePackageItemProvider.dispose(); 521 if (eParameterItemProvider != null) eParameterItemProvider.dispose(); 522 if (eReferenceItemProvider != null) eReferenceItemProvider.dispose(); 523 if (eStringToStringMapEntryItemProvider != null) eStringToStringMapEntryItemProvider.dispose(); 524 } 525 526 } 527 | Popular Tags |