1 17 package org.eclipse.emf.codegen.ecore.genmodel.provider; 18 19 20 import java.util.List ; 21 22 import org.eclipse.emf.codegen.ecore.genmodel.GenFeature; 23 import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage; 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.EAttribute; 28 import org.eclipse.emf.ecore.EStructuralFeature; 29 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; 30 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; 31 import org.eclipse.emf.edit.provider.IItemLabelProvider; 32 import org.eclipse.emf.edit.provider.IItemPropertySource; 33 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; 34 import org.eclipse.emf.edit.provider.ITreeItemContentProvider; 35 import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; 36 37 import org.eclipse.emf.edit.provider.ViewerNotification; 38 39 41 42 48 public class GenFeatureItemProvider 49 extends GenBaseItemProvider 50 implements 51 IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource 52 { 53 59 public GenFeatureItemProvider(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 addPropertyPropertyDescriptor(object); 77 addNotifyPropertyDescriptor(object); 78 addChildrenPropertyDescriptor(object); 79 addCreateChildPropertyDescriptor(object); 80 addPropertyCategoryPropertyDescriptor(object); 81 addPropertyFilterFlagsPropertyDescriptor(object); 82 addPropertyDescriptionPropertyDescriptor(object); 83 addEcoreFeaturePropertyDescriptor(object); 84 } 85 return itemPropertyDescriptors; 86 } 87 88 94 protected void addPropertyPropertyDescriptor(Object object) 95 { 96 itemPropertyDescriptors.add 97 (createItemPropertyDescriptor 98 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 99 getResourceLocator(), 100 getString("_UI_GenFeature_property_feature"), 101 getString("_UI_GenFeature_property_description"), 102 GenModelPackage.eINSTANCE.getGenFeature_Property(), 103 true, 104 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 105 getString("_UI_EditPropertyCategory"), 106 null)); 107 } 108 109 115 protected void addNotifyPropertyDescriptor(Object object) 116 { 117 itemPropertyDescriptors.add 118 (createItemPropertyDescriptor 119 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 120 getResourceLocator(), 121 getString("_UI_GenFeature_notify_feature"), 122 getString("_UI_GenFeature_notify_description"), 123 GenModelPackage.eINSTANCE.getGenFeature_Notify(), 124 true, 125 ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, 126 getString("_UI_EditPropertyCategory"), 127 null)); 128 } 129 130 136 protected void addChildrenPropertyDescriptor(Object object) 137 { 138 itemPropertyDescriptors.add 139 (createItemPropertyDescriptor 140 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 141 getResourceLocator(), 142 getString("_UI_GenFeature_children_feature"), 143 getString("_UI_GenFeature_children_description"), 144 GenModelPackage.eINSTANCE.getGenFeature_Children(), 145 true, 146 ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, 147 getString("_UI_EditPropertyCategory"), 148 null)); 149 } 150 151 157 protected void addCreateChildPropertyDescriptor(Object object) 158 { 159 itemPropertyDescriptors.add 160 (createItemPropertyDescriptor 161 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 162 getResourceLocator(), 163 getString("_UI_GenFeature_createChild_feature"), 164 getString("_UI_GenFeature_createChild_description"), 165 GenModelPackage.eINSTANCE.getGenFeature_CreateChild(), 166 true, 167 ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, 168 getString("_UI_EditPropertyCategory"), 169 null)); 170 } 171 172 178 protected void addPropertyCategoryPropertyDescriptor(Object object) 179 { 180 itemPropertyDescriptors.add 181 (createItemPropertyDescriptor 182 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 183 getResourceLocator(), 184 getString("_UI_GenFeature_propertyCategory_feature"), 185 getString("_UI_GenFeature_propertyCategory_description"), 186 GenModelPackage.eINSTANCE.getGenFeature_PropertyCategory(), 187 true, 188 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 189 getString("_UI_EditPropertyCategory"), 190 null)); 191 } 192 193 199 protected void addPropertyFilterFlagsPropertyDescriptor(Object object) 200 { 201 itemPropertyDescriptors.add 202 (createItemPropertyDescriptor 203 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 204 getResourceLocator(), 205 getString("_UI_GenFeature_propertyFilterFlags_feature"), 206 getString("_UI_GenFeature_propertyFilterFlags_description"), 207 GenModelPackage.eINSTANCE.getGenFeature_PropertyFilterFlags(), 208 true, 209 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 210 getString("_UI_EditPropertyCategory"), 211 null)); 212 } 213 214 220 protected void addPropertyDescriptionPropertyDescriptor(Object object) 221 { 222 itemPropertyDescriptors.add 223 (createItemPropertyDescriptor 224 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 225 getResourceLocator(), 226 getString("_UI_GenFeature_propertyDescription_feature"), 227 getString("_UI_GenFeature_propertyDescription_description"), 228 GenModelPackage.eINSTANCE.getGenFeature_PropertyDescription(), 229 true, 230 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 231 getString("_UI_EditPropertyCategory"), 232 null)); 233 } 234 235 241 protected void addEcoreFeaturePropertyDescriptor(Object object) 242 { 243 itemPropertyDescriptors.add 244 (createItemPropertyDescriptor 245 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 246 getResourceLocator(), 247 getString("_UI_GenFeature_ecoreFeature_feature"), 248 getString("_UI_GenFeature_ecoreFeature_description"), 249 GenModelPackage.eINSTANCE.getGenFeature_EcoreFeature(), 250 false, 251 null, 252 getString("_UI_EcorePropertyCategory"), 253 null)); 254 } 255 256 258 public Object getImage(Object object) 259 { 260 GenFeature genFeature = (GenFeature)object; 261 EStructuralFeature eStructuralFeature = genFeature.getEcoreFeature(); 262 Object image = 263 getResourceLocator().getImage(eStructuralFeature instanceof EAttribute ? "full/obj16/EAttribute" : "full/obj16/EReference"); 264 265 String imageName = "full/obj16/EOccurrence"; 266 int minOccurs = eStructuralFeature.getLowerBound(); 267 int maxOccurs = eStructuralFeature.getUpperBound(); 268 if (minOccurs >= 0 && (minOccurs <= maxOccurs || maxOccurs == -1)) 269 { 270 switch (minOccurs) 271 { 272 case 0: 273 { 274 imageName += "Zero"; 275 break; 276 } 277 case 1: 278 { 279 imageName += "One"; 280 break; 281 } 282 default: 283 { 284 imageName += "N"; 285 break; 286 } 287 } 288 289 if (minOccurs != maxOccurs) 290 { 291 switch (maxOccurs) 292 { 293 case -1: 294 { 295 imageName += "ToUnbounded"; 296 break; 297 } 298 case 0: 299 { 300 break; 301 } 302 case 1: 303 { 304 imageName += "ToOne"; 305 break; 306 } 307 default: 308 { 309 imageName += minOccurs <= 1 ? "ToN" : "ToM"; 310 break; 311 } 312 } 313 } 314 } 315 else 316 { 317 imageName += "NToM"; 318 } 319 320 if (imageName.equals("full/obj16/EOccurrenceZeroToOne")) 321 { 322 return new UnderlayedImage(image); 323 } 324 else 325 { 326 return new UnderlayedImage(image, getResourceLocator().getImage(imageName)); 327 } 328 } 329 330 333 public String getText(Object object) 334 { 335 GenFeature genFeature = (GenFeature)object; 336 EStructuralFeature eStructuralFeature = genFeature.getEcoreFeature(); 337 StringBuffer result = new StringBuffer (); 338 result.append(genFeature.getName()); 339 if (eStructuralFeature.getEType() != null) 340 { 341 result.append(" : "); 342 result.append(eStructuralFeature.getEType().getName()); 343 } 344 return result.toString(); 345 } 346 347 354 public void notifyChanged(Notification notification) 355 { 356 updateChildren(notification); 357 358 switch (notification.getFeatureID(GenFeature.class)) 359 { 360 case GenModelPackage.GEN_FEATURE__PROPERTY: 361 case GenModelPackage.GEN_FEATURE__NOTIFY: 362 case GenModelPackage.GEN_FEATURE__CHILDREN: 363 case GenModelPackage.GEN_FEATURE__CREATE_CHILD: 364 case GenModelPackage.GEN_FEATURE__PROPERTY_CATEGORY: 365 case GenModelPackage.GEN_FEATURE__PROPERTY_FILTER_FLAGS: 366 case GenModelPackage.GEN_FEATURE__PROPERTY_DESCRIPTION: 367 case GenModelPackage.GEN_FEATURE__ECORE_FEATURE: 368 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true)); 369 return; 370 } 371 super.notifyChanged(notification); 372 } 373 374 380 public ResourceLocator getResourceLocator() 381 { 382 return GenModelEditPlugin.INSTANCE; 383 } 384 385 } 386 | Popular Tags |