1 17 package org.eclipse.emf.edit.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.common.notify.impl.AdapterFactoryImpl; 27 import org.eclipse.emf.ecore.EObject; 28 29 32 public class ReflectiveItemProviderAdapterFactory 33 extends AdapterFactoryImpl 34 implements ComposeableAdapterFactory, IChangeNotifier, IDisposable 35 { 36 39 protected ComposedAdapterFactory parentAdapterFactory; 40 41 44 protected IChangeNotifier changeNotifier = new ChangeNotifier(); 45 46 49 protected Collection supportedTypes = new ArrayList (); 50 51 54 protected ReflectiveItemProvider reflectiveItemProviderAdapter; 55 56 59 public ReflectiveItemProviderAdapterFactory() 60 { 61 reflectiveItemProviderAdapter = new ReflectiveItemProvider(this); 62 63 supportedTypes.add(IStructuredItemContentProvider.class); 64 supportedTypes.add(ITreeItemContentProvider.class); 65 supportedTypes.add(IItemPropertySource.class); 66 supportedTypes.add(IEditingDomainItemProvider.class); 67 supportedTypes.add(IItemLabelProvider.class); 68 supportedTypes.add(ITableItemLabelProvider.class); 69 } 70 71 public Adapter createAdapter(Notifier target) 72 { 73 return reflectiveItemProviderAdapter; 74 } 75 76 79 public ComposeableAdapterFactory getRootAdapterFactory() 80 { 81 return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory(); 82 } 83 84 87 public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) 88 { 89 this.parentAdapterFactory = parentAdapterFactory; 90 } 91 92 96 public boolean isFactoryForType(Object type) 97 { 98 return type instanceof EObject || supportedTypes.contains(type); 99 } 100 101 104 public Adapter adapt(Notifier notifier, Object type) 105 { 106 return super.adapt(notifier, this); 107 } 108 109 111 public Object adapt(Object object, Object type) 112 { 113 if (isFactoryForType(type)) 114 { 115 Object adapter = super.adapt(object, type); 116 if (!(type instanceof Class ) || (((Class )type).isInstance(adapter))) 117 { 118 return adapter; 119 } 120 } 121 122 return null; 123 } 124 125 128 public void addListener(INotifyChangedListener notifyChangedListener) 129 { 130 changeNotifier.addListener(notifyChangedListener); 131 } 132 133 136 public void removeListener(INotifyChangedListener notifyChangedListener) 137 { 138 changeNotifier.removeListener(notifyChangedListener); 139 } 140 141 144 public void fireNotifyChanged(Notification notification) 145 { 146 changeNotifier.fireNotifyChanged(notification); 147 148 if (parentAdapterFactory != null) 149 { 150 parentAdapterFactory.fireNotifyChanged(notification); 151 } 152 } 153 154 public void dispose() 155 { 156 if (reflectiveItemProviderAdapter != null) 157 { 158 reflectiveItemProviderAdapter.dispose(); 159 } 160 } 161 } 162 | Popular Tags |