1 17 package org.eclipse.emf.codegen.ecore.genmodel.provider; 18 19 import java.util.ArrayList ; 20 import java.util.Collection ; 21 22 import org.eclipse.emf.codegen.ecore.genmodel.util.GenModelAdapterFactory; 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.edit.provider.ChangeNotifier; 27 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; 28 import org.eclipse.emf.edit.provider.ComposedAdapterFactory; 29 import org.eclipse.emf.edit.provider.IChangeNotifier; 30 import org.eclipse.emf.edit.provider.IDisposable; 31 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; 32 import org.eclipse.emf.edit.provider.IItemLabelProvider; 33 import org.eclipse.emf.edit.provider.IItemPropertySource; 34 import org.eclipse.emf.edit.provider.INotifyChangedListener; 35 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; 36 import org.eclipse.emf.edit.provider.ITreeItemContentProvider; 37 38 47 public class GenModelItemProviderAdapterFactory extends GenModelAdapterFactory implements ComposeableAdapterFactory, IChangeNotifier, IDisposable 48 { 49 55 protected ComposedAdapterFactory parentAdapterFactory; 56 57 63 protected IChangeNotifier changeNotifier = new ChangeNotifier(); 64 65 71 protected Collection supportedTypes = new ArrayList (); 72 73 79 public GenModelItemProviderAdapterFactory() 80 { 81 supportedTypes.add(IEditingDomainItemProvider.class); 82 supportedTypes.add(IStructuredItemContentProvider.class); 83 supportedTypes.add(ITreeItemContentProvider.class); 84 supportedTypes.add(IItemLabelProvider.class); 85 supportedTypes.add(IItemPropertySource.class); 86 } 87 88 94 protected GenModelItemProvider genModelItemProvider; 95 96 102 public Adapter createGenModelAdapter() 103 { 104 if (genModelItemProvider == null) 105 { 106 genModelItemProvider = new GenModelItemProvider(this); 107 } 108 109 return genModelItemProvider; 110 } 111 112 118 protected GenPackageItemProvider genPackageItemProvider; 119 120 126 public Adapter createGenPackageAdapter() 127 { 128 if (genPackageItemProvider == null) 129 { 130 genPackageItemProvider = new GenPackageItemProvider(this); 131 } 132 133 return genPackageItemProvider; 134 } 135 136 142 protected GenClassItemProvider genClassItemProvider; 143 144 150 public Adapter createGenClassAdapter() 151 { 152 if (genClassItemProvider == null) 153 { 154 genClassItemProvider = new GenClassItemProvider(this); 155 } 156 157 return genClassItemProvider; 158 } 159 160 166 protected GenFeatureItemProvider genFeatureItemProvider; 167 168 174 public Adapter createGenFeatureAdapter() 175 { 176 if (genFeatureItemProvider == null) 177 { 178 genFeatureItemProvider = new GenFeatureItemProvider(this); 179 } 180 181 return genFeatureItemProvider; 182 } 183 184 190 protected GenEnumItemProvider genEnumItemProvider; 191 192 198 public Adapter createGenEnumAdapter() 199 { 200 if (genEnumItemProvider == null) 201 { 202 genEnumItemProvider = new GenEnumItemProvider(this); 203 } 204 205 return genEnumItemProvider; 206 } 207 208 214 protected GenEnumLiteralItemProvider genEnumLiteralItemProvider; 215 216 222 public Adapter createGenEnumLiteralAdapter() 223 { 224 if (genEnumLiteralItemProvider == null) 225 { 226 genEnumLiteralItemProvider = new GenEnumLiteralItemProvider(this); 227 } 228 229 return genEnumLiteralItemProvider; 230 } 231 232 238 protected GenDataTypeItemProvider genDataTypeItemProvider; 239 240 246 public Adapter createGenDataTypeAdapter() 247 { 248 if (genDataTypeItemProvider == null) 249 { 250 genDataTypeItemProvider = new GenDataTypeItemProvider(this); 251 } 252 253 return genDataTypeItemProvider; 254 } 255 256 262 protected GenOperationItemProvider genOperationItemProvider; 263 264 270 public Adapter createGenOperationAdapter() 271 { 272 if (genOperationItemProvider == null) 273 { 274 genOperationItemProvider = new GenOperationItemProvider(this); 275 } 276 277 return genOperationItemProvider; 278 } 279 280 286 public ComposeableAdapterFactory getRootAdapterFactory() 287 { 288 return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory(); 289 } 290 291 297 public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) 298 { 299 this.parentAdapterFactory = parentAdapterFactory; 300 } 301 302 307 public boolean isFactoryForType(Object type) 308 { 309 return supportedTypes.contains(type) || super.isFactoryForType(type); 310 } 311 312 318 public Adapter adapt(Notifier notifier, Object type) 319 { 320 return super.adapt(notifier, this); 321 } 322 323 328 public Object adapt(Object object, Object type) 329 { 330 if (isFactoryForType(type)) 331 { 332 Object adapter = super.adapt(object, type); 333 if (!(type instanceof Class ) || (((Class )type).isInstance(adapter))) 334 { 335 return adapter; 336 } 337 } 338 339 return null; 340 } 341 342 348 public void addListener(INotifyChangedListener notifyChangedListener) 349 { 350 changeNotifier.addListener(notifyChangedListener); 351 } 352 353 359 public void removeListener(INotifyChangedListener notifyChangedListener) 360 { 361 changeNotifier.removeListener(notifyChangedListener); 362 } 363 364 370 public void fireNotifyChanged(Notification notification) 371 { 372 changeNotifier.fireNotifyChanged(notification); 373 374 if (parentAdapterFactory != null) 375 { 376 parentAdapterFactory.fireNotifyChanged(notification); 377 } 378 } 379 380 386 public void dispose() 387 { 388 if (genModelItemProvider != null) genModelItemProvider.dispose(); 389 if (genPackageItemProvider != null) genPackageItemProvider.dispose(); 390 if (genClassItemProvider != null) genClassItemProvider.dispose(); 391 if (genFeatureItemProvider != null) genFeatureItemProvider.dispose(); 392 if (genEnumItemProvider != null) genEnumItemProvider.dispose(); 393 if (genEnumLiteralItemProvider != null) genEnumLiteralItemProvider.dispose(); 394 if (genDataTypeItemProvider != null) genDataTypeItemProvider.dispose(); 395 if (genOperationItemProvider != null) genOperationItemProvider.dispose(); 396 } 397 398 } 399 | Popular Tags |