1 17 package org.eclipse.emf.mapping.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.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.Disposable; 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.ITableItemLabelProvider; 38 import org.eclipse.emf.edit.provider.ITreeItemContentProvider; 39 import org.eclipse.emf.mapping.util.MappingAdapterFactory; 40 41 42 46 public class MappingItemProviderAdapterFactory 47 extends 48 MappingAdapterFactory 49 implements 50 ComposeableAdapterFactory, 51 IChangeNotifier, 52 IDisposable 53 { 54 57 protected ComposedAdapterFactory parentAdapterFactory; 58 59 62 protected IChangeNotifier changeNotifier = new ChangeNotifier(); 63 64 67 protected Disposable disposable = new Disposable(); 68 69 72 protected Collection supportedTypes = new ArrayList (); 73 74 77 public MappingItemProviderAdapterFactory() 78 { 79 supportedTypes.add(IStructuredItemContentProvider.class); 80 supportedTypes.add(ITreeItemContentProvider.class); 81 supportedTypes.add(IItemPropertySource.class); 82 supportedTypes.add(IEditingDomainItemProvider.class); 83 supportedTypes.add(IItemLabelProvider.class); 84 supportedTypes.add(ITableItemLabelProvider.class); 85 86 90 } 92 93 96 public ComposeableAdapterFactory getRootAdapterFactory() 97 { 98 return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory(); 99 } 100 101 104 public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) 105 { 106 this.parentAdapterFactory = parentAdapterFactory; 107 } 108 109 public boolean isFactoryForType(Object type) 110 { 111 return super.isFactoryForType(type) || supportedTypes.contains(type); 112 } 113 114 public Adapter adapt(Notifier notifier, Object type) 115 { 116 return super.adapt(notifier, this); 117 } 118 119 public Object adapt(Object object, Object type) 120 { 121 if (isFactoryForType(type)) 122 { 123 Object adapter = super.adapt(object, type); 124 if (!(type instanceof Class ) || (((Class )type).isInstance(adapter))) 125 { 126 return adapter; 127 } 128 } 129 130 return null; 131 } 132 133 public Adapter adaptNew(Notifier object, Object type) 134 { 135 Adapter result = super.adaptNew(object, type); 136 disposable.add(result); 137 return result; 138 } 139 140 143 public void addListener(INotifyChangedListener notifyChangedListener) 144 { 145 changeNotifier.addListener(notifyChangedListener); 146 } 147 148 151 public void removeListener(INotifyChangedListener notifyChangedListener) 152 { 153 changeNotifier.removeListener(notifyChangedListener); 154 } 155 156 159 public void fireNotifyChanged(Notification msg) 160 { 161 changeNotifier.fireNotifyChanged(msg); 162 163 if (parentAdapterFactory != null) 164 { 165 parentAdapterFactory.fireNotifyChanged(msg); 166 } 167 } 168 169 172 protected MappingRootItemProvider mappingRootItemProvider; 173 174 177 public Adapter createMappingRootAdapter() 178 { 179 186 mappingRootItemProvider = new MappingRootItemProvider(this); 187 188 return mappingRootItemProvider; 189 } 190 191 194 protected MappingItemProvider mappingItemProvider; 195 196 199 public Adapter createMappingAdapter() 200 { 201 208 mappingItemProvider = new MappingItemProvider(this); 209 210 return mappingItemProvider; 211 } 212 213 216 protected FunctionPairItemProvider functionPairItemProvider; 217 218 221 public Adapter createFunctionPairAdapter() 222 { 223 { 225 functionPairItemProvider = new FunctionPairItemProvider(this); 226 } 227 228 return functionPairItemProvider; 229 } 230 231 234 protected TypeConverterItemProvider typeConverterItemProvider; 235 236 239 public Adapter createTypeConverterAdapter() 240 { 241 { 243 typeConverterItemProvider = new TypeConverterItemProvider(this); 244 } 245 246 return typeConverterItemProvider; 247 } 248 249 252 protected MappingHelperItemProvider mappingHelperItemProvider; 253 254 257 public Adapter createMappingHelperAdapter() 258 { 259 { 261 mappingHelperItemProvider = new MappingHelperItemProvider(this); 262 } 263 264 return mappingHelperItemProvider; 265 } 266 267 270 protected MappingStrategyItemProvider mappingStrategyItemProvider; 271 272 275 public Adapter createMappingStrategyAdapter() 276 { 277 { 279 mappingStrategyItemProvider = new MappingStrategyItemProvider(this); 280 } 281 282 return mappingStrategyItemProvider; 283 } 284 285 288 protected FunctionNamePairItemProvider functionNamePairItemProvider; 289 290 293 public Adapter createFunctionNamePairAdapter() 294 { 295 { 297 functionNamePairItemProvider = new FunctionNamePairItemProvider(this); 298 } 299 300 return functionNamePairItemProvider; 301 } 302 303 306 protected ComplexTypeConverterItemProvider complexTypeConverterItemProvider; 307 308 311 public Adapter createComplexTypeConverterAdapter() 312 { 313 { 315 complexTypeConverterItemProvider = new ComplexTypeConverterItemProvider(this); 316 } 317 318 return complexTypeConverterItemProvider; 319 } 320 321 public void dispose() 322 { 323 disposable.dispose(); 324 } 325 } 326 | Popular Tags |