KickJava   Java API By Example, From Geeks To Geeks.

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


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: EReferenceItemProvider.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.ArrayList JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 import org.eclipse.emf.common.command.CompoundCommand;
27 import org.eclipse.emf.common.notify.AdapterFactory;
28 import org.eclipse.emf.common.notify.Notification;
29 import org.eclipse.emf.common.util.ResourceLocator;
30 import org.eclipse.emf.ecore.EClass;
31 import org.eclipse.emf.ecore.EReference;
32 import org.eclipse.emf.ecore.EcorePackage;
33 import org.eclipse.emf.edit.command.SetCommand;
34 import org.eclipse.emf.edit.domain.EditingDomain;
35 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
36 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
37 import org.eclipse.emf.edit.provider.IItemLabelProvider;
38 import org.eclipse.emf.edit.provider.IItemPropertySource;
39 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
40 import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
41 import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
42
43
44 import org.eclipse.emf.edit.provider.ViewerNotification;
45
46 /**
47  * This is the item provider adapter for a {@link org.eclipse.emf.ecore.EReference} object.
48  * <!-- begin-user-doc -->
49  * <!-- end-user-doc -->
50  * @generated
51  */

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

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

74   public List JavaDoc getPropertyDescriptors(Object JavaDoc object)
75   {
76     if (itemPropertyDescriptors == null)
77     {
78       super.getPropertyDescriptors(object);
79
80       addContainmentPropertyDescriptor(object);
81       addContainerPropertyDescriptor(object);
82       addResolveProxiesPropertyDescriptor(object);
83       addEOppositePropertyDescriptor(object);
84       addEReferenceTypePropertyDescriptor(object);
85     }
86     return itemPropertyDescriptors;
87   }
88
89   /**
90    * This adds a property descriptor for the Containment feature.
91    * <!-- begin-user-doc -->
92    * <!-- end-user-doc -->
93    * @generated
94    */

95   protected void addContainmentPropertyDescriptor(Object JavaDoc object)
96   {
97     itemPropertyDescriptors.add
98       (createItemPropertyDescriptor
99         (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
100          getResourceLocator(),
101          getString("_UI_EReference_containment_feature"),
102          getString("_UI_PropertyDescriptor_description", "_UI_EReference_containment_feature", "_UI_EReference_type"),
103          EcorePackage.eINSTANCE.getEReference_Containment(),
104          true,
105          ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE,
106          null,
107          null));
108   }
109
110   /**
111    * This adds a property descriptor for the Container feature.
112    * <!-- begin-user-doc -->
113    * <!-- end-user-doc -->
114    * @generated
115    */

116   protected void addContainerPropertyDescriptor(Object JavaDoc object)
117   {
118     itemPropertyDescriptors.add
119       (createItemPropertyDescriptor
120         (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
121          getResourceLocator(),
122          getString("_UI_EReference_container_feature"),
123          getString("_UI_PropertyDescriptor_description", "_UI_EReference_container_feature", "_UI_EReference_type"),
124          EcorePackage.eINSTANCE.getEReference_Container(),
125          false,
126          ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE,
127          null,
128          null));
129   }
130
131   /**
132    * This adds a property descriptor for the Resolve Proxies feature.
133    * <!-- begin-user-doc -->
134    * <!-- end-user-doc -->
135    * @generated
136    */

137   protected void addResolveProxiesPropertyDescriptor(Object JavaDoc object)
138   {
139     itemPropertyDescriptors.add
140       (createItemPropertyDescriptor
141         (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
142          getResourceLocator(),
143          getString("_UI_EReference_resolveProxies_feature"),
144          getString("_UI_PropertyDescriptor_description", "_UI_EReference_resolveProxies_feature", "_UI_EReference_type"),
145          EcorePackage.eINSTANCE.getEReference_ResolveProxies(),
146          true,
147          ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE,
148          null,
149          null));
150   }
151
152   /**
153    * This adds a property descriptor for the EOpposite feature.
154    * <!-- begin-user-doc -->
155    * <!-- end-user-doc -->
156    * @generated NOT
157    */

