KickJava   Java API By Example, From Geeks To Geeks.

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


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: MappingItemProviderAdapterFactory.java,v 1.3 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
23 import org.eclipse.emf.common.notify.Adapter;
24 import org.eclipse.emf.common.notify.Notification;
25 import org.eclipse.emf.common.notify.Notifier;
26 import org.eclipse.emf.edit.provider.ChangeNotifier;
27 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
28 import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
29 import org.eclipse.emf.edit.provider.Disposable;
30 import org.eclipse.emf.edit.provider.IChangeNotifier;
31 import org.eclipse.emf.edit.provider.IDisposable;
32 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
33 import org.eclipse.emf.edit.provider.IItemLabelProvider;
34 import org.eclipse.emf.edit.provider.IItemPropertySource;
35 import org.eclipse.emf.edit.provider.INotifyChangedListener;
36 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
37 import org.eclipse.emf.edit.provider.ITableItemLabelProvider;
38 import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
39 import org.eclipse.emf.mapping.util.MappingAdapterFactory;
40
41
42 /**
43  * This is the factory that is used to provide the interfaces needed to support {@link org.eclipse.jface.viewers.Viewer}s.
44  * The adapters generated by this factory convert EMF adapter notifications into calls to {@link #fireNotifyChanged fireNotifyChanged}.
45  */

46 public class MappingItemProviderAdapterFactory
47   extends
48     MappingAdapterFactory
49   implements
50     ComposeableAdapterFactory,
51     IChangeNotifier,
52     IDisposable
53 {
54   /**
55    * This keeps track of the root adapter factory that delegates to this adapter factory
56    */

57   protected ComposedAdapterFactory parentAdapterFactory;
58
59   /**
60    * This is used to implement {@link IChangeNotifier}.
61    */

62   protected IChangeNotifier changeNotifier = new ChangeNotifier();
63
64   /**
65    * This is used to implement {@link IDisposable}.
66    */

67   protected Disposable disposable = new Disposable();
68
69   /**
70    * This keeps track of all the supported types checked by {@link #isFactoryForType isFactoryForType}.
71    */

72   protected Collection JavaDoc supportedTypes = new ArrayList JavaDoc();
73
74   /**
75    * This constructs an instance from a domain notifier.
76    */

77   public MappingItemProviderAdapterFactory()
78   {
79     supportedTypes.add(IStructuredItemContentProvider.class);
80     supportedTypes.add(ITreeItemContentProvider.class);
81     supportedTypes.add(IItemPropertySource.class);
82     supportedTypes.add(IEditingDomainItemProvider.class);
83     supportedTypes.add(IItemLabelProvider.class);
84     supportedTypes.add(ITableItemLabelProvider.class);
85
86     // This is here only to support deprecated adapt(object) rather than adapt(object, Interface.class).
87
//
88
// supportedTypes.add(null);
89

90     // supportedTypes.add(IUpdateableItemText.class);
91
}
92
93   /**
94    * This returns the root adapter factory that contains this factory.
95    */

96   public ComposeableAdapterFactory getRootAdapterFactory()
97   {
98     return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory();
99   }
100
101   /**
102    * This sets the composed adapter factory that contains this factory.
103    */

104   public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory)
105   {
106     this.parentAdapterFactory = parentAdapterFactory;
107   }
108
109   public boolean isFactoryForType(Object JavaDoc type)
110   {
111     return super.isFactoryForType(type) || supportedTypes.contains(type);
112   }
113
114   public Adapter adapt(Notifier notifier, Object JavaDoc type)
115   {
116     return super.adapt(notifier, this);
117   }
118
119   public Object JavaDoc adapt(Object JavaDoc object, Object JavaDoc type)
120   {
121     if (isFactoryForType(type))
122     {
123       Object JavaDoc adapter = super.adapt(object, type);
124       if (!(type instanceof Class JavaDoc) || (((Class JavaDoc)type).isInstance(adapter)))
125       {
126         return adapter;
127       }
128     }
129
130     return null;
131   }
132
133   public Adapter adaptNew(Notifier object, Object JavaDoc type)
134   {
135     Adapter result = super.adaptNew(object, type);
136     disposable.add(result);
137     return result;
138   }
139
140   /**
141    * This adds a listener.
142    */

143   public void addListener(INotifyChangedListener notifyChangedListener)
144   {
145     changeNotifier.addListener(notifyChangedListener);
146   }
147
148   /**
149    * This removes a listener.
150    */

151   public void removeListener(INotifyChangedListener notifyChangedListener)
152   {
153     changeNotifier.removeListener(notifyChangedListener);
154   }
155
156   /**
157    * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}.
158    */

159   public void fireNotifyChanged(Notification msg)
160   {
161      changeNotifier.fireNotifyChanged(msg);
162
163     if (parentAdapterFactory != null)
164     {
165       parentAdapterFactory.fireNotifyChanged(msg);
166     }
167   }
168
169   /**
170    * This keeps track of the one adapter used for all {@link org.eclipse.emf.mapping.MappingRoot} instances.
171    */

