KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > codegen > ecore > genmodel > provider > GenFeatureItemProvider


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2005 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: GenFeatureItemProvider.java,v 1.11 2005/06/08 06:17:51 nickb Exp $
16  */

17 package org.eclipse.emf.codegen.ecore.genmodel.provider;
18
19
20 import java.util.List JavaDoc;
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 // import org.eclipse.emf.codegen.ecore.genmodel.GenPropertyKind;
40

41
42 /**
43  * This is the item provider adapter for a {@link org.eclipse.emf.codegen.ecore.genmodel.GenFeature} object.
44  * <!-- begin-user-doc -->
45  * <!-- end-user-doc -->
46  * @generated
47  */

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

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

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

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

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

136   protected void addChildrenPropertyDescriptor(Object JavaDoc 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   /**
152    * This adds a property descriptor for the Create Child feature.
153    * <!-- begin-user-doc -->
154    * <!-- end-user-doc -->
155    * @generated
156    */

157   protected void addCreateChildPropertyDescriptor(Object JavaDoc 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   /**
173    * This adds a property descriptor for the Property Category feature.
174    * <!-- begin-user-doc -->
175    * <!-- end-user-doc -->
176    * @generated
177    */

178   protected void addPropertyCategoryPropertyDescriptor(Object JavaDoc 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   /**
194    * This adds a property descriptor for the Property Filter Flags feature.
195    * <!-- begin-user-doc -->
196    * <!-- end-user-doc -->
197    * @generated
198    */

199   protected void addPropertyFilterFlagsPropertyDescriptor(Object JavaDoc 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   /**
215    * This adds a property descriptor for the Property Description feature.
216    * <!-- begin-user-doc -->
217    * <!-- end-user-doc -->
218    * @generated
219    */

220   protected void addPropertyDescriptionPropertyDescriptor(Object JavaDoc 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   /**
236    * This adds a property descriptor for the Ecore Feature feature.
237    * <!-- begin-user-doc -->
238    * <!-- end-user-doc -->
239    * @generated
240    */

241   protected void addEcoreFeaturePropertyDescriptor(Object JavaDoc 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   /**
257    */

258   public Object JavaDoc getImage(Object JavaDoc object)
259   {
260     GenFeature genFeature = (GenFeature)object;
261     EStructuralFeature eStructuralFeature = genFeature.getEcoreFeature();
262     Object JavaDoc image =
263       getResourceLocator().getImage(eStructuralFeature instanceof EAttribute ? "full/obj16/EAttribute" : "full/obj16/EReference");
264
265     String JavaDoc 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   /**
331    * This returns the label text for the adapted class.
332    */

333   public String JavaDoc getText(Object JavaDoc object)
334   {
335     GenFeature genFeature = (GenFeature)object;
336     EStructuralFeature eStructuralFeature = genFeature.getEcoreFeature();
337     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
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   /**
348    * This handles model notifications by calling {@link #updateChildren} to update any cached
349    * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
350    * <!-- begin-user-doc -->
351    * <!-- end-user-doc -->
352    * @generated
353    */

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   /**
375    * Return the resource locator for this item provider's resources.
376    * <!-- begin-user-doc -->
377    * <!-- end-user-doc -->
378    * @generated
379    */

380   public ResourceLocator getResourceLocator()
381   {
382     return GenModelEditPlugin.INSTANCE;
383   }
384
385 }
386
Popular Tags