158   protected void addEOppositePropertyDescriptor(Object JavaDoc object)
159   {
160     itemPropertyDescriptors.add
161       (new ItemPropertyDescriptor
162         (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
163          getResourceLocator(),
164          getString("_UI_EReference_eOpposite_feature"),
165          getString("_UI_PropertyDescriptor_description", "_UI_EReference_eOpposite_feature", "_UI_EReference_type"),
166          EcorePackage.eINSTANCE.getEReference_EOpposite(),
167          true)
168         {
169           public Collection JavaDoc getChoiceOfValues(Object JavaDoc object)
170           {
171             EReference eReference = (EReference)object;
172             EClass eContainingClass = eReference.getEContainingClass();
173             EClass eReferenceType = eReference.getEReferenceType();
174             if (eContainingClass == null || eReferenceType == null)
175             {
176               return Collections.EMPTY_LIST;
177             }
178             Collection JavaDoc result = new ArrayList JavaDoc(super.getChoiceOfValues(object));
179             for (Iterator JavaDoc i = result.iterator(); i.hasNext(); )
180             {
181               EReference eOpposite = (EReference)i.next();
182               if (eOpposite != null)
183               {
184                 if (eOpposite == eReference)
185                 {
186                   i.remove();
187                 }
188                 else
189                 {
190                   EClass eOppositeContainingClass = eOpposite.getEContainingClass();
191                   EClass eOppositeReferenceType = eOpposite.getEReferenceType();
192                   if (eOppositeContainingClass == null ||
193                         !eOppositeContainingClass.isSuperTypeOf(eReferenceType) ||
194                         !eContainingClass.isSuperTypeOf(eOppositeReferenceType))
195                   {
196                     i.remove();
197                   }
198                 }
199               }
200             }
201             return result;
202           }
203           
204           public void setPropertyValue(Object JavaDoc object, Object JavaDoc value)
205           {
206             EReference eReference = (EReference)object;
207             EReference eOpposite = (EReference)value;
208             EditingDomain editingDomain = getEditingDomain(eReference);
209             if (editingDomain == null)
210             {
211               EReference oldReferenceOpposite = eReference.getEOpposite();
212               if (oldReferenceOpposite != null)
213               {
214                 oldReferenceOpposite.setEOpposite(null);
215               }
216               if (eOpposite != null)
217               {
218                 EReference oldOppositeOpposite = eOpposite.getEOpposite();
219                 if (oldOppositeOpposite != null)
220                 {
221                   oldOppositeOpposite.setEOpposite(null);
222                 }
223                 eOpposite.setEOpposite(eReference);
224               }
225               eReference.setEOpposite(eOpposite);
226             }
227             else
228             {
229               CompoundCommand compoundCommand = new CompoundCommand(CompoundCommand.LAST_COMMAND_ALL);
230               EReference oldReferenceOpposite = eReference.getEOpposite();
231               if (oldReferenceOpposite != null)
232               {
233                 compoundCommand.append(SetCommand.create(editingDomain, getCommandOwner(oldReferenceOpposite), feature, null));
234               }
235               if (eOpposite != null)
236               {
237                 EReference oldOppositeOpposite = eOpposite.getEOpposite();
238                 if (oldOppositeOpposite != null)
239                 {
240                   compoundCommand.append(SetCommand.create(editingDomain, getCommandOwner(oldOppositeOpposite), feature, null));
241                 }
242                 compoundCommand.append(SetCommand.create(editingDomain, getCommandOwner(eOpposite), feature, eReference));
243               }
244               compoundCommand.append(SetCommand.create(editingDomain, getCommandOwner(eReference), feature, eOpposite));
245               editingDomain.getCommandStack().execute(compoundCommand);
246             }
247           }
248         });
249   }
250
251   /**
252    * This adds a property descriptor for the EReference Type feature.
253    * <!-- begin-user-doc -->
254    * <!-- end-user-doc -->
255    * @generated
256    */

257   protected void addEReferenceTypePropertyDescriptor(Object JavaDoc object)
258   {
259     itemPropertyDescriptors.add
260       (createItemPropertyDescriptor
261         (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
262          getResourceLocator(),
263          getString("_UI_EReference_eReferenceType_feature"),
264          getString("_UI_PropertyDescriptor_description", "_UI_EReference_eReferenceType_feature", "_UI_EReference_type"),
265          EcorePackage.eINSTANCE.getEReference_EReferenceType(),
266          false,
267          null,
268          null,
269          null));
270   }
271
272   /**
273    * This returns EReference.gif.
274    * <!-- begin-user-doc -->
275    * <!-- end-user-doc -->
276    * @generated NOT
277    */

278   public Object JavaDoc getImage(Object JavaDoc object)
279   {
280     return getComposedImage(object, getResourceLocator().getImage("full/obj16/EReference"));
281   }
282
283   /**
284    * This returns the label text for the adapted class.
285    * <!-- begin-user-doc -->
286    * <!-- end-user-doc -->
287    * @generated NOT
288    */

289   public String JavaDoc getText(Object JavaDoc object)
290   {
291     EReference eReference = (EReference)object;
292     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
293     result.append(eReference.getName());
294     if (eReference.getEType() != null)
295     {
296       result.append(" : ");
297       result.append(eReference.getEType().getName());
298     }
299     return result.toString();
300   }
301
302   /**
303    * This handles model notifications by calling {@link #updateChildren} to update any cached
304    * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
305    * <!-- begin-user-doc -->
306    * <!-- end-user-doc -->
307    * @generated
308    */

309   public void notifyChanged(Notification notification)
310   {
311     updateChildren(notification);
312
313     switch (notification.getFeatureID(EReference.class))
314     {
315       case EcorePackage.EREFERENCE__CONTAINMENT:
316       case EcorePackage.EREFERENCE__CONTAINER:
317       case EcorePackage.EREFERENCE__RESOLVE_PROXIES:
318       case EcorePackage.EREFERENCE__EOPPOSITE:
319       case EcorePackage.EREFERENCE__EREFERENCE_TYPE:
320         fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
321         return;
322     }
323     super.notifyChanged(notification);
324   }
325
326   /**
327    * This adds to the collection of {@link org.eclipse.emf.edit.command.CommandParameter}s
328    * describing all of the children that can be created under this object.
329    * <!-- begin-user-doc -->
330    * <!-- end-user-doc -->
331    * @generated
332    */

333   protected void collectNewChildDescriptors(Collection JavaDoc newChildDescriptors, Object JavaDoc object)
334   {
335     super.collectNewChildDescriptors(newChildDescriptors, object);
336   }
337
338   /**
339    * Return the resource locator for this item provider's resources.
340    * <!-- begin-user-doc -->
341    * <!-- end-user-doc -->
342    * @generated
343    */

344   public ResourceLocator getResourceLocator()
345   {
346     return EcoreEditPlugin.INSTANCE;
347   }
348
349 }
350
Popular Tags