KickJava   Java API By Example, From Geeks To Geeks.

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


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: GenClassItemProvider.java,v 1.10 2005/06/08 06:17:51 nickb Exp $
16  */

17 package org.eclipse.emf.codegen.ecore.genmodel.provider;
18
19
20 import java.util.Collection JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
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 // import org.eclipse.emf.codegen.ecore.genmodel.GenProviderKind;
43

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

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

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

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

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

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

135   protected void addEcoreClassPropertyDescriptor(Object JavaDoc 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   /**
151    * This adds a property descriptor for the Label Feature feature.
152    */

153   protected void addLabelFeaturePropertyDescriptor(Object JavaDoc 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 JavaDoc getComboBoxObjects(Object JavaDoc object)
165          {
166            GenClass genClass = (GenClass)object;
167            return genClass.getLabelFeatureCandidates();
168          }
169        });
170   }
171
172   /**
173    * This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
174    * {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
175    * {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}.
176    * <!-- begin-user-doc -->
177    * <!-- end-user-doc -->
178    * @generated
179    */

180   public Collection JavaDoc getChildrenFeatures(Object JavaDoc 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   /**
192    * <!-- begin-user-doc -->
193    * <!-- end-user-doc -->
194    * @generated
195    */

196   protected EStructuralFeature getChildFeature(Object JavaDoc object, Object JavaDoc child)
197   {
198     // Check the type of the specified child object and return the proper feature to use for
199
// adding (see {@link AddCommand}) it as a child.
200

201     return super.getChildFeature(object, child);
202   }
203
204   /**
205    */

206   public Object JavaDoc getImage(Object JavaDoc object)
207   {
208     return new UnderlayedImage(getResourceLocator().getImage("full/obj16/EClass"));
209   }
210
211   /**
212    * This returns the label text for the adapted class.
213    */

214   public String JavaDoc getText(Object JavaDoc object)
215   {
216     GenClass genClass = (GenClass)object;
217     EClass eClass = genClass.getEcoreClass();
218     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
219     if (eClass.getName() != null)
220     {
221       result.append(eClass.getName());
222     }
223     if (!eClass.getESuperTypes().isEmpty())
224     {
225       result.append(" -> ");
226       for (Iterator JavaDoc 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   /**
247    * This handles model notifications by calling {@link #updateChildren} to update any cached
248    * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
249    * <!-- begin-user-doc -->
250    * <!-- end-user-doc -->
251    * @generated
252    */

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   /**
275    * Return the resource locator for this item provider's resources.
276    * <!-- begin-user-doc -->
277    * <!-- end-user-doc -->
278    * @generated
279    */

280   public ResourceLocator getResourceLocator()
281   {
282     return GenModelEditPlugin.INSTANCE;
283   }
284
285 }
286
Popular Tags