1 17 package org.eclipse.emf.mapping.ecore2xml.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 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 import org.eclipse.emf.mapping.ecore2xml.util.Ecore2XMLAdapterFactory; 39 40 49 public class Ecore2XMLItemProviderAdapterFactory extends Ecore2XMLAdapterFactory implements ComposeableAdapterFactory, IChangeNotifier, IDisposable 50 { 51 57 protected ComposedAdapterFactory parentAdapterFactory; 58 59 65 protected IChangeNotifier changeNotifier = new ChangeNotifier(); 66 67 73 protected Collection supportedTypes = new ArrayList (); 74 75 81 public Ecore2XMLItemProviderAdapterFactory() 82 { 83 supportedTypes.add(IEditingDomainItemProvider.class); 84 supportedTypes.add(IStructuredItemContentProvider.class); 85 supportedTypes.add(ITreeItemContentProvider.class); 86 supportedTypes.add(IItemLabelProvider.class); 87 supportedTypes.add(IItemPropertySource.class); 88 } 89 90 96 protected XMLInfoItemProvider xmlInfoItemProvider; 97 98 104 public Adapter createXMLInfoAdapter() 105 { 106 if (xmlInfoItemProvider == null) 107 { 108 xmlInfoItemProvider = new XMLInfoItemProvider(this); 109 } 110 111 return xmlInfoItemProvider; 112 } 113 114 120 protected XMLMapItemProvider xmlMapItemProvider; 121 122 128 public Adapter createXMLMapAdapter() 129 { 130 if (xmlMapItemProvider == null) 131 { 132 xmlMapItemProvider = new XMLMapItemProvider(this); 133 } 134 135 return xmlMapItemProvider; 136 } 137 138 144 protected ENamedElementToXMLInfoMapEntryItemProvider eNamedElementToXMLInfoMapEntryItemProvider; 145 146 152 public Adapter createENamedElementToXMLInfoMapEntryAdapter() 153 { 154 if (eNamedElementToXMLInfoMapEntryItemProvider == null) 155 { 156 eNamedElementToXMLInfoMapEntryItemProvider = new ENamedElementToXMLInfoMapEntryItemProvider(this); 157 } 158 159 return eNamedElementToXMLInfoMapEntryItemProvider; 160 } 161 162 168 public ComposeableAdapterFactory getRootAdapterFactory() 169 { 170 return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory(); 171 } 172 173 179 public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) 180 { 181 this.parentAdapterFactory = parentAdapterFactory; 182 } 183 184 189 public boolean isFactoryForType(Object type) 190 { 191 return supportedTypes.contains(type) || super.isFactoryForType(type); 192 } 193 194 200 public Adapter adapt(Notifier notifier, Object type) 201 { 202 return super.adapt(notifier, this); 203 } 204 205 210 public Object adapt(Object object, Object type) 211 { 212 if (isFactoryForType(type)) 213 { 214 Object adapter = super.adapt(object, type); 215 if (!(type instanceof Class ) || (((Class )type).isInstance(adapter))) 216 { 217 return adapter; 218 } 219 } 220 221 return null; 222 } 223 224 230 public void addListener(INotifyChangedListener notifyChangedListener) 231 { 232 changeNotifier.addListener(notifyChangedListener); 233 } 234 235 241 public void removeListener(INotifyChangedListener notifyChangedListener) 242 { 243 changeNotifier.removeListener(notifyChangedListener); 244 } 245 246 252 public void fireNotifyChanged(Notification notification) 253 { 254 changeNotifier.fireNotifyChanged(notification); 255 256 if (parentAdapterFactory != null) 257 { 258 parentAdapterFactory.fireNotifyChanged(notification); 259 } 260 } 261 262 268 public void dispose() 269 { 270 if (xmlInfoItemProvider != null) xmlInfoItemProvider.dispose(); 271 if (xmlMapItemProvider != null) xmlMapItemProvider.dispose(); 272 if (eNamedElementToXMLInfoMapEntryItemProvider != null) eNamedElementToXMLInfoMapEntryItemProvider.dispose(); 273 } 274 275 } 276 | Popular Tags |