172   protected MappingRootItemProvider mappingRootItemProvider;
173
174   /**
175    * This creates an adapter for a {@link org.eclipse.emf.mapping.MappingRoot}.
176    */

177   public Adapter createMappingRootAdapter()
178   {
179     // EATM
180
// We want stateful ones.
181
// if (mappingRootItemProvider == null)
182
// {
183
// mappingRootItemProvider = new MappingRootItemProvider(this, domainNotifier);
184
// }
185

186     mappingRootItemProvider = new MappingRootItemProvider(this);
187
188     return mappingRootItemProvider;
189   }
190
191   /**
192    * This keeps track of the one adapter used for all {@link org.eclipse.emf.mapping.Mapping} instances.
193    */

194   protected MappingItemProvider mappingItemProvider;
195
196   /**
197    * This creates an adapter for a {@link org.eclipse.emf.mapping.Mapping}.
198    */

199   public Adapter createMappingAdapter()
200   {
201     // EATM
202
// We want stateful ones.
203
// if (mappingItemProvider == null)
204
// {
205
// mappingItemProvider = new MappingItemProvider(this);
206
// }
207

208     mappingItemProvider = new MappingItemProvider(this);
209
210     return mappingItemProvider;
211   }
212
213   /**
214    * This keeps track of the one adapter used for all {@link org.eclipse.emf.mapping.FunctionPair} instances.
215    */

216   protected FunctionPairItemProvider functionPairItemProvider;
217
218   /**
219    * This creates an adapter for a {@link org.eclipse.emf.mapping.FunctionPair}.
220    */

221   public Adapter createFunctionPairAdapter()
222   {
223     // if (functionPairItemProvider == null)
224
{
225       functionPairItemProvider = new FunctionPairItemProvider(this);
226     }
227
228     return functionPairItemProvider;
229   }
230
231   /**
232    * This keeps track of the one adapter used for all {@link org.eclipse.emf.mapping.TypeConverter} instances.
233    */

234   protected TypeConverterItemProvider typeConverterItemProvider;
235
236   /**
237    * This creates an adapter for a {@link org.eclipse.emf.mapping.TypeConverter}.
238    */

239   public Adapter createTypeConverterAdapter()
240   {
241     // if (typeConverterItemProvider == null)
242
{
243       typeConverterItemProvider = new TypeConverterItemProvider(this);
244     }
245
246     return typeConverterItemProvider;
247   }
248
249   /**
250    * This keeps track of the one adapter used for all {@link org.eclipse.emf.mapping.MappingHelper} instances.
251    */

252   protected MappingHelperItemProvider mappingHelperItemProvider;
253
254   /**
255    * This creates an adapter for a {@link org.eclipse.emf.mapping.MappingHelper}.
256    */

257   public Adapter createMappingHelperAdapter()
258   {
259     // if (mappingHelperItemProvider == null)
260
{
261       mappingHelperItemProvider = new MappingHelperItemProvider(this);
262     }
263
264     return mappingHelperItemProvider;
265   }
266
267   /**
268    * This keeps track of the one adapter used for all {@link org.eclipse.emf.mapping.MappingStrategy} instances.
269    */

270   protected MappingStrategyItemProvider mappingStrategyItemProvider;
271
272   /**
273    * This creates an adapter for a {@link org.eclipse.emf.mapping.MappingStrategy}.
274    */

275   public Adapter createMappingStrategyAdapter()
276   {
277     // if (mappingStrategyItemProvider == null)
278
{
279       mappingStrategyItemProvider = new MappingStrategyItemProvider(this);
280     }
281
282     return mappingStrategyItemProvider;
283   }
284
285   /**
286    * This keeps track of the one adapter used for all {@link org.eclipse.emf.mapping.FunctionNamePair} instances.
287    */

288   protected FunctionNamePairItemProvider functionNamePairItemProvider;
289
290   /**
291    * This creates an adapter for a {@link org.eclipse.emf.mapping.FunctionNamePair}.
292    */

293   public Adapter createFunctionNamePairAdapter()
294   {
295     // if (functionNamePairItemProvider == null)
296
{
297       functionNamePairItemProvider = new FunctionNamePairItemProvider(this);
298     }
299
300     return functionNamePairItemProvider;
301   }
302
303   /**
304    * This keeps track of the one adapter used for all {@link org.eclipse.emf.mapping.ComplexTypeConverter} instances.
305    */

306   protected ComplexTypeConverterItemProvider complexTypeConverterItemProvider;
307
308   /**
309    * This creates an adapter for a {@link org.eclipse.emf.mapping.ComplexTypeConverter}.
310    */

311   public Adapter createComplexTypeConverterAdapter()
312   {
313     // if (complexTypeConverterItemProvider == null)
314
{
315       complexTypeConverterItemProvider = new ComplexTypeConverterItemProvider(this);
316     }
317
318     return complexTypeConverterItemProvider;
319   }
320
321   public void dispose()
322   {
323     disposable.dispose();
324   }
325 }
326
Popular Tags