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.EClassifier; 28 import org.eclipse.emf.ecore.EOperation; 29 import org.eclipse.emf.ecore.EParameter; 30 import org.eclipse.emf.ecore.EcoreFactory; 31 import org.eclipse.emf.ecore.EcorePackage; 32 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; 33 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; 34 import org.eclipse.emf.edit.provider.IItemLabelProvider; 35 import org.eclipse.emf.edit.provider.IItemPropertySource; 36 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; 37 import org.eclipse.emf.edit.provider.ITreeItemContentProvider; 38 import org.eclipse.emf.edit.provider.ViewerNotification; 39 40 41 47 public class EOperationItemProvider 48 extends ETypedElementItemProvider 49 implements 50 IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource 51 { 52 58 public EOperationItemProvider(AdapterFactory adapterFactory) 59 { 60 super(adapterFactory); 61 } 62 63 69 public List getPropertyDescriptors(Object object) 70 { 71 if (itemPropertyDescriptors == null) 72 { 73 super.getPropertyDescriptors(object); 74 75 addEExceptionsPropertyDescriptor(object); 76 } 77 return itemPropertyDescriptors; 78 } 79 80 86 protected void addEExceptionsPropertyDescriptor(Object object) 87 { 88 itemPropertyDescriptors.add 89 (createItemPropertyDescriptor 90 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 91 getResourceLocator(), 92 getString("_UI_EOperation_eExceptions_feature"), 93 getString("_UI_PropertyDescriptor_description", "_UI_EOperation_eExceptions_feature", "_UI_EOperation_type"), 94 EcorePackage.eINSTANCE.getEOperation_EExceptions(), 95 true, 96 null, 97 null, 98 null)); 99 } 100 101 109 public Collection getChildrenFeatures(Object object) 110 { 111 if (childrenFeatures == null) 112 { 113 super.getChildrenFeatures(object); 114 childrenFeatures.add(EcorePackage.eINSTANCE.getEOperation_EParameters()); 115 } 116 return childrenFeatures; 117 } 118 119 125 public Object getImage(Object object) 126 { 127 return getResourceLocator().getImage("full/obj16/EOperation"); 128 } 129 130 136 public String getText(Object object) 137 { 138 EOperation eOperation = (EOperation)object; 139 StringBuffer result = new StringBuffer (); 140 result.append(eOperation.getName()); 141 result.append("("); for (Iterator i = eOperation.getEParameters().iterator(); i.hasNext(); ) 143 { 144 EParameter eParameter = (EParameter)i.next(); 145 if (eParameter.getEType() != null) 146 { 147 result.append(eParameter.getEType().getName()); 148 if (i.hasNext()) 149 { 150 result.append(", "); 151 } 152 } 153 } 154 result.append(")"); 156 if (eOperation.getEType() != null) 157 { 158 result.append(" : "); 159 result.append(eOperation.getEType().getName()); 160 } 161 162 if (!eOperation.getEExceptions().isEmpty()) 163 { 164 result.append(" throws "); 165 for (Iterator i = eOperation.getEExceptions().iterator(); i.hasNext(); ) 166 { 167 EClassifier eClassifier = (EClassifier)i.next(); 168 result.append(eClassifier.getName()); 169 if (i.hasNext()) 170 { 171 result.append(", "); 172 } 173 } 174 } 175 return result.toString(); 176 } 177 178 185 public void notifyChanged(Notification notification) 186 { 187 updateChildren(notification); 188 189 switch (notification.getFeatureID(EOperation.class)) 190 { 191 case EcorePackage.EOPERATION__EPARAMETERS: 192 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false)); 193 return; 194 } 195 super.notifyChanged(notification); 196 } 197 198 205 protected void collectNewChildDescriptors(Collection newChildDescriptors, Object object) 206 { 207 super.collectNewChildDescriptors(newChildDescriptors, object); 208 209 newChildDescriptors.add 210 (createChildParameter 211 (EcorePackage.eINSTANCE.getEOperation_EParameters(), 212 EcoreFactory.eINSTANCE.createEParameter())); 213 } 214 215 221 public ResourceLocator getResourceLocator() 222 { 223 return EcoreEditPlugin.INSTANCE; 224 } 225 226 } 227 | Popular Tags |