1 17 package org.eclipse.emf.edit.provider; 18 19 20 import java.util.Collection ; 21 import java.util.List ; 22 23 import org.eclipse.emf.common.command.Command; 24 import org.eclipse.emf.common.notify.AdapterFactory; 25 import org.eclipse.emf.common.notify.Notification; 26 import org.eclipse.emf.edit.command.CommandParameter; 27 import org.eclipse.emf.edit.domain.EditingDomain; 28 29 30 36 public class ItemProviderDecorator 37 implements 38 INotifyChangedListener, 39 IItemProviderDecorator, 40 IChangeNotifier, 41 IDisposable 42 { 43 47 protected AdapterFactory adapterFactory; 48 49 52 protected IChangeNotifier decoratedItemProvider; 53 54 57 protected IChangeNotifier changeNotifier; 58 59 63 public ItemProviderDecorator(AdapterFactory adapterFactory) 64 { 65 this.adapterFactory = adapterFactory; 66 } 67 68 71 public boolean isAdapterForType(Object type) 72 { 73 return type == adapterFactory; 74 } 75 76 79 public AdapterFactory getAdapterFactory() 80 { 81 return adapterFactory; 82 } 83 84 87 public IChangeNotifier getDecoratedItemProvider() 88 { 89 return decoratedItemProvider; 90 } 91 92 96 public void setDecoratedItemProvider(IChangeNotifier decoratedItemProvider) 97 { 98 if (this.decoratedItemProvider != null) 99 { 100 this.decoratedItemProvider.removeListener(this); 101 } 102 103 this.decoratedItemProvider = decoratedItemProvider; 104 105 if (decoratedItemProvider != null) 106 { 107 decoratedItemProvider.addListener(this); 108 } 109 } 110 111 public void addListener(INotifyChangedListener listener) 112 { 113 if (changeNotifier == null) 114 { 115 changeNotifier = new ChangeNotifier(); 116 } 117 changeNotifier.addListener(listener); 118 } 119 120 public void removeListener(INotifyChangedListener listener) 121 { 122 if (changeNotifier != null) 123 { 124 changeNotifier.removeListener(listener); 125 } 126 } 127 128 132 public void fireNotifyChanged(Notification notification) 133 { 134 if (adapterFactory instanceof IChangeNotifier) 135 { 136 IChangeNotifier adapterFactoryChangeNotifier = (IChangeNotifier)adapterFactory; 137 adapterFactoryChangeNotifier.fireNotifyChanged(notification); 138 } 139 if (changeNotifier != null) 140 { 141 changeNotifier.fireNotifyChanged(notification); 142 } 143 } 144 145 149 public List getPropertyDescriptors(Object object) 150 { 151 return ((IItemPropertySource)decoratedItemProvider).getPropertyDescriptors(object); 152 } 153 154 158 public IItemPropertyDescriptor getPropertyDescriptor(Object object, Object propertyId) 159 { 160 return ((IItemPropertySource)decoratedItemProvider).getPropertyDescriptor(object, propertyId); 161 } 162 163 167 public Object getEditableValue(Object object) 168 { 169 return ((IItemPropertySource)decoratedItemProvider).getEditableValue(object); 170 } 171 172 176 public Collection getElements(Object object) 177 { 178 return ((IStructuredItemContentProvider)decoratedItemProvider).getElements(object); 179 } 180 181 185 public Collection getChildren(Object object) 186 { 187 return ((ITreeItemContentProvider)decoratedItemProvider).getChildren(object); 188 } 189 190 194 public boolean hasChildren(Object object) 195 { 196 return ((ITreeItemContentProvider)decoratedItemProvider).hasChildren(object); 197 } 198 199 203 public Object getParent(Object object) 204 { 205 return ((ITreeItemContentProvider)decoratedItemProvider).getParent(object); 206 } 207 208 212 public Object getImage(Object object) 213 { 214 return ((IItemLabelProvider)decoratedItemProvider).getImage(object); 215 } 216 217 221 public Object getColumnImage(Object object, int columnIndex) 222 { 223 return ((ITableItemLabelProvider)decoratedItemProvider).getColumnImage(object, columnIndex); 224 } 225 226 230 public String getText(Object object) 231 { 232 return ((IItemLabelProvider)decoratedItemProvider).getText(object); 233 } 234 235 239 public String getColumnText(Object object, int columnIndex) 240 { 241 return ((ITableItemLabelProvider)decoratedItemProvider).getColumnText(object, columnIndex); 242 } 243 244 248 public String getUpdateableText(Object object) 249 { 250 return ((IUpdateableItemText)decoratedItemProvider).getUpdateableText(object); 251 } 252 253 258 public Collection getNewChildDescriptors(Object object, EditingDomain editingDomain, Object sibling) 259 { 260 return ((IEditingDomainItemProvider)decoratedItemProvider).getNewChildDescriptors(object, editingDomain, sibling); 261 } 262 263 267 public Command createCommand(Object object, EditingDomain domain, Class commandClass, CommandParameter commandParameter) 268 { 269 return ((IEditingDomainItemProvider)decoratedItemProvider).createCommand(object, domain, commandClass, commandParameter); 270 344 } 345 346 412 413 417 public void notifyChanged(Notification notification) 418 { 419 fireNotifyChanged(notification); 420 } 421 422 public void dispose() 423 { 424 if (decoratedItemProvider != null) 425 { 426 decoratedItemProvider.removeListener(this); 427 } 428 } 429 430 public String toString() 431 { 432 return getClass().getName() + '@' + Integer.toHexString(hashCode()); 433 } 434 } 435 | Popular Tags |