1 17 package org.eclipse.emf.codegen.ecore.genmodel.provider; 18 19 20 import java.util.Collection ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import org.eclipse.emf.codegen.ecore.genmodel.GenClass; 25 import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage; 26 import org.eclipse.emf.common.notify.AdapterFactory; 27 import org.eclipse.emf.common.notify.Notification; 28 import org.eclipse.emf.common.util.ResourceLocator; 29 import org.eclipse.emf.ecore.EStructuralFeature; 30 31 import org.eclipse.emf.ecore.EClass; 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.ItemPropertyDescriptor; 39 40 import org.eclipse.emf.edit.provider.ViewerNotification; 41 42 44 45 51 public class GenClassItemProvider 52 extends GenBaseItemProvider 53 implements 54 IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource 55 { 56 62 public GenClassItemProvider(AdapterFactory adapterFactory) 63 { 64 super(adapterFactory); 65 } 66 67 73 public List getPropertyDescriptors(Object object) 74 { 75 if (itemPropertyDescriptors == null) 76 { 77 super.getPropertyDescriptors(object); 78 79 addProviderPropertyDescriptor(object); 80 addImagePropertyDescriptor(object); 81 addEcoreClassPropertyDescriptor(object); 82 addLabelFeaturePropertyDescriptor(object); 83 } 84 return itemPropertyDescriptors; 85 } 86 87 93 protected void addProviderPropertyDescriptor(Object object) 94 { 95 itemPropertyDescriptors.add 96 (createItemPropertyDescriptor 97 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 98 getResourceLocator(), 99 getString("_UI_GenClass_provider_feature"), 100 getString("_UI_GenClass_provider_description"), 101 GenModelPackage.eINSTANCE.getGenClass_Provider(), 102 true, 103 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 104 getString("_UI_EditPropertyCategory"), 105 null)); 106 } 107 108 114 protected void addImagePropertyDescriptor(Object object) 115 { 116 itemPropertyDescriptors.add 117 (createItemPropertyDescriptor 118 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 119 getResourceLocator(), 120 getString("_UI_GenClass_image_feature"), 121 getString("_UI_GenClass_image_description"), 122 GenModelPackage.eINSTANCE.getGenClass_Image(), 123 true, 124 ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, 125 getString("_UI_EditPropertyCategory"), 126 null)); 127 } 128 129 135 protected void addEcoreClassPropertyDescriptor(Object object) 136 { 137 itemPropertyDescriptors.add 138 (createItemPropertyDescriptor 139 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 140 getResourceLocator(), 141 getString("_UI_GenClass_ecoreClass_feature"), 142 getString("_UI_GenClass_ecoreClass_description"), 143 GenModelPackage.eINSTANCE.getGenClass_EcoreClass(), 144 false, 145 null, 146 getString("_UI_EcorePropertyCategory"), 147 null)); 148 } 149 150 153 protected void addLabelFeaturePropertyDescriptor(Object object) 154 { 155 itemPropertyDescriptors.add 156 (new GenItemPropertyDescriptor 157 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 158 getString("_UI_GenClass_labelFeature_feature"), 159 getString("_UI_GenClass_labelFeature_description"), 160 GenModelPackage.eINSTANCE.getGenClass_LabelFeature(), 161 true, 162 getString("_UI_EditPropertyCategory")) 163 { 164 protected Collection getComboBoxObjects(Object object) 165 { 166 GenClass genClass = (GenClass)object; 167 return genClass.getLabelFeatureCandidates(); 168 } 169 }); 170 } 171 172 180 public Collection getChildrenFeatures(Object object) 181 { 182 if (childrenFeatures == null) 183 { 184 super.getChildrenFeatures(object); 185 childrenFeatures.add(GenModelPackage.eINSTANCE.getGenClass_GenFeatures()); 186 childrenFeatures.add(GenModelPackage.eINSTANCE.getGenClass_GenOperations()); 187 } 188 return childrenFeatures; 189 } 190 191 196 protected EStructuralFeature getChildFeature(Object object, Object child) 197 { 198 201 return super.getChildFeature(object, child); 202 } 203 204 206 public Object getImage(Object object) 207 { 208 return new UnderlayedImage(getResourceLocator().getImage("full/obj16/EClass")); 209 } 210 211 214 public String getText(Object object) 215 { 216 GenClass genClass = (GenClass)object; 217 EClass eClass = genClass.getEcoreClass(); 218 StringBuffer result = new StringBuffer (); 219 if (eClass.getName() != null) 220 { 221 result.append(eClass.getName()); 222 } 223 if (!eClass.getESuperTypes().isEmpty()) 224 { 225 result.append(" -> "); 226 for (Iterator i = eClass.getESuperTypes().iterator(); i.hasNext(); ) 227 { 228 EClass eSuperType = (EClass)i.next(); 229 result.append(eSuperType.getName()); 230 if (i.hasNext()) 231 { 232 result.append(", "); 233 } 234 } 235 } 236 if (eClass.getInstanceClassName() != null) 237 { 238 result.append(" <"); 239 result.append(eClass.getInstanceClassName()); 240 result.append(">"); 241 } 242 243 return result.toString(); 244 } 245 246 253 public void notifyChanged(Notification notification) 254 { 255 updateChildren(notification); 256 257 switch (notification.getFeatureID(GenClass.class)) 258 { 259 case GenModelPackage.GEN_CLASS__GEN_PACKAGE: 260 case GenModelPackage.GEN_CLASS__PROVIDER: 261 case GenModelPackage.GEN_CLASS__IMAGE: 262 case GenModelPackage.GEN_CLASS__ECORE_CLASS: 263 case GenModelPackage.GEN_CLASS__LABEL_FEATURE: 264 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true)); 265 return; 266 case GenModelPackage.GEN_CLASS__GEN_FEATURES: 267 case GenModelPackage.GEN_CLASS__GEN_OPERATIONS: 268 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false)); 269 return; 270 } 271 super.notifyChanged(notification); 272 } 273 274 280 public ResourceLocator getResourceLocator() 281 { 282 return GenModelEditPlugin.INSTANCE; 283 } 284 285 } 286 | Popular Tags |