1 17 package org.eclipse.emf.edit.tree.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.ecore.EObject; 27 import org.eclipse.emf.edit.provider.ChangeNotifier; 28 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; 29 import org.eclipse.emf.edit.provider.ComposedAdapterFactory; 30 import org.eclipse.emf.edit.provider.Disposable; 31 import org.eclipse.emf.edit.provider.IChangeNotifier; 32 import org.eclipse.emf.edit.provider.IDisposable; 33 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; 34 import org.eclipse.emf.edit.provider.IItemLabelProvider; 35 import org.eclipse.emf.edit.provider.IItemPropertySource; 36 import org.eclipse.emf.edit.provider.INotifyChangedListener; 37 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; 38 import org.eclipse.emf.edit.provider.ITableItemLabelProvider; 39 import org.eclipse.emf.edit.provider.ITreeItemContentProvider; 40 import org.eclipse.emf.edit.tree.util.TreeAdapterFactory; 41 42 43 51 public class TreeItemProviderAdapterFactory 52 extends 53 TreeAdapterFactory 54 implements 55 ComposeableAdapterFactory, 56 IChangeNotifier, 57 IDisposable 58 { 59 62 protected ComposedAdapterFactory parentAdapterFactory; 63 64 67 protected IChangeNotifier changeNotifier = new ChangeNotifier(); 68 69 72 protected Disposable disposable = new Disposable(); 73 74 77 protected Collection supportedTypes = new ArrayList (); 78 79 82 public TreeItemProviderAdapterFactory() 83 { 84 supportedTypes.add(IStructuredItemContentProvider.class); 85 supportedTypes.add(ITreeItemContentProvider.class); 86 supportedTypes.add(IItemPropertySource.class); 87 supportedTypes.add(IEditingDomainItemProvider.class); 88 supportedTypes.add(IItemLabelProvider.class); 89 supportedTypes.add(ITableItemLabelProvider.class); 90 } 91 92 95 public Adapter createTreeNodeAdapter() 96 { 97 return new TreeNodeItemProvider(this); 98 } 99 100 103 public ComposeableAdapterFactory getRootAdapterFactory() 104 { 105 return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory(); 106 } 107 108 111 public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) 112 { 113 this.parentAdapterFactory = parentAdapterFactory; 114 } 115 116 119 public boolean isFactoryForType(Object type) 120 { 121 return super.isFactoryForType(type) || supportedTypes.contains(type); 122 } 123 124 127 public Adapter adapt(Notifier notifier, Object type) 128 { 129 return super.adapt(notifier, this); 130 } 131 132 public Object adapt(Object object, Object type) 133 { 134 if (object instanceof EObject && ((EObject)object).eClass() == null) 137 { 138 return null; 139 } 140 141 if (isFactoryForType(type)) 142 { 143 Object adapter = super.adapt(object, type); 144 if (!(type instanceof Class ) || (((Class )type).isInstance(adapter))) 145 { 146 return adapter; 147 } 148 } 149 150 return null; 151 } 152 153 156 public Adapter adaptNew(Notifier object, Object type) 157 { 158 Adapter result = super.adaptNew(object, type); 159 disposable.add(result); 160 return result; 161 } 162 163 166 public void addListener(INotifyChangedListener notifyChangedListener) 167 { 168 changeNotifier.addListener(notifyChangedListener); 169 } 170 171 174 public void removeListener(INotifyChangedListener notifyChangedListener) 175 { 176 changeNotifier.removeListener(notifyChangedListener); 177 } 178 179 182 public void fireNotifyChanged(Notification notification) 183 { 184 changeNotifier.fireNotifyChanged(notification); 185 186 if (parentAdapterFactory != null) 187 { 188 parentAdapterFactory.fireNotifyChanged(notification); 189 } 190 } 191 192 195 public void dispose() 196 { 197 disposable.dispose(); 198 } 199 } 200 | Popular Tags |