1 17 package org.eclipse.emf.ecore.provider; 18 19 20 import java.util.ArrayList ; 21 import java.util.Collection ; 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.EStructuralFeature; 28 import org.eclipse.emf.ecore.EcorePackage; 29 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; 30 import org.eclipse.emf.edit.provider.ComposedImage; 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 39 import org.eclipse.emf.edit.provider.ViewerNotification; 40 41 47 public class EStructuralFeatureItemProvider 48 extends ETypedElementItemProvider 49 implements 50 IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource 51 { 52 58 public EStructuralFeatureItemProvider(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 addChangeablePropertyDescriptor(object); 76 addVolatilePropertyDescriptor(object); 77 addTransientPropertyDescriptor(object); 78 addDefaultValueLiteralPropertyDescriptor(object); 79 addDefaultValuePropertyDescriptor(object); 80 addUnsettablePropertyDescriptor(object); 81 addDerivedPropertyDescriptor(object); 82 addEContainingClassPropertyDescriptor(object); 83 } 84 return itemPropertyDescriptors; 85 } 86 87 93 protected void addChangeablePropertyDescriptor(Object object) 94 { 95 itemPropertyDescriptors.add 96 (createItemPropertyDescriptor 97 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 98 getResourceLocator(), 99 getString("_UI_EStructuralFeature_changeable_feature"), 100 getString("_UI_PropertyDescriptor_description", "_UI_EStructuralFeature_changeable_feature", "_UI_EStructuralFeature_type"), 101 EcorePackage.eINSTANCE.getEStructuralFeature_Changeable(), 102 true, 103 ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, 104 null, 105 null)); 106 } 107 108 114 protected void addVolatilePropertyDescriptor(Object object) 115 { 116 itemPropertyDescriptors.add 117 (createItemPropertyDescriptor 118 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 119 getResourceLocator(), 120 getString("_UI_EStructuralFeature_volatile_feature"), 121 getString("_UI_PropertyDescriptor_description", "_UI_EStructuralFeature_volatile_feature", "_UI_EStructuralFeature_type"), 122 EcorePackage.eINSTANCE.getEStructuralFeature_Volatile(), 123 true, 124 ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, 125 null, 126 null)); 127 } 128 129 135 protected void addTransientPropertyDescriptor(Object object) 136 { 137 itemPropertyDescriptors.add 138 (createItemPropertyDescriptor 139 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 140 getResourceLocator(), 141 getString("_UI_EStructuralFeature_transient_feature"), 142 getString("_UI_PropertyDescriptor_description", "_UI_EStructuralFeature_transient_feature", "_UI_EStructuralFeature_type"), 143 EcorePackage.eINSTANCE.getEStructuralFeature_Transient(), 144 true, 145 ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, 146 null, 147 null)); 148 } 149 150 156 protected void addDefaultValueLiteralPropertyDescriptor(Object object) 157 { 158 itemPropertyDescriptors.add 159 (createItemPropertyDescriptor 160 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 161 getResourceLocator(), 162 getString("_UI_EStructuralFeature_defaultValueLiteral_feature"), 163 getString("_UI_PropertyDescriptor_description", "_UI_EStructuralFeature_defaultValueLiteral_feature", "_UI_EStructuralFeature_type"), 164 EcorePackage.eINSTANCE.getEStructuralFeature_DefaultValueLiteral(), 165 true, 166 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 167 null, 168 null)); 169 } 170 171 177 protected void addDefaultValuePropertyDescriptor(Object object) 178 { 179 itemPropertyDescriptors.add 180 (createItemPropertyDescriptor 181 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 182 getResourceLocator(), 183 getString("_UI_EStructuralFeature_defaultValue_feature"), 184 getString("_UI_PropertyDescriptor_description", "_UI_EStructuralFeature_defaultValue_feature", "_UI_EStructuralFeature_type"), 185 EcorePackage.eINSTANCE.getEStructuralFeature_DefaultValue(), 186 true, 187 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 188 null, 189 null)); 190 } 191 192 198 protected void addUnsettablePropertyDescriptor(Object object) 199 { 200 itemPropertyDescriptors.add 201 (createItemPropertyDescriptor 202 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 203 getResourceLocator(), 204 getString("_UI_EStructuralFeature_unsettable_feature"), 205 getString("_UI_PropertyDescriptor_description", "_UI_EStructuralFeature_unsettable_feature", "_UI_EStructuralFeature_type"), 206 EcorePackage.eINSTANCE.getEStructuralFeature_Unsettable(), 207 true, 208 ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, 209 null, 210 null)); 211 } 212 213 219 protected void addDerivedPropertyDescriptor(Object object) 220 { 221 itemPropertyDescriptors.add 222 (createItemPropertyDescriptor 223 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 224 getResourceLocator(), 225 getString("_UI_EStructuralFeature_derived_feature"), 226 getString("_UI_PropertyDescriptor_description", "_UI_EStructuralFeature_derived_feature", "_UI_EStructuralFeature_type"), 227 EcorePackage.eINSTANCE.getEStructuralFeature_Derived(), 228 true, 229 ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, 230 null, 231 null)); 232 } 233 234 240 protected void addEContainingClassPropertyDescriptor(Object object) 241 { 242 itemPropertyDescriptors.add 243 (createItemPropertyDescriptor 244 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 245 getResourceLocator(), 246 getString("_UI_EStructuralFeature_eContainingClass_feature"), 247 getString("_UI_PropertyDescriptor_description", "_UI_EStructuralFeature_eContainingClass_feature", "_UI_EStructuralFeature_type"), 248 EcorePackage.eINSTANCE.getEStructuralFeature_EContainingClass(), 249 false, 250 null, 251 null, 252 null)); 253 } 254 255 261 public String getText(Object object) 262 { 263 String label = ((EStructuralFeature)object).getName(); 264 return label == null || label.length() == 0 ? 265 getString("_UI_EStructuralFeature_type") : 266 getString("_UI_EStructuralFeature_type") + " " + label; 267 } 268 269 public Object getComposedImage(Object object, Object imageToCompose) 270 { 271 EStructuralFeature eStructuralFeature = (EStructuralFeature)object; 272 Collection images = new ArrayList (); 273 images.add(imageToCompose); 274 String imageName = "full/obj16/EOccurrence"; 275 int minOccurs = eStructuralFeature.getLowerBound(); 276 int maxOccurs = eStructuralFeature.getUpperBound(); 277 if (minOccurs >= 0 && (minOccurs <= maxOccurs || maxOccurs == -1)) 278 { 279 switch (minOccurs) 280 { 281 case 0: 282 { 283 imageName += "Zero"; 284 break; 285 } 286 case 1: 287 { 288 imageName += "One"; 289 break; 290 } 291 default: 292 { 293 imageName += "N"; 294 break; 295 } 296 } 297 298 if (minOccurs != maxOccurs) 299 { 300 switch (maxOccurs) 301 { 302 case -1: 303 { 304 imageName += "ToUnbounded"; 305 break; 306 } 307 case 0: 308 { 309 break; 310 } 311 case 1: 312 { 313 imageName += "ToOne"; 314 break; 315 } 316 default: 317 { 318 imageName += minOccurs <= 1 ? "ToN" : "ToM"; 319 break; 320 } 321 } 322 } 323 } 324 else 325 { 326 imageName += "NToM"; 327 } 328 329 if (!imageName.equals("full/obj16/EOccurrenceZeroToOne")) 330 { 331 images.add(EcoreEditPlugin.INSTANCE.getImage(imageName)); 332 } 333 334 return 335 new ComposedImage(images) 336 { 337 public List getDrawPoints(Size size) 338 { 339 List result = super.getDrawPoints(size); 340 if (result.size() > 1) 341 { 342 ((Point)result.get(0)).y = -2; 343 } 344 return result; 345 } 346 }; 347 } 348 349 350 357 public void notifyChanged(Notification notification) 358 { 359 updateChildren(notification); 360 361 switch (notification.getFeatureID(EStructuralFeature.class)) 362 { 363 case EcorePackage.ESTRUCTURAL_FEATURE__CHANGEABLE: 364 case EcorePackage.ESTRUCTURAL_FEATURE__VOLATILE: 365 case EcorePackage.ESTRUCTURAL_FEATURE__TRANSIENT: 366 case EcorePackage.ESTRUCTURAL_FEATURE__DEFAULT_VALUE_LITERAL: 367 case EcorePackage.ESTRUCTURAL_FEATURE__DEFAULT_VALUE: 368 case EcorePackage.ESTRUCTURAL_FEATURE__UNSETTABLE: 369 case EcorePackage.ESTRUCTURAL_FEATURE__DERIVED: 370 case EcorePackage.ESTRUCTURAL_FEATURE__ECONTAINING_CLASS: 371 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true)); 372 return; 373 } 374 super.notifyChanged(notification); 375 } 376 377 384 protected void collectNewChildDescriptors(Collection newChildDescriptors, Object object) 385 { 386 super.collectNewChildDescriptors(newChildDescriptors, object); 387 } 388 389 395 public ResourceLocator getResourceLocator() 396 { 397 return EcoreEditPlugin.INSTANCE; 398 } 399 400 } 401 | Popular Tags |