KickJava   Java API By Example, From Geeks To Geeks.

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


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

17 package org.eclipse.emf.mapping.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.List JavaDoc;
24
25 import org.eclipse.emf.common.command.Command;
26 import org.eclipse.emf.common.command.UnexecutableCommand;
27 import org.eclipse.emf.common.notify.AdapterFactory;
28 import org.eclipse.emf.common.notify.Notification;
29 import org.eclipse.emf.common.notify.NotificationWrapper;
30 import org.eclipse.emf.ecore.EObject;
31 import org.eclipse.emf.edit.command.CommandParameter;
32 import org.eclipse.emf.edit.domain.EditingDomain;
33 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
34 import org.eclipse.emf.edit.provider.IChangeNotifier;
35 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
36 import org.eclipse.emf.edit.provider.IItemLabelProvider;
37 import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
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.ItemPropertyDescriptorDecorator;
42 import org.eclipse.emf.edit.provider.ItemProviderDecorator;
43 import org.eclipse.emf.mapping.MappedObjectState;
44 import org.eclipse.emf.mapping.Mapping;
45
46
47 /**
48  * This is the item provider adpater for a {@link org.eclipse.emf.mapping.Mapping} object.
49  */

50 public class MappedObjectItemProvider
51   extends
52     ItemProviderDecorator
53   implements
54     IEditingDomainItemProvider,
55     IStructuredItemContentProvider,
56     ITreeItemContentProvider,
57     IItemLabelProvider,
58     IItemPropertySource
59 {
60   protected Mapping mapping;
61   protected EObject mappedObject;
62   protected MappedObjectState mappedObjectState;
63
64   /**
65    * This constructs an instance from a factory and a notifier.
66    */

67   public MappedObjectItemProvider(AdapterFactory adapterFactory, EObject mappedObject, Mapping mapping)
68   {
69     super(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory());
70     setDecoratedItemProvider((IChangeNotifier)this.adapterFactory.adapt(mappedObject, IItemLabelProvider.class));
71     this.mappedObject = mappedObject;
72     this.mapping = mapping;
73
74     mappedObjectState = mapping.getMappingRoot().getMappedObjectState(mappedObject);
75     mappedObjectState.addListener(this);
76   }
77
78   /**
79    * This returns the nestedIn of the Mapping.
80    */

81   public Object JavaDoc getParent(Object JavaDoc object)
82   {
83     // Returning null here causes RemoveCommand.create(domain, mappedObjectItemProvider) to be delegated
84
// to MappedObjectItemProvider.createCommand() and there we return a command to remove mappedObject instead.
85
//
86
// return null;
87
return mapping;
88   }
89
90   public Collection JavaDoc getElements(Object JavaDoc object)
91   {
92     return Collections.EMPTY_LIST;
93   }
94
95   public Collection JavaDoc getChildren(Object JavaDoc object)
96   {
97     return Collections.EMPTY_LIST;
98   }
99
100   public boolean hasChildren(Object JavaDoc object)
101   {
102     return false;
103   }
104
105   public Object JavaDoc getImage(Object JavaDoc object)
106   {
107     return super.getImage(mappedObject);
108   }
109
110   public String JavaDoc getText(Object JavaDoc object)
111   {
112     return super.getText(mappedObject);
113   }
114
115   public List JavaDoc getPropertyDescriptors(Object JavaDoc object)
116   {
117     List JavaDoc descriptors = super.getPropertyDescriptors(mappedObject);
118
119     List JavaDoc result = new ArrayList JavaDoc();
120     for (int i = 0; i < descriptors.size(); ++i)
121     {
122       result.add(new ItemPropertyDescriptorDecorator(mappedObject, (IItemPropertyDescriptor)descriptors.get(i)));
123     }
124     return result;
125   }
126
127   public IItemPropertyDescriptor getPropertyDescriptor(Object JavaDoc object, Object JavaDoc propertyId)
128   {
129     IItemPropertyDescriptor descriptor = super.getPropertyDescriptor(mappedObject, propertyId);
130     if (descriptor != null)
131     {
132       return new ItemPropertyDescriptorDecorator(mappedObject, descriptor);
133     }
134     return null;
135   }
136
137   /**
138    * This handles notification by delegating to {@link #fireNotifyChanged fireNotifyChanged}.
139    */

140   public void notifyChanged(Notification msg)
141   {
142     if (msg.getFeature() == null)
143     {
144       Notification notification = new NotificationWrapper(this, msg);
145       super.notifyChanged(notification);
146     }
147     else
148     {
149       super.notifyChanged(msg);
150     }
151   }
152
153   public Command createCommand(Object JavaDoc object, EditingDomain editingDomain, Class JavaDoc commandClass, CommandParameter commandParameter)
154   {
155     if (commandClass == org.eclipse.emf.edit.command.DragAndDropCommand.class)
156     {
157       return super.createCommand(object, editingDomain, commandClass, commandParameter);
158     }
159     else
160     {
161       return UnexecutableCommand.INSTANCE;
162     }
163   }
164
165   public EObject getMappedObject()
166   {
167     return mappedObject;
168   }
169
170   public Mapping getMapping()
171   {
172     return mapping;
173   }
174
175   public void dispose()
176   {
177     mappedObjectState.removeListener(this);
178     super.dispose();
179   }
180 }
181
Popular Tags