KickJava   Java API By Example, From Geeks To Geeks.

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


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: EStringToStringMapEntryItemProvider.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.List JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.eclipse.emf.common.command.Command;
25 import org.eclipse.emf.common.command.CommandWrapper;
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.EObject;
30 import org.eclipse.emf.ecore.EStructuralFeature;
31 import org.eclipse.emf.ecore.EcorePackage;
32 import org.eclipse.emf.edit.domain.EditingDomain;
33 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
34 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
35 import org.eclipse.emf.edit.provider.IItemLabelProvider;
36 import org.eclipse.emf.edit.provider.IItemPropertySource;
37 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
38 import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
39 import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
40 import org.eclipse.emf.edit.provider.ItemProviderAdapter;
41
42 import org.eclipse.emf.edit.provider.ViewerNotification;
43
44 /**
45  * This is the item provider adapter for a {@link java.util.Map.Entry} object.
46  * <!-- begin-user-doc -->
47  * <!-- end-user-doc -->
48  * @generated
49  */

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

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

72   public List JavaDoc getPropertyDescriptors(Object JavaDoc object)
73   {
74     if (itemPropertyDescriptors == null)
75     {
76       super.getPropertyDescriptors(object);
77
78       addKeyPropertyDescriptor(object);
79       addValuePropertyDescriptor(object);
80     }
81     return itemPropertyDescriptors;
82   }
83
84   /**
85    * This adds a property descriptor for the Key feature.
86    * <!-- begin-user-doc -->
87    * <!-- end-user-doc -->
88    * @generated
89    */

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

111   protected void addValuePropertyDescriptor(Object JavaDoc object)
112   {
113     itemPropertyDescriptors.add
114       (createItemPropertyDescriptor
115         (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
116          getResourceLocator(),
117          getString("_UI_EStringToStringMapEntry_value_feature"),
118          getString("_UI_PropertyDescriptor_description", "_UI_EStringToStringMapEntry_value_feature", "_UI_EStringToStringMapEntry_type"),
119          EcorePackage.eINSTANCE.getEStringToStringMapEntry_Value(),
120          true,
121          ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
122          null,
123          null));
124   }
125
126   /**
127    * This returns EStringToStringMapEntry.gif.
128    * <!-- begin-user-doc -->
129    * <!-- end-user-doc -->
130    * @generated
131    */

132   public Object JavaDoc getImage(Object JavaDoc object)
133   {
134     return getResourceLocator().getImage("full/obj16/EStringToStringMapEntry");
135   }
136
137   /**
138    * This returns the label text for the adapted class.
139    * <!-- begin-user-doc -->
140    * <!-- end-user-doc -->
141    * @generated
142    */

143   public String JavaDoc getText(Object JavaDoc object)
144   {
145     Map.Entry JavaDoc eStringToStringMapEntry = (Map.Entry JavaDoc)object;
146     return "" + eStringToStringMapEntry.getKey() + " -> " + eStringToStringMapEntry.getValue();
147   }
148
149   /**
150    * This handles model notifications by calling {@link #updateChildren} to update any cached
151    * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
152    * <!-- begin-user-doc -->
153    * <!-- end-user-doc -->
154    * @generated
155    */

156   public void notifyChanged(Notification notification)
157   {
158     updateChildren(notification);
159
160     switch (notification.getFeatureID(Map.Entry JavaDoc.class))
161     {
162       case EcorePackage.ESTRING_TO_STRING_MAP_ENTRY__KEY:
163       case EcorePackage.ESTRING_TO_STRING_MAP_ENTRY__VALUE:
164         fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
165         return;
166     }
167     super.notifyChanged(notification);
168   }
169
170   /**
171    * This adds to the collection of {@link org.eclipse.emf.edit.command.CommandParameter}s
172    * describing all of the children that can be created under this object.
173    * <!-- begin-user-doc -->
174    * <!-- end-user-doc -->
175    * @generated
176    */

177   protected void collectNewChildDescriptors(Collection JavaDoc newChildDescriptors, Object JavaDoc object)
178   {
179     super.collectNewChildDescriptors(newChildDescriptors, object);
180   }
181
182   /**
183    * When setting the key attribute, use a command wrapper that reindexes the attribute's details map.
184    */

185   protected Command createSetCommand(EditingDomain domain, final EObject owner, EStructuralFeature feature, Object JavaDoc value, int index)
186   {
187     Command result = super.createSetCommand(domain, owner, feature, value, index);
188     if (feature == EcorePackage.eINSTANCE.getEStringToStringMapEntry_Key())
189     {
190       result = new
191         CommandWrapper(result)
192         {
193           public void execute()
194           {
195             super.execute();
196             reindex();
197           }
198   
199           public void undo()
200           {
201             super.undo();
202             reindex();
203           }
204   
205           public void redo()
206           {
207             super.redo();
208             reindex();
209           }
210   
211           private void reindex()
212           {
213             EObject parent = owner.eContainer();
214             if (parent != null)
215             {
216               EStructuralFeature feature = owner.eContainmentFeature();
217               List JavaDoc list = (List JavaDoc)parent.eGet(feature);
218               list.set(list.indexOf(owner), owner);
219             }
220           }
221         };
222     }
223     return result;
224   }
225
226   /**
227    * Return the resource locator for this item provider's resources.
228    * <!-- begin-user-doc -->
229    * <!-- end-user-doc -->
230    * @generated
231    */

232   public ResourceLocator getResourceLocator()
233   {
234     return EcoreEditPlugin.INSTANCE;
235   }
236
237 }
238
Popular Tags