1 17 package org.eclipse.emf.ecore.provider; 18 19 20 import java.util.Collection ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import org.eclipse.emf.common.notify.AdapterFactory; 25 import org.eclipse.emf.common.notify.Notification; 26 import org.eclipse.emf.common.util.ResourceLocator; 27 import org.eclipse.emf.ecore.EClass; 28 import org.eclipse.emf.ecore.EStructuralFeature; 29 import org.eclipse.emf.ecore.EcoreFactory; 30 import org.eclipse.emf.ecore.EcorePackage; 31 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; 32 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; 33 import org.eclipse.emf.edit.provider.IItemLabelProvider; 34 import org.eclipse.emf.edit.provider.IItemPropertySource; 35 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; 36 import org.eclipse.emf.edit.provider.ITreeItemContentProvider; 37 import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; 38 39 40 import org.eclipse.emf.edit.provider.ViewerNotification; 41 42 48 public class EClassItemProvider 49 extends EClassifierItemProvider 50 implements 51 IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource 52 { 53 59 public EClassItemProvider(AdapterFactory adapterFactory) 60 { 61 super(adapterFactory); 62 } 63 64 70 public List getPropertyDescriptors(Object object) 71 { 72 if (itemPropertyDescriptors == null) 73 { 74 super.getPropertyDescriptors(object); 75 76 addAbstractPropertyDescriptor(object); 77 addInterfacePropertyDescriptor(object); 78 addESuperTypesPropertyDescriptor(object); 79 } 80 return itemPropertyDescriptors; 81 } 82 83 89 protected void addAbstractPropertyDescriptor(Object object) 90 { 91 itemPropertyDescriptors.add 92 (createItemPropertyDescriptor 93 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 94 getResourceLocator(), 95 getString("_UI_EClass_abstract_feature"), 96 getString("_UI_PropertyDescriptor_description", "_UI_EClass_abstract_feature", "_UI_EClass_type"), 97 EcorePackage.eINSTANCE.getEClass_Abstract(), 98 true, 99 ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, 100 null, 101 null)); 102 } 103 104 110 protected void addInterfacePropertyDescriptor(Object object) 111 { 112 itemPropertyDescriptors.add 113 (createItemPropertyDescriptor 114 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 115 getResourceLocator(), 116 getString("_UI_EClass_interface_feature"), 117 getString("_UI_PropertyDescriptor_description", "_UI_EClass_interface_feature", "_UI_EClass_type"), 118 EcorePackage.eINSTANCE.getEClass_Interface(), 119 true, 120 ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, 121 null, 122 null)); 123 } 124 125 131 protected void addESuperTypesPropertyDescriptor(Object object) 132 { 133 itemPropertyDescriptors.add 134 (new ItemPropertyDescriptor 135 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 136 getResourceLocator(), 137 getString("_UI_EClass_eSuperTypes_feature"), 138 getString("_UI_PropertyDescriptor_description", "_UI_EClass_eSuperTypes_feature", "_UI_EClass_type"), 139 EcorePackage.eINSTANCE.getEClass_ESuperTypes(), 140 true) 141 { 142 public Collection getChoiceOfValues(Object object) 143 { 144 EClass eClass = (EClass)object; 145 146 Collection result = super.getChoiceOfValues(object); 149 for (Iterator i = result.iterator(); i.hasNext(); ) 150 { 151 EClass otherEClass = (EClass)i.next(); 152 if (otherEClass == eClass || otherEClass.getEAllSuperTypes().contains(eClass)) 153 { 154 i.remove(); 155 } 156 } 157 return result; 158 } 159 }); 160 } 161 162 170 public Collection getChildrenFeatures(Object object) 171 { 172 if (childrenFeatures == null) 173 { 174 super.getChildrenFeatures(object); 175 childrenFeatures.add(EcorePackage.eINSTANCE.getEClass_EOperations()); 176 childrenFeatures.add(EcorePackage.eINSTANCE.getEClass_EStructuralFeatures()); 177 } 178 return childrenFeatures; 179 } 180 181 186 protected EStructuralFeature getChildFeature(Object object, Object child) 187 { 188 191 return super.getChildFeature(object, child); 192 } 193 194 200 public Object getImage(Object object) 201 { 202 return getResourceLocator().getImage("full/obj16/EClass"); 203 } 204 205 211 public String getText(Object object) 212 { 213 EClass eClass = (EClass)object; 214 StringBuffer result = new StringBuffer (); 215 if (eClass.getName() != null) 216 { 217 result.append(eClass.getName()); 218 } 219 if (!eClass.getESuperTypes().isEmpty()) 220 { 221 result.append(" -> "); 222 for (Iterator i = eClass.getESuperTypes().iterator(); i.hasNext(); ) 223 { 224 EClass eSuperType = (EClass)i.next(); 225 result.append(eSuperType.getName()); 226 if (i.hasNext()) 227 { 228 result.append(", "); 229 } 230 } 231 } 232 if (eClass.getInstanceClassName() != null) 233 { 234 result.append(" <"); 235 result.append(eClass.getInstanceClassName()); 236 result.append(">"); 237 } 238 239 return result.toString(); 240 } 241 242 249 public void notifyChanged(Notification notification) 250 { 251 updateChildren(notification); 252 253 switch (notification.getFeatureID(EClass.class)) 254 { 255 case EcorePackage.ECLASS__ABSTRACT: 256 case EcorePackage.ECLASS__INTERFACE: 257 case EcorePackage.ECLASS__ESUPER_TYPES: 258 case EcorePackage.ECLASS__EREFERENCES: 259 case EcorePackage.ECLASS__EATTRIBUTES: 260 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true)); 261 return; 262 case EcorePackage.ECLASS__EOPERATIONS: 263 case EcorePackage.ECLASS__ESTRUCTURAL_FEATURES: 264 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false)); 265 return; 266 } 267 super.notifyChanged(notification); 268 } 269 270 277 protected void collectNewChildDescriptors(Collection newChildDescriptors, Object object) 278 { 279 super.collectNewChildDescriptors(newChildDescriptors, object); 280 281 newChildDescriptors.add 282 (createChildParameter 283 (EcorePackage.eINSTANCE.getEClass_EOperations(), 284 EcoreFactory.eINSTANCE.createEOperation())); 285 286 newChildDescriptors.add 287 (createChildParameter 288 (EcorePackage.eINSTANCE.getEClass_EStructuralFeatures(), 289 EcoreFactory.eINSTANCE.createEAttribute())); 290 291 newChildDescriptors.add 292 (createChildParameter 293 (EcorePackage.eINSTANCE.getEClass_EStructuralFeatures(), 294 EcoreFactory.eINSTANCE.createEReference())); 295 } 296 297 303 public ResourceLocator getResourceLocator() 304 { 305 return EcoreEditPlugin.INSTANCE; 306 } 307 308 } 309 | Popular Tags |