1 17 package org.eclipse.emf.edit.provider; 18 19 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 23 import org.eclipse.emf.common.notify.Adapter; 24 import org.eclipse.emf.common.notify.AdapterFactory; 25 import org.eclipse.emf.common.notify.Notification; 26 import org.eclipse.emf.common.notify.Notifier; 27 import org.eclipse.emf.edit.EMFEditPlugin; 28 29 30 34 public abstract class DecoratorAdapterFactory 35 implements 36 AdapterFactory, 37 ComposeableAdapterFactory, 38 IChangeNotifier, 39 IDisposable 40 { 41 protected HashMap itemProviderDecorators = new HashMap (); 42 43 46 protected AdapterFactory decoratedAdapterFactory; 47 48 51 protected ComposedAdapterFactory parentAdapterFactory; 52 53 56 protected ChangeNotifier changeNotifier = new ChangeNotifier(); 57 58 61 public DecoratorAdapterFactory(AdapterFactory decoratedAdapterFactory) 62 { 63 this.decoratedAdapterFactory = decoratedAdapterFactory; 64 } 65 66 69 public boolean isFactoryForType(Object type) 70 { 71 return decoratedAdapterFactory.isFactoryForType(type); 72 } 73 74 77 public AdapterFactory getDecoratedAdapterFactory() 78 { 79 return decoratedAdapterFactory; 80 } 81 82 85 public void setDecoratedAdapterFactory(AdapterFactory decoratedAdapterFactory) 86 { 87 this.decoratedAdapterFactory = decoratedAdapterFactory; 88 } 89 90 93 protected abstract IItemProviderDecorator createItemProviderDecorator(Object target, Object Type); 94 95 100 public Object adapt(Object target, Object type) 101 { 102 Object adapter = decoratedAdapterFactory.adapt(target, type); 103 if (adapter instanceof IChangeNotifier) 104 { 105 IItemProviderDecorator itemProviderDecorator = (IItemProviderDecorator)itemProviderDecorators.get(adapter); 106 if (itemProviderDecorator == null) 107 { 108 itemProviderDecorator = createItemProviderDecorator(target, type); 109 itemProviderDecorators.put(adapter, itemProviderDecorator); 110 itemProviderDecorator.setDecoratedItemProvider((IChangeNotifier)adapter); 111 } 112 113 if (itemProviderDecorator != null) 114 { 115 return itemProviderDecorator; 116 } 117 } 118 119 return adapter; 120 } 121 122 125 public Adapter adapt(Notifier target, Object type) 126 { 127 return (Adapter)adapt((Object )target, type); 128 } 129 130 133 public Adapter adaptNew(Notifier target, Object type) 134 { 135 throw 136 new RuntimeException 137 (EMFEditPlugin.INSTANCE.getString 138 ("_EXC_Method_not_implemented", new Object [] { this.getClass() + "adaptNew(Notifier target, Object type)" })); 139 } 140 141 public void adaptAllNew(Notifier target) 142 { 143 decoratedAdapterFactory.adaptAllNew(target); 144 } 145 146 149 public ComposeableAdapterFactory getRootAdapterFactory() 150 { 151 return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory(); 152 } 153 154 157 public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) 158 { 159 this.parentAdapterFactory = parentAdapterFactory; 160 } 161 162 public void addListener(INotifyChangedListener notifyChangedListener) 163 { 164 changeNotifier.addListener(notifyChangedListener); 165 } 166 167 public void removeListener(INotifyChangedListener notifyChangedListener) 168 { 169 changeNotifier.removeListener(notifyChangedListener); 170 } 171 172 public void fireNotifyChanged(Notification notification) 173 { 174 changeNotifier.fireNotifyChanged(notification); 175 176 if (parentAdapterFactory != null) 177 { 178 parentAdapterFactory.fireNotifyChanged(notification); 179 } 180 } 181 182 public void dispose() 183 { 184 for (Iterator objects = itemProviderDecorators.values().iterator(); objects.hasNext(); ) 185 { 186 Object object = objects.next(); 187 if (object instanceof IDisposable) 188 { 189 ((IDisposable)object).dispose(); 190 } 191 } 192 } 193 } 194 | Popular Tags |