KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > mapping > provider > MappingHelperItemProvider


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: MappingHelperItemProvider.java,v 1.6 2005/06/12 13:38:46 emerks Exp $
16  */

17 package org.eclipse.emf.mapping.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.edit.provider.ComposeableAdapterFactory;
28 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
29 import org.eclipse.emf.edit.provider.IItemLabelProvider;
30 import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
31 import org.eclipse.emf.edit.provider.IItemPropertySource;
32 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
33 import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
34 //import org.eclipse.emf.edit.provider.ViewerNotification;
35

36 import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
37 import org.eclipse.emf.edit.provider.ItemPropertyDescriptorDecorator;
38 import org.eclipse.emf.mapping.Mapping;
39 import org.eclipse.emf.mapping.MappingHelper;
40 import org.eclipse.emf.mapping.MappingPackage;
41 import org.eclipse.emf.mapping.MappingPlugin;
42
43 // import org.eclipse.emf.edit.provider.ItemProviderAdapter;
44

45
46 /**
47  * This is the item provider adpater for a {@link org.eclipse.emf.mapping.MappingHelper} object.
48  */

49 public class MappingHelperItemProvider
50   extends MappingItemProviderAdapter
51   implements
52     IEditingDomainItemProvider,
53     IStructuredItemContentProvider,
54     ITreeItemContentProvider,
55     IItemLabelProvider,
56     IItemPropertySource
57 {
58   /**
59    * This constructs an instance from a factory and a notifier.
60    */

61   public MappingHelperItemProvider(AdapterFactory adapterFactory)
62   {
63     super(adapterFactory);
64   }
65
66   /**
67    * This returns the property descriptors for the adapted class.
68    */

69   public List JavaDoc getPropertyDescriptors(Object JavaDoc object)
70   {
71     if (itemPropertyDescriptors == null)
72     {
73       super.getPropertyDescriptors(object);
74
75       MappingHelper mappingHelper = (MappingHelper)object;
76
77       Mapping mapping = mappingHelper.getMapper();
78       
79       MappingPackage ePackage = MappingPackage.eINSTANCE;
80       if (!mappingHelper.getNested().isEmpty())
81       {
82         int count = 1;
83         for (Iterator JavaDoc helpers = mappingHelper.getNested().iterator(); helpers.hasNext(); ++count)
84         {
85           final MappingHelper childHelper = (MappingHelper)helpers.next();
86
87           String JavaDoc additionalLabel =
88             mapping.getInputs().contains(childHelper.getHelpedObject()) ? MappingPlugin.INSTANCE.getString("_UI_Input_label") :
89             mapping.getOutputs().contains(childHelper.getHelpedObject()) ? MappingPlugin.INSTANCE.getString("_UI_Output_label") :
90             "";
91
92           IItemPropertyDescriptor childHelperItemPropertyDescriptor =
93             (new ItemPropertyDescriptor
94                (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
95                 count + ". " + additionalLabel + MappingPlugin.INSTANCE.getString("_UI_Helper_label"),
96                 MappingPlugin.INSTANCE.getString("_UI_Helper_description"),
97                 ePackage.getMappingHelper_Nested()));
98
99           itemPropertyDescriptors.add
100             (new ItemPropertyDescriptorDecorator(childHelper, childHelperItemPropertyDescriptor)
101              {
102                protected Object JavaDoc createPropertyValueWrapper(Object JavaDoc object, Object JavaDoc propertyValue)
103                {
104                  return
105                    new ItemPropertyDescriptor.PropertyValueWrapper
106                      (((ComposeableAdapterFactory)getAdapterFactory()).getRootAdapterFactory(), object, propertyValue, object);
107                }
108                public Object JavaDoc getPropertyValue(Object JavaDoc o)
109                {
110                  return createPropertyValueWrapper(childHelper, childHelper.getHelpedObject());
111                }
112                public Collection JavaDoc getChoiceOfValues(Object JavaDoc object)
113                {
114                  return null;
115                }
116              });
117         }
118       }
119     }
120     return itemPropertyDescriptors;
121   }
122
123   /**
124    * This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
125    * {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
126    * {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}.
127    * <!-- begin-user-doc -->
128    * <!-- end-user-doc -->
129    * @generated NOT
130    */

131   public Collection JavaDoc getChildrenFeatures(Object JavaDoc object)
132   {
133     return super.getChildrenFeatures(object);
134   }
135
136   public Collection JavaDoc getChildren(Object JavaDoc object)
137   {
138     return ((MappingHelper)object).getNested();
139   }
140
141   public boolean hasChildren(Object JavaDoc object)
142   {
143     return !((MappingHelper)object).getNested().isEmpty();
144   }
145
146   /**
147    * This returns the mapper of the MappingHelper.
148    */

149   public Object JavaDoc getParent(Object JavaDoc object)
150   {
151     MappingHelper mappingHelper = (MappingHelper)object;
152     if (mappingHelper.getNestedIn() != null)
153     {
154       return mappingHelper.getNestedIn();
155     }
156     else
157     {
158       return mappingHelper.getMapper();
159     }
160   }
161
162   /**
163    * This returns MappingHelper.gif.
164    */

165   public Object JavaDoc getImage(Object JavaDoc object)
166   {
167     return MappingPlugin.getPlugin().getImage("full/obj16/MappingHelper");
168   }
169
170   public String JavaDoc getText(Object JavaDoc object)
171   {
172     return "MappingHelper";
173   }
174
175   /**
176    * This handles notification by delegating to {@link #fireNotifyChanged fireNotifyChanged}.
177    */

178   public void notifyChanged(Notification msg)
179   {
180     if (msg.getFeature() == MappingPackage.eINSTANCE.getMappingHelper_Mapper())
181     {
182       fireNotifyChanged(msg);
183       return;
184     }
185     super.notifyChanged(msg);
186   }
187
188   /**
189    * Return the resource locator for this item provider's resources.
190    * <!-- begin-user-doc -->
191    * <!-- end-user-doc -->
192    * @generated
193    */

194   public ResourceLocator getResourceLocator()
195   {
196     return MappingPlugin.INSTANCE;
197   }
198
199 }
200
Popular Tags