1 17 package org.eclipse.emf.ecore.change.provider; 18 19 import java.util.ArrayList ; 20 import java.util.Collection ; 21 22 import org.eclipse.emf.common.notify.Adapter; 23 import org.eclipse.emf.common.notify.Notification; 24 import org.eclipse.emf.common.notify.Notifier; 25 import org.eclipse.emf.ecore.change.util.ChangeAdapterFactory; 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 ChangeItemProviderAdapterFactory extends ChangeAdapterFactory 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 ChangeItemProviderAdapterFactory() 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 ChangeDescriptionItemProvider changeDescriptionItemProvider; 95 96 102 public Adapter createChangeDescriptionAdapter() 103 { 104 if (changeDescriptionItemProvider == null) 105 { 106 changeDescriptionItemProvider = new ChangeDescriptionItemProvider(this); 107 } 108 109 return changeDescriptionItemProvider; 110 } 111 112 118 protected EObjectToChangesMapEntryItemProvider eObjectToChangesMapEntryItemProvider; 119 120 126 public Adapter createEObjectToChangesMapEntryAdapter() 127 { 128 if (eObjectToChangesMapEntryItemProvider == null) 129 { 130 eObjectToChangesMapEntryItemProvider = new EObjectToChangesMapEntryItemProvider(this); 131 } 132 133 return eObjectToChangesMapEntryItemProvider; 134 } 135 136 142 protected FeatureChangeItemProvider featureChangeItemProvider; 143 144 150 public Adapter createFeatureChangeAdapter() 151 { 152 if (featureChangeItemProvider == null) 153 { 154 featureChangeItemProvider = new FeatureChangeItemProvider(this); 155 } 156 157 return featureChangeItemProvider; 158 } 159 160 166 protected ListChangeItemProvider listChangeItemProvider; 167 168 174 public Adapter createListChangeAdapter() 175 { 176 if (listChangeItemProvider == null) 177 { 178 listChangeItemProvider = new ListChangeItemProvider(this); 179 } 180 181 return listChangeItemProvider; 182 } 183 184 190 protected ResourceChangeItemProvider resourceChangeItemProvider; 191 192 198 public Adapter createResourceChangeAdapter() 199 { 200 if (resourceChangeItemProvider == null) 201 { 202 resourceChangeItemProvider = new ResourceChangeItemProvider(this); 203 } 204 205 return resourceChangeItemProvider; 206 } 207 208 214 protected FeatureMapEntryItemProvider featureMapEntryItemProvider; 215 216 222 public Adapter createFeatureMapEntryAdapter() 223 { 224 if (featureMapEntryItemProvider == null) 225 { 226 featureMapEntryItemProvider = new FeatureMapEntryItemProvider(this); 227 } 228 229 return featureMapEntryItemProvider; 230 } 231 232 238 public ComposeableAdapterFactory getRootAdapterFactory() 239 { 240 return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory(); 241 } 242 243 249 public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) 250 { 251 this.parentAdapterFactory = parentAdapterFactory; 252 } 253 254 259 public boolean isFactoryForType(Object type) 260 { 261 return supportedTypes.contains(type) || super.isFactoryForType(type); 262 } 263 264 270 public Adapter adapt(Notifier notifier, Object type) 271 { 272 return super.adapt(notifier, this); 273 } 274 275 280 public Object adapt(Object object, Object type) 281 { 282 if (isFactoryForType(type)) 283 { 284 Object adapter = super.adapt(object, type); 285 if (!(type instanceof Class ) || (((Class )type).isInstance(adapter))) 286 { 287 return adapter; 288 } 289 } 290 291 return null; 292 } 293 294 300 public void addListener(INotifyChangedListener notifyChangedListener) 301 { 302 changeNotifier.addListener(notifyChangedListener); 303 } 304 305 311 public void removeListener(INotifyChangedListener notifyChangedListener) 312 { 313 changeNotifier.removeListener(notifyChangedListener); 314 } 315 316 322 public void fireNotifyChanged(Notification notification) 323 { 324 changeNotifier.fireNotifyChanged(notification); 325 326 if (parentAdapterFactory != null) 327 { 328 parentAdapterFactory.fireNotifyChanged(notification); 329 } 330 } 331 332 338 public void dispose() 339 { 340 if (changeDescriptionItemProvider != null) changeDescriptionItemProvider.dispose(); 341 if (eObjectToChangesMapEntryItemProvider != null) eObjectToChangesMapEntryItemProvider.dispose(); 342 if (featureChangeItemProvider != null) featureChangeItemProvider.dispose(); 343 if (listChangeItemProvider != null) listChangeItemProvider.dispose(); 344 if (resourceChangeItemProvider != null) resourceChangeItemProvider.dispose(); 345 if (featureMapEntryItemProvider != null) featureMapEntryItemProvider.dispose(); 346 } 347 348 } 349 | Popular Tags |