1 | /** |
2 | * Copyright 2005-2009 by SDQ, IPD, University of Karlsruhe, Germany |
3 | * |
4 | * $Id$ |
5 | */ |
6 | package de.uka.ipd.sdq.pcm.core.provider; |
7 | |
8 | import java.util.ArrayList; |
9 | import java.util.Collection; |
10 | |
11 | import org.eclipse.emf.common.notify.Adapter; |
12 | import org.eclipse.emf.common.notify.Notification; |
13 | import org.eclipse.emf.common.notify.Notifier; |
14 | import org.eclipse.emf.edit.provider.ChangeNotifier; |
15 | import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; |
16 | import org.eclipse.emf.edit.provider.ComposedAdapterFactory; |
17 | import org.eclipse.emf.edit.provider.IChangeNotifier; |
18 | import org.eclipse.emf.edit.provider.IDisposable; |
19 | import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; |
20 | import org.eclipse.emf.edit.provider.IItemLabelProvider; |
21 | import org.eclipse.emf.edit.provider.IItemPropertySource; |
22 | import org.eclipse.emf.edit.provider.INotifyChangedListener; |
23 | import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; |
24 | import org.eclipse.emf.edit.provider.ITreeItemContentProvider; |
25 | |
26 | import de.uka.ipd.sdq.pcm.core.util.CoreAdapterFactory; |
27 | |
28 | /** |
29 | * This is the factory that is used to provide the interfaces needed to support Viewers. |
30 | * The adapters generated by this factory convert EMF adapter notifications into calls to {@link #fireNotifyChanged fireNotifyChanged}. |
31 | * The adapters also support Eclipse property sheets. |
32 | * Note that most of the adapters are shared among multiple instances. |
33 | * <!-- begin-user-doc --> |
34 | * <!-- end-user-doc --> |
35 | * @generated |
36 | */ |
37 | public class CoreItemProviderAdapterFactory extends CoreAdapterFactory implements ComposeableAdapterFactory, IChangeNotifier, IDisposable { |
38 | /** |
39 | * <!-- begin-user-doc --> |
40 | * <!-- end-user-doc --> |
41 | * @generated |
42 | */ |
43 | public static final String copyright = "Copyright 2005-2009 by SDQ, IPD, University of Karlsruhe, Germany"; |
44 | |
45 | /** |
46 | * This keeps track of the root adapter factory that delegates to this adapter factory. |
47 | * <!-- begin-user-doc --> |
48 | * <!-- end-user-doc --> |
49 | * @generated |
50 | */ |
51 | protected ComposedAdapterFactory parentAdapterFactory; |
52 | |
53 | /** |
54 | * This is used to implement {@link org.eclipse.emf.edit.provider.IChangeNotifier}. |
55 | * <!-- begin-user-doc --> |
56 | * <!-- end-user-doc --> |
57 | * @generated |
58 | */ |
59 | protected IChangeNotifier changeNotifier = new ChangeNotifier(); |
60 | |
61 | /** |
62 | * This keeps track of all the supported types checked by {@link #isFactoryForType isFactoryForType}. |
63 | * <!-- begin-user-doc --> |
64 | * <!-- end-user-doc --> |
65 | * @generated |
66 | */ |
67 | protected Collection<Object> supportedTypes = new ArrayList<Object>(); |
68 | |
69 | /** |
70 | * This constructs an instance. |
71 | * <!-- begin-user-doc --> |
72 | * <!-- end-user-doc --> |
73 | * @generated |
74 | */ |
75 | public CoreItemProviderAdapterFactory() { |
76 | supportedTypes.add(IEditingDomainItemProvider.class); |
77 | supportedTypes.add(IStructuredItemContentProvider.class); |
78 | supportedTypes.add(ITreeItemContentProvider.class); |
79 | supportedTypes.add(IItemLabelProvider.class); |
80 | supportedTypes.add(IItemPropertySource.class); |
81 | } |
82 | |
83 | /** |
84 | * This keeps track of the one adapter used for all {@link de.uka.ipd.sdq.pcm.core.PCMRandomVariable} instances. |
85 | * <!-- begin-user-doc --> |
86 | * <!-- end-user-doc --> |
87 | * @generated |
88 | */ |
89 | protected PCMRandomVariableItemProvider pcmRandomVariableItemProvider; |
90 | |
91 | /** |
92 | * This creates an adapter for a {@link de.uka.ipd.sdq.pcm.core.PCMRandomVariable}. |
93 | * <!-- begin-user-doc --> |
94 | * <!-- end-user-doc --> |
95 | * @generated |
96 | */ |
97 | @Override |
98 | public Adapter createPCMRandomVariableAdapter() { |
99 | if (pcmRandomVariableItemProvider == null) { |
100 | pcmRandomVariableItemProvider = new PCMRandomVariableItemProvider(this); |
101 | } |
102 | |
103 | return pcmRandomVariableItemProvider; |
104 | } |
105 | |
106 | /** |
107 | * This returns the root adapter factory that contains this factory. |
108 | * <!-- begin-user-doc --> |
109 | * <!-- end-user-doc --> |
110 | * @generated |
111 | */ |
112 | public ComposeableAdapterFactory getRootAdapterFactory() { |
113 | return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory(); |
114 | } |
115 | |
116 | /** |
117 | * This sets the composed adapter factory that contains this factory. |
118 | * <!-- begin-user-doc --> |
119 | * <!-- end-user-doc --> |
120 | * @generated |
121 | */ |
122 | public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) { |
123 | this.parentAdapterFactory = parentAdapterFactory; |
124 | } |
125 | |
126 | /** |
127 | * <!-- begin-user-doc --> |
128 | * <!-- end-user-doc --> |
129 | * @generated |
130 | */ |
131 | @Override |
132 | public boolean isFactoryForType(Object type) { |
133 | return supportedTypes.contains(type) || super.isFactoryForType(type); |
134 | } |
135 | |
136 | /** |
137 | * This implementation substitutes the factory itself as the key for the adapter. |
138 | * <!-- begin-user-doc --> |
139 | * <!-- end-user-doc --> |
140 | * @generated |
141 | */ |
142 | @Override |
143 | public Adapter adapt(Notifier notifier, Object type) { |
144 | return super.adapt(notifier, this); |
145 | } |
146 | |
147 | /** |
148 | * <!-- begin-user-doc --> |
149 | * <!-- end-user-doc --> |
150 | * @generated |
151 | */ |
152 | @Override |
153 | public Object adapt(Object object, Object type) { |
154 | if (isFactoryForType(type)) { |
155 | Object adapter = super.adapt(object, type); |
156 | if (!(type instanceof Class<?>) || (((Class<?>)type).isInstance(adapter))) { |
157 | return adapter; |
158 | } |
159 | } |
160 | |
161 | return null; |
162 | } |
163 | |
164 | /** |
165 | * This adds a listener. |
166 | * <!-- begin-user-doc --> |
167 | * <!-- end-user-doc --> |
168 | * @generated |
169 | */ |
170 | public void addListener(INotifyChangedListener notifyChangedListener) { |
171 | changeNotifier.addListener(notifyChangedListener); |
172 | } |
173 | |
174 | /** |
175 | * This removes a listener. |
176 | * <!-- begin-user-doc --> |
177 | * <!-- end-user-doc --> |
178 | * @generated |
179 | */ |
180 | public void removeListener(INotifyChangedListener notifyChangedListener) { |
181 | changeNotifier.removeListener(notifyChangedListener); |
182 | } |
183 | |
184 | /** |
185 | * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}. |
186 | * <!-- begin-user-doc --> |
187 | * <!-- end-user-doc --> |
188 | * @generated |
189 | */ |
190 | public void fireNotifyChanged(Notification notification) { |
191 | changeNotifier.fireNotifyChanged(notification); |
192 | |
193 | if (parentAdapterFactory != null) { |
194 | parentAdapterFactory.fireNotifyChanged(notification); |
195 | } |
196 | } |
197 | |
198 | /** |
199 | * This disposes all of the item providers created by this factory. |
200 | * <!-- begin-user-doc --> |
201 | * <!-- end-user-doc --> |
202 | * @generated |
203 | */ |
204 | public void dispose() { |
205 | if (pcmRandomVariableItemProvider != null) pcmRandomVariableItemProvider.dispose(); |
206 | } |
207 | |
208 | } |