KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > edit > provider > resource > ResourceItemProviderAdapterFactory


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: ResourceItemProviderAdapterFactory.java,v 1.3 2005/06/08 06:17:06 nickb Exp $
16  */

17 package org.eclipse.emf.edit.provider.resource;
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.common.notify.impl.AdapterFactoryImpl;
27 import org.eclipse.emf.ecore.EObject;
28 import org.eclipse.emf.ecore.resource.Resource;
29 import org.eclipse.emf.ecore.resource.ResourceSet;
30 import org.eclipse.emf.edit.provider.ChangeNotifier;
31 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
32 import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
33 import org.eclipse.emf.edit.provider.Disposable;
34 import org.eclipse.emf.edit.provider.IChangeNotifier;
35 import org.eclipse.emf.edit.provider.IDisposable;
36 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
37 import org.eclipse.emf.edit.provider.IItemLabelProvider;
38 import org.eclipse.emf.edit.provider.IItemPropertySource;
39 import org.eclipse.emf.edit.provider.INotifyChangedListener;
40 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
41 import org.eclipse.emf.edit.provider.ITableItemLabelProvider;
42 import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
43
44
45 /**
46  * This is the factory that is used to provide the interfaces needed to support Viewers.
47  * The adapters generated by this factory convert EMF adapter notifications into calls to {@link #fireNotifyChanged fireNotifyChanged}.
48  * The adapters also support Eclipse property sheets.
49  * Note that most of the adapters are shared among multiple instances.
50  * @generated
51  */

52 public class ResourceItemProviderAdapterFactory
53   extends AdapterFactoryImpl
54   implements ComposeableAdapterFactory, IChangeNotifier, IDisposable
55 {
56   protected static Package JavaDoc resourcePackage = Resource.class.getPackage();
57
58   /**
59    * This keeps track of the root adapter factory that delegates to this adapter factory.
60    * @generated
61    */

62   protected ComposedAdapterFactory parentAdapterFactory;
63
64   /**
65    * This is used to implement {@link org.eclipse.emf.edit.provider.IChangeNotifier}.
66    * @generated
67    */

68   protected IChangeNotifier changeNotifier = new ChangeNotifier();
69
70   /**
71    * This keeps track of all the supported types checked by {@link #isFactoryForType isFactoryForType}.
72    * @generated
73    */

74   protected Collection JavaDoc supportedTypes = new ArrayList JavaDoc();
75
76   /**
77    * This is used to implement {@link org.eclipse.emf.edit.provider.IDisposable}.
78    */

79   protected Disposable disposable = new Disposable();
80
81   /**
82    * This constructs an instance.
83    * @generated
84    */

85   public ResourceItemProviderAdapterFactory()
86   {
87     supportedTypes.add(IStructuredItemContentProvider.class);
88     supportedTypes.add(ITreeItemContentProvider.class);
89     supportedTypes.add(IItemPropertySource.class);
90     supportedTypes.add(IEditingDomainItemProvider.class);
91     supportedTypes.add(IItemLabelProvider.class);
92     supportedTypes.add(ITableItemLabelProvider.class);
93   }
94
95   public Adapter createAdapter(Notifier target)
96   {
97     if (target instanceof Resource)
98     {
99       return createResourceAdapter();
100     }
101     else
102     {
103       return createResourceSetAdapter();
104     }
105   }
106
107   /**
108    * This creates an adapter for a {@link org.eclipse.emf.ecore.resource.Resource}.
109    * @generated
110    */

111   public Adapter createResourceAdapter()
112   {
113     return new ResourceItemProvider(this);
114   }
115
116   /**
117    * This creates an adapter for a {@link org.eclipse.emf.ecore.resource.ResourceSet}.
118    * @generated
119    */

120   public Adapter createResourceSetAdapter()
121   {
122     return new ResourceSetItemProvider(this);
123   }
124
125   /**
126    * This returns the root adapter factory that contains this factory.
127    * @generated
128    */

129   public ComposeableAdapterFactory getRootAdapterFactory()
130   {
131     return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory();
132   }
133
134   /**
135    * This sets the composed adapter factory that contains this factory.
136    * @generated
137    */

138   public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory)
139   {
140     this.parentAdapterFactory = parentAdapterFactory;
141   }
142
143   /**
144    * Returns whether this factory is applicable for the type of the object.
145    * <!-- begin-user-doc -->
146    * This implementation returns <code>true</code> if the object is either the model's package or is an instance object of the model.
147    * <!-- end-user-doc -->
148    * @return whether this factory is applicable for the type of the object.
149    * @generated
150    */

151   public boolean isFactoryForType(Object JavaDoc type)
152   {
153     return type == resourcePackage || type instanceof Resource || type instanceof ResourceSet || supportedTypes.contains(type);
154   }
155
156   /**
157    * This implementation substitutes the factory itself as the key for the adapter.
158    * @generated
159    */

160   public Adapter adapt(Notifier notifier, Object JavaDoc type)
161   {
162     return super.adapt(notifier, this);
163   }
164
165   /**
166    * @generated
167    */

168   public Object JavaDoc adapt(Object JavaDoc object, Object JavaDoc type)
169   {
170     // This is a kludge to deal with enumerators, which crash the doSwitch.
171
//
172
if (object instanceof EObject && ((EObject)object).eClass() == null)
173     {
174       return null;
175     }
176
177     if (isFactoryForType(type))
178     {
179       Object JavaDoc adapter = super.adapt(object, type);
180       if (!(type instanceof Class JavaDoc) || (((Class JavaDoc)type).isInstance(adapter)))
181       {
182         return adapter;
183       }
184     }
185
186     return null;
187   }
188
189   /**
190    * This adds a listener.
191    * @generated
192    */

193   public void addListener(INotifyChangedListener notifyChangedListener)
194   {
195     changeNotifier.addListener(notifyChangedListener);
196   }
197
198   /**
199    * This removes a listener.
200    * @generated
201    */

202   public void removeListener(INotifyChangedListener notifyChangedListener)
203   {
204     changeNotifier.removeListener(notifyChangedListener);
205   }
206
207   /**
208    * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}.
209    * @generated
210    */

211   public void fireNotifyChanged(Notification notification)
212   {
213     changeNotifier.fireNotifyChanged(notification);
214
215     if (parentAdapterFactory != null)
216     {
217       parentAdapterFactory.fireNotifyChanged(notification);
218     }
219   }
220
221   protected void associate(Adapter adapter, Notifier target)
222   {
223     super.associate(adapter, target);
224     if (adapter != null)
225     {
226       disposable.add(adapter);
227     }
228   }
229   
230   public void dispose()
231   {
232     disposable.dispose();
233   }
234 }
235
Popular Tags