KickJava   Java API By Example, From Geeks To Geeks.

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


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: EClassItemProvider.java,v 1.8 2005/06/08 06:15:46 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.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.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.EClass;
28 import org.eclipse.emf.ecore.EStructuralFeature;
29 import org.eclipse.emf.ecore.EcoreFactory;
30 import org.eclipse.emf.ecore.EcorePackage;
31 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
32 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
33 import org.eclipse.emf.edit.provider.IItemLabelProvider;
34 import org.eclipse.emf.edit.provider.IItemPropertySource;
35 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
36 import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
37 import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
38
39
40 import org.eclipse.emf.edit.provider.ViewerNotification;
41
42 /**
43  * This is the item provider adapter for a {@link org.eclipse.emf.ecore.EClass} object.
44  * <!-- begin-user-doc -->
45  * <!-- end-user-doc -->
46  * @generated
47  */

48 public class EClassItemProvider
49   extends EClassifierItemProvider
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 EClassItemProvider(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       addAbstractPropertyDescriptor(object);
77       addInterfacePropertyDescriptor(object);
78       addESuperTypesPropertyDescriptor(object);
79     }
80     return itemPropertyDescriptors;
81   }
82
83   /**
84    * This adds a property descriptor for the Abstract feature.
85    * <!-- begin-user-doc -->
86    * <!-- end-user-doc -->
87    * @generated
88    */

89   protected void addAbstractPropertyDescriptor(Object JavaDoc object)
90   {
91     itemPropertyDescriptors.add
92       (createItemPropertyDescriptor
93         (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
94          getResourceLocator(),
95          getString("_UI_EClass_abstract_feature"),
96          getString("_UI_PropertyDescriptor_description", "_UI_EClass_abstract_feature", "_UI_EClass_type"),
97          EcorePackage.eINSTANCE.getEClass_Abstract(),
98          true,
99          ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE,
100          null,
101          null));
102   }
103
104   /**
105    * This adds a property descriptor for the Interface feature.
106    * <!-- begin-user-doc -->
107    * <!-- end-user-doc -->
108    * @generated
109    */

110   protected void addInterfacePropertyDescriptor(Object JavaDoc object)
111   {
112     itemPropertyDescriptors.add
113       (createItemPropertyDescriptor
114         (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
115          getResourceLocator(),
116          getString("_UI_EClass_interface_feature"),
117          getString("_UI_PropertyDescriptor_description", "_UI_EClass_interface_feature", "_UI_EClass_type"),
118          EcorePackage.eINSTANCE.getEClass_Interface(),
119          true,
120          ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE,
121          null,
122          null));
123   }
124
125   /**
126    * This adds a property descriptor for the ESuper Types feature.
127    * <!-- begin-user-doc -->
128    * <!-- end-user-doc -->
129    * @generated NOT
130    */

131   protected void addESuperTypesPropertyDescriptor(Object JavaDoc object)
132   {
133     itemPropertyDescriptors.add
134       (new ItemPropertyDescriptor
135         (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
136          getResourceLocator(),
137          getString("_UI_EClass_eSuperTypes_feature"),
138          getString("_UI_PropertyDescriptor_description", "_UI_EClass_eSuperTypes_feature", "_UI_EClass_type"),
139          EcorePackage.eINSTANCE.getEClass_ESuperTypes(),
140          true)
141        {
142          public Collection JavaDoc getChoiceOfValues(Object JavaDoc object)
143          {
144            EClass eClass = (EClass)object;
145            
146            // Filter out classes that aren't permitted.
147
//
148
Collection JavaDoc result = super.getChoiceOfValues(object);
149            for (Iterator JavaDoc i = result.iterator(); i.hasNext(); )
150            {
151              EClass otherEClass = (EClass)i.next();
152              if (otherEClass == eClass || otherEClass.getEAllSuperTypes().contains(eClass))
153              {
154                i.remove();
155              }
156            }
157            return result;
158          }
159        });
160   }
161
162   /**
163    * This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
164    * {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
165    * {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}.
166    * <!-- begin-user-doc -->
167    * <!-- end-user-doc -->
168    * @generated
169    */

