1 17 package org.eclipse.emf.edit.provider; 18 19 20 import java.util.Collection ; 21 import java.util.Collections ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.eclipse.emf.common.command.Command; 26 import org.eclipse.emf.common.command.UnexecutableCommand; 27 import org.eclipse.emf.common.notify.AdapterFactory; 28 import org.eclipse.emf.common.util.EList; 29 import org.eclipse.emf.edit.command.CommandParameter; 30 import org.eclipse.emf.edit.domain.EditingDomain; 31 32 33 35 public class AdapterFactoryItemDelegator 36 implements 37 IEditingDomainItemProvider, 38 IItemLabelProvider, 39 IItemPropertySource, 40 IStructuredItemContentProvider, 41 ITableItemLabelProvider, 42 ITreeItemContentProvider 43 { 44 47 protected AdapterFactory adapterFactory; 48 49 51 public AdapterFactoryItemDelegator(AdapterFactory adapterFactory) 52 { 53 this.adapterFactory = adapterFactory; 54 } 55 56 public AdapterFactory getAdapterFactory() 57 { 58 return adapterFactory; 59 } 60 61 65 public String getText(Object object) 66 { 67 if (object instanceof EList) 68 { 69 StringBuffer result = new StringBuffer (); 70 for (Iterator i = ((List )object).iterator(); i.hasNext(); ) 71 { 72 Object child = i.next(); 73 if (result.length() != 0) 74 { 75 result.append(", "); 76 } 77 result.append(getText(child)); 78 } 79 return result.toString(); 80 } 81 else 82 { 83 IItemLabelProvider itemLabelProvider = (IItemLabelProvider)adapterFactory.adapt(object, IItemLabelProvider.class); 85 86 return 87 itemLabelProvider != null ? 88 itemLabelProvider.getText(object) : 89 object == null ? 90 "" : 91 object.toString(); 92 } 93 } 94 95 99 public Object getImage(Object object) 100 { 101 if (object instanceof EList) 102 { 103 for (Iterator i = ((List )object).iterator(); i.hasNext(); ) 104 { 105 Object child = i.next(); 106 return getImage(child); 107 } 108 109 return null; 110 } 111 else 112 { 113 IItemLabelProvider itemLabelProvider = (IItemLabelProvider)adapterFactory.adapt(object, IItemLabelProvider.class); 115 116 return 117 itemLabelProvider != null ? 118 itemLabelProvider.getImage(object) : 119 null; 120 } 121 } 122 123 126 public String getColumnText(Object object, int columnIndex) 127 { 128 ITableItemLabelProvider tableItemLabelProvider = (ITableItemLabelProvider)adapterFactory.adapt(object, ITableItemLabelProvider.class); 131 132 if (tableItemLabelProvider != null) 135 { 136 return tableItemLabelProvider.getColumnText(object, columnIndex); 139 } 140 else 143 { 144 IItemLabelProvider itemLabelProvider = (IItemLabelProvider)adapterFactory.adapt(object, IItemLabelProvider.class); 145 if (itemLabelProvider != null) 146 { 147 return itemLabelProvider.getText(object); 150 } 151 else if (object != null) 154 { 155 return object.toString(); 156 } 157 else 158 { 159 return ""; 160 } 161 } 162 } 163 164 167 public Object getColumnImage(Object object, int columnIndex) 168 { 169 ITableItemLabelProvider tableItemLabelProvider = (ITableItemLabelProvider)adapterFactory.adapt(object, ITableItemLabelProvider.class); 172 173 Object result = null; 176 177 if (tableItemLabelProvider != null) 180 { 181 result = tableItemLabelProvider.getColumnImage(object, columnIndex); 184 } 185 else 188 { 189 IItemLabelProvider itemLabelProvider = (IItemLabelProvider)adapterFactory.adapt(object, IItemLabelProvider.class); 190 if (itemLabelProvider != null) 191 { 192 result = itemLabelProvider.getImage(object); 195 } 196 } 197 198 return result; 199 } 200 201 202 public List getPropertyDescriptors(Object object) 203 { 204 IItemPropertySource itemPropertySource = (IItemPropertySource)adapterFactory.adapt(object, IItemPropertySource.class); 206 207 return 208 itemPropertySource != null ? 209 itemPropertySource.getPropertyDescriptors(object) : 210 null; 211 } 212 213 public IItemPropertyDescriptor getPropertyDescriptor(Object object, Object propertyId) 214 { 215 IItemPropertySource itemPropertySource = (IItemPropertySource)adapterFactory.adapt(object, IItemPropertySource.class); 217 218 return 219 itemPropertySource != null ? 220 itemPropertySource.getPropertyDescriptor(object, propertyId) : 221 null; 222 } 223 224 public Object getEditableValue(Object object) 225 { 226 IItemPropertySource itemPropertySource = (IItemPropertySource)adapterFactory.adapt(object, IItemPropertySource.class); 228 229 return 230 itemPropertySource != null ? 231 itemPropertySource.getEditableValue(object) : 232 object; 233 } 234 235 238 public Collection getElements(Object object) 239 { 240 IStructuredItemContentProvider structuredItemContentProvider = 243 (IStructuredItemContentProvider)adapterFactory.adapt(object, IStructuredItemContentProvider.class); 244 245 return 248 structuredItemContentProvider != null ? 249 structuredItemContentProvider.getElements(object) : 250 Collections.EMPTY_LIST; 251 } 252 253 254 257 public Collection getChildren(Object object) 258 { 259 ITreeItemContentProvider treeItemContentProvider = 262 (ITreeItemContentProvider)adapterFactory.adapt(object, ITreeItemContentProvider.class); 263 264 return 267 treeItemContentProvider != null ? 268 treeItemContentProvider.getChildren(object) : 269 Collections.EMPTY_LIST; 270 } 271 272 275 public boolean hasChildren(Object object) 276 { 277 ITreeItemContentProvider treeItemContentProvider = 280 (ITreeItemContentProvider)adapterFactory.adapt(object, ITreeItemContentProvider.class); 281 282 return 285 treeItemContentProvider != null && 286 treeItemContentProvider.hasChildren(object); 287 } 288 289 292 public Object getParent(Object object) 293 { 294 ITreeItemContentProvider treeItemContentProvider = 297 (ITreeItemContentProvider)adapterFactory.adapt(object, ITreeItemContentProvider.class); 298 299 return 302 treeItemContentProvider != null ? 303 treeItemContentProvider.getParent(object) : 304 null; 305 } 306 307 310 312 313 316 318 321 323 328 public Collection getNewChildDescriptors(Object object, EditingDomain editingDomain, Object sibling) 329 { 330 IEditingDomainItemProvider editingDomainItemProvider = 333 (IEditingDomainItemProvider)adapterFactory.adapt(object, IEditingDomainItemProvider.class); 334 335 return 338 editingDomainItemProvider != null ? 339 editingDomainItemProvider.getNewChildDescriptors(object, editingDomain, sibling) : 340 Collections.EMPTY_LIST; 341 } 342 343 347 public Command createCommand(Object object, EditingDomain editingDomain, Class commandClass, CommandParameter commandParameter) 348 { 349 IEditingDomainItemProvider editingDomainItemProvider = 352 (IEditingDomainItemProvider)adapterFactory.adapt(object, IEditingDomainItemProvider.class); 353 354 return 357 editingDomainItemProvider != null ? 358 editingDomainItemProvider.createCommand(object, editingDomain, commandClass, commandParameter) : 359 UnexecutableCommand.INSTANCE; 360 } 361 } 362 | Popular Tags |