1 7 package org.enhydra.dods.editor.Doml.provider; 8 9 import java.util.ArrayList ; 10 import java.util.Collection ; 11 12 import org.eclipse.emf.common.notify.Adapter; 13 import org.eclipse.emf.common.notify.Notification; 14 import org.eclipse.emf.common.notify.Notifier; 15 16 import org.eclipse.emf.edit.provider.ChangeNotifier; 17 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; 18 import org.eclipse.emf.edit.provider.ComposedAdapterFactory; 19 import org.eclipse.emf.edit.provider.IChangeNotifier; 20 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; 21 import org.eclipse.emf.edit.provider.IItemLabelProvider; 22 import org.eclipse.emf.edit.provider.IItemPropertySource; 23 import org.eclipse.emf.edit.provider.INotifyChangedListener; 24 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; 25 import org.eclipse.emf.edit.provider.ITreeItemContentProvider; 26 27 import org.enhydra.dods.editor.Doml.util.DomlAdapterFactory; 28 29 38 public class DomlItemProviderAdapterFactory extends DomlAdapterFactory implements ComposeableAdapterFactory, IChangeNotifier { 39 45 protected ComposedAdapterFactory parentAdapterFactory; 46 47 53 protected IChangeNotifier changeNotifier = new ChangeNotifier(); 54 55 61 protected Collection supportedTypes = new ArrayList (); 62 63 69 public DomlItemProviderAdapterFactory() { 70 supportedTypes.add(IStructuredItemContentProvider.class); 71 supportedTypes.add(ITreeItemContentProvider.class); 72 supportedTypes.add(IItemPropertySource.class); 73 supportedTypes.add(IEditingDomainItemProvider.class); 74 supportedTypes.add(IItemLabelProvider.class); 75 } 76 77 83 protected ColumnTypeItemProvider columnTypeItemProvider; 84 85 91 public Adapter createColumnTypeAdapter() { 92 if (columnTypeItemProvider == null) { 93 columnTypeItemProvider = new ColumnTypeItemProvider(this); 94 } 95 96 return columnTypeItemProvider; 97 } 98 99 105 protected DatabaseTypeItemProvider databaseTypeItemProvider; 106 107 113 public Adapter createDatabaseTypeAdapter() { 114 if (databaseTypeItemProvider == null) { 115 databaseTypeItemProvider = new DatabaseTypeItemProvider(this); 116 } 117 118 return databaseTypeItemProvider; 119 } 120 121 127 protected DocumentRootItemProvider documentRootItemProvider; 128 129 135 public Adapter createDocumentRootAdapter() { 136 if (documentRootItemProvider == null) { 137 documentRootItemProvider = new DocumentRootItemProvider(this); 138 } 139 140 return documentRootItemProvider; 141 } 142 143 149 protected DomlTypeItemProvider domlTypeItemProvider; 150 151 157 public Adapter createDomlTypeAdapter() { 158 if (domlTypeItemProvider == null) { 159 domlTypeItemProvider = new DomlTypeItemProvider(this); 160 } 161 162 return domlTypeItemProvider; 163 } 164 165 171 protected IndexColumnTypeItemProvider indexColumnTypeItemProvider; 172 173 179 public Adapter createIndexColumnTypeAdapter() { 180 if (indexColumnTypeItemProvider == null) { 181 indexColumnTypeItemProvider = new IndexColumnTypeItemProvider(this); 182 } 183 184 return indexColumnTypeItemProvider; 185 } 186 187 193 protected IndexTypeItemProvider indexTypeItemProvider; 194 195 201 public Adapter createIndexTypeAdapter() { 202 if (indexTypeItemProvider == null) { 203 indexTypeItemProvider = new IndexTypeItemProvider(this); 204 } 205 206 return indexTypeItemProvider; 207 } 208 209 215 protected PackageTypeItemProvider packageTypeItemProvider; 216 217 223 public Adapter createPackageTypeAdapter() { 224 if (packageTypeItemProvider == null) { 225 packageTypeItemProvider = new PackageTypeItemProvider(this); 226 } 227 228 return packageTypeItemProvider; 229 } 230 231 237 protected ReferenceObjectTypeItemProvider referenceObjectTypeItemProvider; 238 239 245 public Adapter createReferenceObjectTypeAdapter() { 246 if (referenceObjectTypeItemProvider == null) { 247 referenceObjectTypeItemProvider = new ReferenceObjectTypeItemProvider(this); 248 } 249 250 return referenceObjectTypeItemProvider; 251 } 252 253 259 protected TableTypeItemProvider tableTypeItemProvider; 260 261 267 public Adapter createTableTypeAdapter() { 268 if (tableTypeItemProvider == null) { 269 tableTypeItemProvider = new TableTypeItemProvider(this); 270 } 271 272 return tableTypeItemProvider; 273 } 274 275 281 protected TypeTypeItemProvider typeTypeItemProvider; 282 283 289 public Adapter createTypeTypeAdapter() { 290 if (typeTypeItemProvider == null) { 291 typeTypeItemProvider = new TypeTypeItemProvider(this); 292 } 293 294 return typeTypeItemProvider; 295 } 296 297 303 public ComposeableAdapterFactory getRootAdapterFactory() { 304 return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory(); 305 } 306 307 313 public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) { 314 this.parentAdapterFactory = parentAdapterFactory; 315 } 316 317 322 public boolean isFactoryForType(Object type) { 323 return supportedTypes.contains(type) || super.isFactoryForType(type); 324 } 325 326 332 public Adapter adapt(Notifier notifier, Object type) { 333 return super.adapt(notifier, this); 334 } 335 336 341 public Object adapt(Object object, Object type) { 342 if (isFactoryForType(type)) { 343 Object adapter = super.adapt(object, type); 344 if (!(type instanceof Class ) || (((Class )type).isInstance(adapter))) { 345 return adapter; 346 } 347 } 348 349 return null; 350 } 351 352 358 public void addListener(INotifyChangedListener notifyChangedListener) { 359 changeNotifier.addListener(notifyChangedListener); 360 } 361 362 368 public void removeListener(INotifyChangedListener notifyChangedListener) { 369 changeNotifier.removeListener(notifyChangedListener); 370 } 371 372 378 public void fireNotifyChanged(Notification notification) { 379 changeNotifier.fireNotifyChanged(notification); 380 381 if (parentAdapterFactory != null) { 382 parentAdapterFactory.fireNotifyChanged(notification); 383 } 384 } 385 386 } 387 | Popular Tags |