KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > provider > EStructuralFeatureItemProvider


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: EStructuralFeatureItemProvider.java,v 1.7 2005/06/08 06:15:46 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.provider;
18
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.List JavaDoc;
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 /**
42  * This is the item provider adapter for a {@link org.eclipse.emf.ecore.EStructuralFeature} object.
43  * <!-- begin-user-doc -->
44  * <!-- end-user-doc -->
45  * @generated
46  */

47 public class EStructuralFeatureItemProvider
48   extends ETypedElementItemProvider
49   implements
50     IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource
51 {
52   /**
53    * This constructs an instance from a factory and a notifier.
54    * <!-- begin-user-doc -->
55    * <!-- end-user-doc -->
56    * @generated
57    */

58   public EStructuralFeatureItemProvider(AdapterFactory adapterFactory)
59   {
60     super(adapterFactory);
61   }
62
63   /**
64    * This returns the property descriptors for the adapted class.
65    * <!-- begin-user-doc -->
66    * <!-- end-user-doc -->
67    * @generated
68    */

69   public List JavaDoc getPropertyDescriptors(Object JavaDoc 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   /**
88    * This adds a property descriptor for the Changeable feature.
89    * <!-- begin-user-doc -->
90    * <!-- end-user-doc -->
91    * @generated
92    */

93   protected void addChangeablePropertyDescriptor(Object JavaDoc 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   /**
109    * This adds a property descriptor for the Volatile feature.
110    * <!-- begin-user-doc -->
111    * <!-- end-user-doc -->
112    * @generated
113    */

114   protected void addVolatilePropertyDescriptor(Object JavaDoc 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   /**
130    * This adds a property descriptor for the Transient feature.
131    * <!-- begin-user-doc -->
132    * <!-- end-user-doc -->
133    * @generated
134    */

135   protected void addTransientPropertyDescriptor(Object JavaDoc 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   /**
151    * This adds a property descriptor for the Default Value Literal feature.
152    * <!-- begin-user-doc -->
153    * <!-- end-user-doc -->
154    * @generated
155    */

156   protected void addDefaultValueLiteralPropertyDescriptor(Object JavaDoc 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   /**
172    * This adds a property descriptor for the Default Value feature.
173    * <!-- begin-user-doc -->
174    * <!-- end-user-doc -->
175    * @generated
176    */

177   protected void addDefaultValuePropertyDescriptor(Object JavaDoc 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   /**
193    * This adds a property descriptor for the Unsettable feature.
194    * <!-- begin-user-doc -->
195    * <!-- end-user-doc -->
196    * @generated
197    */

198   protected void addUnsettablePropertyDescriptor(Object JavaDoc 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   /**
214    * This adds a property descriptor for the Derived feature.
215    * <!-- begin-user-doc -->
216    * <!-- end-user-doc -->
217    * @generated
218    */

219   protected void addDerivedPropertyDescriptor(Object JavaDoc 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   /**
235    * This adds a property descriptor for the EContaining Class feature.
236    * <!-- begin-user-doc -->
237    * <!-- end-user-doc -->
238    * @generated
239    */

240   protected void addEContainingClassPropertyDescriptor(Object JavaDoc 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   /**
256    * This returns the label text for the adapted class.
257    * <!-- begin-user-doc -->
258    * <!-- end-user-doc -->
259    * @generated
260    */

261   public String JavaDoc getText(Object JavaDoc object)
262   {
263     String JavaDoc 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 JavaDoc getComposedImage(Object JavaDoc object, Object JavaDoc imageToCompose)
270   {
271     EStructuralFeature eStructuralFeature = (EStructuralFeature)object;
272     Collection JavaDoc images = new ArrayList JavaDoc();
273     images.add(imageToCompose);
274     String JavaDoc 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 JavaDoc getDrawPoints(Size size)
338         {
339           List JavaDoc 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   /**
351    * This handles model notifications by calling {@link #updateChildren} to update any cached
352    * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
353    * <!-- begin-user-doc -->
354    * <!-- end-user-doc -->
355    * @generated
356    */

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   /**
378    * This adds to the collection of {@link org.eclipse.emf.edit.command.CommandParameter}s
379    * describing all of the children that can be created under this object.
380    * <!-- begin-user-doc -->
381    * <!-- end-user-doc -->
382    * @generated
383    */

384   protected void collectNewChildDescriptors(Collection JavaDoc newChildDescriptors, Object JavaDoc object)
385   {
386     super.collectNewChildDescriptors(newChildDescriptors, object);
387   }
388
389   /**
390    * Return the resource locator for this item provider's resources.
391    * <!-- begin-user-doc -->
392    * <!-- end-user-doc -->
393    * @generated
394    */

395   public ResourceLocator getResourceLocator()
396   {
397     return EcoreEditPlugin.INSTANCE;
398   }
399
400 }
401
Popular Tags