1 17 package org.eclipse.emf.ecore.provider; 18 19 20 import java.util.Collection ; 21 import java.util.List ; 22 23 import org.eclipse.emf.common.notify.AdapterFactory; 24 import org.eclipse.emf.common.notify.Notification; 25 import org.eclipse.emf.common.util.ResourceLocator; 26 import org.eclipse.emf.ecore.EAnnotation; 27 import org.eclipse.emf.ecore.EStructuralFeature; 28 import org.eclipse.emf.ecore.EcoreFactory; 29 import org.eclipse.emf.ecore.EcorePackage; 30 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; 31 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; 32 import org.eclipse.emf.edit.provider.IItemLabelProvider; 33 import org.eclipse.emf.edit.provider.IItemPropertySource; 34 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; 35 import org.eclipse.emf.edit.provider.ITreeItemContentProvider; 36 import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; 37 38 import org.eclipse.emf.edit.provider.ViewerNotification; 39 40 46 public class EAnnotationItemProvider 47 extends EModelElementItemProvider 48 implements 49 IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource 50 { 51 57 public EAnnotationItemProvider(AdapterFactory adapterFactory) 58 { 59 super(adapterFactory); 60 } 61 62 68 public List getPropertyDescriptors(Object object) 69 { 70 if (itemPropertyDescriptors == null) 71 { 72 super.getPropertyDescriptors(object); 73 74 addSourcePropertyDescriptor(object); 75 addReferencesPropertyDescriptor(object); 76 } 77 return itemPropertyDescriptors; 78 } 79 80 86 protected void addSourcePropertyDescriptor(Object object) 87 { 88 itemPropertyDescriptors.add 89 (createItemPropertyDescriptor 90 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 91 getResourceLocator(), 92 getString("_UI_EAnnotation_source_feature"), 93 getString("_UI_PropertyDescriptor_description", "_UI_EAnnotation_source_feature", "_UI_EAnnotation_type"), 94 EcorePackage.eINSTANCE.getEAnnotation_Source(), 95 true, 96 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 97 null, 98 null)); 99 } 100 101 107 protected void addReferencesPropertyDescriptor(Object object) 108 { 109 itemPropertyDescriptors.add 110 (createItemPropertyDescriptor 111 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 112 getResourceLocator(), 113 getString("_UI_EAnnotation_references_feature"), 114 getString("_UI_PropertyDescriptor_description", "_UI_EAnnotation_references_feature", "_UI_EAnnotation_type"), 115 EcorePackage.eINSTANCE.getEAnnotation_References(), 116 true, 117 null, 118 null, 119 null)); 120 } 121 122 130 public Collection getChildrenFeatures(Object object) 131 { 132 if (childrenFeatures == null) 133 { 134 super.getChildrenFeatures(object); 135 childrenFeatures.add(EcorePackage.eINSTANCE.getEAnnotation_Details()); 136 childrenFeatures.add(EcorePackage.eINSTANCE.getEAnnotation_Contents()); 137 } 138 return childrenFeatures; 139 } 140 141 146 protected EStructuralFeature getChildFeature(Object object, Object child) 147 { 148 151 return super.getChildFeature(object, child); 152 } 153 154 160 public Object getImage(Object object) 161 { 162 return getResourceLocator().getImage("full/obj16/EAnnotation"); 163 } 164 165 171 public String getText(Object object) 172 { 173 EAnnotation eAnnotation = (EAnnotation)object; 174 StringBuffer result = new StringBuffer (); 175 if (eAnnotation.getSource() != null) 176 { 177 int index = eAnnotation.getSource().lastIndexOf("/"); 178 if (index == -1) 179 { 180 result.append(eAnnotation.getSource()); 181 } 182 else 183 { 184 result.append(eAnnotation.getSource().substring(index + 1)); 185 } 186 } 187 return result.toString(); 188 } 189 190 197 public void notifyChanged(Notification notification) 198 { 199 updateChildren(notification); 200 201 switch (notification.getFeatureID(EAnnotation.class)) 202 { 203 case EcorePackage.EANNOTATION__SOURCE: 204 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true)); 205 return; 206 case EcorePackage.EANNOTATION__DETAILS: 207 case EcorePackage.EANNOTATION__CONTENTS: 208 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false)); 209 return; 210 } 211 super.notifyChanged(notification); 212 } 213 214 221 protected void collectNewChildDescriptors(Collection newChildDescriptors, Object object) 222 { 223 225 newChildDescriptors.add 226 (createChildParameter 227 (EcorePackage.eINSTANCE.getEAnnotation_Details(), 228 EcoreFactory.eINSTANCE.create(EcorePackage.eINSTANCE.getEStringToStringMapEntry()))); 229 } 230 231 237 public ResourceLocator getResourceLocator() 238 { 239 return EcoreEditPlugin.INSTANCE; 240 } 241 242 } 243 | Popular Tags |