KickJava   Java API By Example, From Geeks To Geeks.

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


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: MappingRootItemProvider.java,v 1.5 2005/06/08 06:21:43 nickb Exp $
16  */

17 package org.eclipse.emf.mapping.provider;
18
19
20 import java.util.Collection JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.eclipse.emf.common.command.Command;
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.command.CommandParameter;
28 import org.eclipse.emf.edit.domain.EditingDomain;
29 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
30 import org.eclipse.emf.edit.provider.IItemLabelProvider;
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.mapping.MappingPackage;
38 import org.eclipse.emf.mapping.MappingPlugin;
39 import org.eclipse.emf.mapping.MappingRoot;
40 import org.eclipse.emf.mapping.command.AddMappingCommand;
41 import org.eclipse.emf.mapping.command.CreateMappingCommand;
42 import org.eclipse.emf.mapping.command.RemoveMappingCommand;
43 import org.eclipse.emf.mapping.command.RestoreInitialStateCommand;
44 import org.eclipse.emf.mapping.domain.MappingDomain;
45
46
47 /**
48  * This is the item provider adpater for a {@link org.eclipse.emf.mapping.MappingRoot} object.
49  */

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

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

70   public List JavaDoc getPropertyDescriptors(Object JavaDoc object)
71   {
72     if (itemPropertyDescriptors == null)
73     {
74       super.getPropertyDescriptors(object);
75
76       MappingRoot mappingRoot = (MappingRoot)object;
77       //MappingPackage ePackage = ((MappingRoot)object).ePackageMapping();
78
MappingPackage ePackage = MappingPackage.eINSTANCE;
79
80       boolean isTypeMapping = mappingRoot.getDomain() == null;
81
82       if (!isTypeMapping)
83       {
84         // This is for the topDown feature.
85
//
86
itemPropertyDescriptors.add
87           (new ItemPropertyDescriptor
88             (adapterFactory,
89              MappingPlugin.getPlugin().getString("_UI_OutputReadOnly_property_label"),
90              MappingPlugin.getPlugin().getString("_UI_OutputReadOnly_property_description"),
91              ePackage.getMappingRoot_OutputReadOnly(),
92              true,
93              ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE));
94   
95         // This is for the topDown feature.
96
//
97
itemPropertyDescriptors.add
98           (new ItemPropertyDescriptor
99             (adapterFactory,
100              MappingPlugin.getPlugin().getString("_UI_TopToBottom_property_label"),
101              MappingPlugin.getPlugin().getString("_UI_TopToBottom_property_description"),
102              ePackage.getMappingRoot_TopToBottom(),
103              false,
104              ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE));
105       }
106     }
107     return itemPropertyDescriptors;
108   }
109
110   /**
111    * This returns the label text for the adapted class.
112    * <!-- begin-user-doc -->
113    * <!-- end-user-doc -->
114    * @generated NOT
115    */

116   public String JavaDoc getText(Object JavaDoc object)
117   {
118     return super.getText(object);
119   }
120
121   /**
122    * This handles notification by delegating to {@link #fireNotifyChanged fireNotifyChanged}.
123    */

124   public void notifyChanged(Notification msg)
125   {
126     //MappingPackage ePackage = ((MappingRoot)msg.getNotifier()).ePackageMapping();
127
MappingPackage ePackage = MappingPackage.eINSTANCE;
128     if (msg.getFeature() == ePackage.getMappingRoot_OutputReadOnly() || msg.getFeature() == ePackage.getMappingRoot_TopToBottom())
129     {
130       fireNotifyChanged(msg);
131       //hgd::fireNotifyChanged(msg.getNotifier(), msg.getEventType(), msg.getStructuralFeature(), msg.getOldValue(), msg.getNewValue(), msg.getPosition());
132
return;
133     }
134     super.notifyChanged(msg);
135   }
136
137   public Command createCommand(Object JavaDoc object, EditingDomain editingDomain, Class JavaDoc commandClass, CommandParameter commandParameter)
138   {
139     if (editingDomain instanceof MappingDomain) // && commandParameter instanceof MappingCommandParameter)
140
{
141       MappingDomain mappingDomain = (MappingDomain)editingDomain;
142
143       if (commandClass == CreateMappingCommand.class)
144       {
145         return createCreateMappingCommand(mappingDomain, commandParameter.getCollection());
146       }
147       else if (commandClass == AddMappingCommand.class)
148       {
149         return createAddMappingCommand(mappingDomain, commandParameter.getCollection());
150       }
151       else if (commandClass == RemoveMappingCommand.class)
152       {
153         return createRemoveMappingCommand(mappingDomain, commandParameter.getCollection());
154       }
155       else if (commandClass == RestoreInitialStateCommand.class)
156       {
157         return createRestoreInitialStateCommand(mappingDomain);
158       }
159     }
160
161     return super.createCommand(object, editingDomain, commandClass, commandParameter);
162   }
163
164   /**
165    * This creates a primitive {@link org.eclipse.emf.mapping.command.CreateMappingCommand}.
166    */

167   protected Command createCreateMappingCommand(MappingDomain domain, Collection JavaDoc collection)
168   {
169     return new CreateMappingCommand(domain, collection);
170   }
171
172   /**
173    * This creates a primitive {@link org.eclipse.emf.mapping.command.AddMappingCommand}.
174    */

175   protected Command createAddMappingCommand(MappingDomain domain, Collection JavaDoc collection)
176   {
177     return new AddMappingCommand(domain, collection);
178   }
179
180   /**
181    * This creates a primitive {@link org.eclipse.emf.mapping.command.RemoveMappingCommand}.
182    */

183   protected Command createRemoveMappingCommand(MappingDomain domain, Collection JavaDoc collection)
184   {
185     return new RemoveMappingCommand(domain, collection);
186   }
187
188   /**
189    * This creates a primitive {@link org.eclipse.emf.mapping.command.RestoreInitialStateCommand}.
190    */

191   protected Command createRestoreInitialStateCommand(MappingDomain domain)
192   {
193     return new RestoreInitialStateCommand(domain);
194   }
195
196   /**
197    * Return the resource locator for this item provider's resources.
198    * <!-- begin-user-doc -->
199    * <!-- end-user-doc -->
200    * @generated
201    */

202   public ResourceLocator getResourceLocator()
203   {
204     return MappingPlugin.INSTANCE;
205   }
206
207 }
208
Popular Tags