170   public Collection JavaDoc getChildrenFeatures(Object JavaDoc object)
171   {
172     if (childrenFeatures == null)
173     {
174       super.getChildrenFeatures(object);
175       childrenFeatures.add(EcorePackage.eINSTANCE.getEClass_EOperations());
176       childrenFeatures.add(EcorePackage.eINSTANCE.getEClass_EStructuralFeatures());
177     }
178     return childrenFeatures;
179   }
180
181   /**
182    * <!-- begin-user-doc -->
183    * <!-- end-user-doc -->
184    * @generated
185    */

186   protected EStructuralFeature getChildFeature(Object JavaDoc object, Object JavaDoc child)
187   {
188     // Check the type of the specified child object and return the proper feature to use for
189
// adding (see {@link AddCommand}) it as a child.
190

191     return super.getChildFeature(object, child);
192   }
193
194   /**
195    * This returns EClass.gif.
196    * <!-- begin-user-doc -->
197    * <!-- end-user-doc -->
198    * @generated
199    */

200   public Object JavaDoc getImage(Object JavaDoc object)
201   {
202     return getResourceLocator().getImage("full/obj16/EClass");
203   }
204
205   /**
206    * This returns the label text for the adapted class.
207    * <!-- begin-user-doc -->
208    * <!-- end-user-doc -->
209    * @generated NOT
210    */

211   public String JavaDoc getText(Object JavaDoc object)
212   {
213     EClass eClass = (EClass)object;
214     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
215     if (eClass.getName() != null)
216     {
217       result.append(eClass.getName());
218     }
219     if (!eClass.getESuperTypes().isEmpty())
220     {
221       result.append(" -> ");
222       for (Iterator JavaDoc i = eClass.getESuperTypes().iterator(); i.hasNext(); )
223       {
224         EClass eSuperType = (EClass)i.next();
225         result.append(eSuperType.getName());
226         if (i.hasNext())
227         {
228           result.append(", ");
229         }
230       }
231     }
232     if (eClass.getInstanceClassName() != null)
233     {
234       result.append(" <");
235       result.append(eClass.getInstanceClassName());
236       result.append(">");
237     }
238
239     return result.toString();
240   }
241
242   /**
243    * This handles model notifications by calling {@link #updateChildren} to update any cached
244    * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
245    * <!-- begin-user-doc -->
246    * <!-- end-user-doc -->
247    * @generated
248    */

249   public void notifyChanged(Notification notification)
250   {
251     updateChildren(notification);
252
253     switch (notification.getFeatureID(EClass.class))
254     {
255       case EcorePackage.ECLASS__ABSTRACT:
256       case EcorePackage.ECLASS__INTERFACE:
257       case EcorePackage.ECLASS__ESUPER_TYPES:
258       case EcorePackage.ECLASS__EREFERENCES:
259       case EcorePackage.ECLASS__EATTRIBUTES:
260         fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
261         return;
262       case EcorePackage.ECLASS__EOPERATIONS:
263       case EcorePackage.ECLASS__ESTRUCTURAL_FEATURES:
264         fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false));
265         return;
266     }
267     super.notifyChanged(notification);
268   }
269
270   /**
271    * This adds to the collection of {@link org.eclipse.emf.edit.command.CommandParameter}s
272    * describing all of the children that can be created under this object.
273    * <!-- begin-user-doc -->
274    * <!-- end-user-doc -->
275    * @generated
276    */

277   protected void collectNewChildDescriptors(Collection JavaDoc newChildDescriptors, Object JavaDoc object)
278   {
279     super.collectNewChildDescriptors(newChildDescriptors, object);
280
281     newChildDescriptors.add
282       (createChildParameter
283         (EcorePackage.eINSTANCE.getEClass_EOperations(),
284          EcoreFactory.eINSTANCE.createEOperation()));
285
286     newChildDescriptors.add
287       (createChildParameter
288         (EcorePackage.eINSTANCE.getEClass_EStructuralFeatures(),
289          EcoreFactory.eINSTANCE.createEAttribute()));
290
291     newChildDescriptors.add
292       (createChildParameter
293         (EcorePackage.eINSTANCE.getEClass_EStructuralFeatures(),
294          EcoreFactory.eINSTANCE.createEReference()));
295   }
296
297   /**
298    * Return the resource locator for this item provider's resources.
299    * <!-- begin-user-doc -->
300    * <!-- end-user-doc -->
301    * @generated
302    */

303   public ResourceLocator getResourceLocator()
304   {
305     return EcoreEditPlugin.INSTANCE;
306   }
307
308 }
309
Popular Tags