1 | /* |
2 | * Copyright 2009, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.resource.part; |
5 | |
6 | import java.util.ArrayList; |
7 | import java.util.List; |
8 | |
9 | import org.eclipse.core.runtime.IPath; |
10 | import org.eclipse.core.runtime.IStatus; |
11 | import org.eclipse.core.runtime.Path; |
12 | import org.eclipse.core.runtime.Platform; |
13 | import org.eclipse.core.runtime.Status; |
14 | import org.eclipse.emf.common.notify.AdapterFactory; |
15 | import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; |
16 | import org.eclipse.emf.edit.provider.ComposedAdapterFactory; |
17 | import org.eclipse.emf.edit.provider.IItemLabelProvider; |
18 | import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; |
19 | import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory; |
20 | import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry; |
21 | import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint; |
22 | import org.eclipse.jface.resource.ImageDescriptor; |
23 | import org.eclipse.swt.graphics.Image; |
24 | import org.eclipse.ui.plugin.AbstractUIPlugin; |
25 | import org.osgi.framework.BundleContext; |
26 | |
27 | import de.uka.ipd.sdq.identifier.provider.IdentifierItemProviderAdapterFactory; |
28 | import de.uka.ipd.sdq.pcm.allocation.provider.AllocationItemProviderAdapterFactory; |
29 | import de.uka.ipd.sdq.pcm.core.composition.provider.CompositionItemProviderAdapterFactory; |
30 | |
31 | import de.uka.ipd.sdq.pcm.core.entity.provider.EntityItemProviderAdapterFactory; |
32 | import de.uka.ipd.sdq.pcm.core.provider.CoreItemProviderAdapterFactory; |
33 | import de.uka.ipd.sdq.pcm.parameter.provider.ParameterItemProviderAdapterFactory; |
34 | import de.uka.ipd.sdq.pcm.protocol.provider.ProtocolItemProviderAdapterFactory; |
35 | import de.uka.ipd.sdq.pcm.provider.PcmItemProviderAdapterFactory; |
36 | import de.uka.ipd.sdq.pcm.qosannotations.provider.QosannotationsItemProviderAdapterFactory; |
37 | import de.uka.ipd.sdq.pcm.qosannotations.qos_performance.provider.Qos_performanceItemProviderAdapterFactory; |
38 | import de.uka.ipd.sdq.pcm.qosannotations.qos_reliability.provider.Qos_reliabilityItemProviderAdapterFactory; |
39 | import de.uka.ipd.sdq.pcm.reliability.provider.ReliabilityItemProviderAdapterFactory; |
40 | import de.uka.ipd.sdq.pcm.repository.provider.RepositoryItemProviderAdapterFactory; |
41 | import de.uka.ipd.sdq.pcm.resourceenvironment.provider.ResourceenvironmentItemProviderAdapterFactory; |
42 | import de.uka.ipd.sdq.pcm.resourcetype.provider.ResourcetypeItemProviderAdapterFactory; |
43 | import de.uka.ipd.sdq.pcm.seff.provider.SeffItemProviderAdapterFactory; |
44 | import de.uka.ipd.sdq.pcm.seff.seff_performance.provider.Seff_performanceItemProviderAdapterFactory; |
45 | import de.uka.ipd.sdq.pcm.seff.seff_reliability.provider.Seff_reliabilityItemProviderAdapterFactory; |
46 | import de.uka.ipd.sdq.pcm.subsystem.provider.SubsystemItemProviderAdapterFactory; |
47 | import de.uka.ipd.sdq.pcm.system.provider.SystemItemProviderAdapterFactory; |
48 | import de.uka.ipd.sdq.pcm.usagemodel.provider.UsagemodelItemProviderAdapterFactory; |
49 | import de.uka.ipd.sdq.pcmbench.ui.provider.PalladioItemProviderAdapterFactory; |
50 | import de.uka.ipd.sdq.probfunction.provider.ProbfunctionItemProviderAdapterFactory; |
51 | import de.uka.ipd.sdq.stoex.provider.StoexItemProviderAdapterFactory; |
52 | import de.uka.ipd.sdq.units.provider.UnitsItemProviderAdapterFactory; |
53 | |
54 | /** |
55 | * @generated |
56 | */ |
57 | public class PalladioComponentModelDiagramEditorPlugin extends AbstractUIPlugin { |
58 | |
59 | /** |
60 | * @generated |
61 | */ |
62 | public static final String ID = "de.uka.ipd.sdq.pcm.gmf.resource"; //$NON-NLS-1$ |
63 | |
64 | /** |
65 | * @generated |
66 | */ |
67 | public static final PreferencesHint DIAGRAM_PREFERENCES_HINT = new PreferencesHint( |
68 | ID); |
69 | |
70 | /** |
71 | * @generated |
72 | */ |
73 | private static PalladioComponentModelDiagramEditorPlugin instance; |
74 | |
75 | /** |
76 | * @generated not |
77 | */ |
78 | private AdapterFactory adapterFactory; |
79 | |
80 | /** |
81 | * @generated |
82 | */ |
83 | private PalladioComponentModelDocumentProvider documentProvider; |
84 | |
85 | /** |
86 | * @generated |
87 | */ |
88 | public PalladioComponentModelDiagramEditorPlugin() { |
89 | } |
90 | |
91 | /** |
92 | * @generated |
93 | */ |
94 | public void start(BundleContext context) throws Exception { |
95 | super.start(context); |
96 | instance = this; |
97 | PreferencesHint.registerPreferenceStore(DIAGRAM_PREFERENCES_HINT, |
98 | getPreferenceStore()); |
99 | adapterFactory = createAdapterFactory(); |
100 | } |
101 | |
102 | /** |
103 | * @generated not |
104 | */ |
105 | public void stop(BundleContext context) throws Exception { |
106 | ((PalladioItemProviderAdapterFactory) adapterFactory).dispose(); |
107 | adapterFactory = null; |
108 | instance = null; |
109 | super.stop(context); |
110 | } |
111 | |
112 | /** |
113 | * @generated |
114 | */ |
115 | public static PalladioComponentModelDiagramEditorPlugin getInstance() { |
116 | return instance; |
117 | } |
118 | |
119 | /** |
120 | * @generated not |
121 | */ |
122 | protected AdapterFactory createAdapterFactory() { |
123 | List factories = new ArrayList(); |
124 | fillItemProviderFactories(factories); |
125 | ComposedAdapterFactory caf = new ComposedAdapterFactory(factories) { |
126 | |
127 | @Override |
128 | public ComposeableAdapterFactory getRootAdapterFactory() { |
129 | // TODO Auto-generated method stub |
130 | return (PalladioItemProviderAdapterFactory) adapterFactory; |
131 | } |
132 | |
133 | }; |
134 | return new PalladioItemProviderAdapterFactory(caf); |
135 | } |
136 | |
137 | /** |
138 | * @generated |
139 | */ |
140 | protected void fillItemProviderFactories(List factories) { |
141 | factories.add(new PcmItemProviderAdapterFactory()); |
142 | factories.add(new CoreItemProviderAdapterFactory()); |
143 | factories.add(new EntityItemProviderAdapterFactory()); |
144 | factories.add(new CompositionItemProviderAdapterFactory()); |
145 | factories.add(new UsagemodelItemProviderAdapterFactory()); |
146 | factories.add(new RepositoryItemProviderAdapterFactory()); |
147 | factories.add(new ResourcetypeItemProviderAdapterFactory()); |
148 | factories.add(new ProtocolItemProviderAdapterFactory()); |
149 | factories.add(new ParameterItemProviderAdapterFactory()); |
150 | factories.add(new ReliabilityItemProviderAdapterFactory()); |
151 | factories.add(new SeffItemProviderAdapterFactory()); |
152 | factories |
153 | .add(new de.uka.ipd.sdq.pcm.seff.seff_performance.provider.Seff_performanceItemProviderAdapterFactory()); |
154 | factories |
155 | .add(new de.uka.ipd.sdq.pcm.seff.seff_reliability.provider.Seff_reliabilityItemProviderAdapterFactory()); |
156 | factories.add(new QosannotationsItemProviderAdapterFactory()); |
157 | factories |
158 | .add(new de.uka.ipd.sdq.pcm.qosannotations.qos_performance.provider.Qos_performanceItemProviderAdapterFactory()); |
159 | factories |
160 | .add(new de.uka.ipd.sdq.pcm.qosannotations.qos_reliability.provider.Qos_reliabilityItemProviderAdapterFactory()); |
161 | factories.add(new SystemItemProviderAdapterFactory()); |
162 | factories.add(new ResourceenvironmentItemProviderAdapterFactory()); |
163 | factories.add(new AllocationItemProviderAdapterFactory()); |
164 | factories.add(new SubsystemItemProviderAdapterFactory()); |
165 | factories.add(new IdentifierItemProviderAdapterFactory()); |
166 | factories.add(new ProbfunctionItemProviderAdapterFactory()); |
167 | factories.add(new StoexItemProviderAdapterFactory()); |
168 | factories.add(new UnitsItemProviderAdapterFactory()); |
169 | factories.add(new ResourceItemProviderAdapterFactory()); |
170 | factories.add(new ReflectiveItemProviderAdapterFactory()); |
171 | } |
172 | |
173 | /** |
174 | * @generated |
175 | */ |
176 | public AdapterFactory getItemProvidersAdapterFactory() { |
177 | return adapterFactory; |
178 | } |
179 | |
180 | /** |
181 | * @generated |
182 | */ |
183 | public ImageDescriptor getItemImageDescriptor(Object item) { |
184 | IItemLabelProvider labelProvider = (IItemLabelProvider) adapterFactory |
185 | .adapt(item, IItemLabelProvider.class); |
186 | if (labelProvider != null) { |
187 | return ExtendedImageRegistry.getInstance().getImageDescriptor( |
188 | labelProvider.getImage(item)); |
189 | } |
190 | return null; |
191 | } |
192 | |
193 | /** |
194 | * Returns an image descriptor for the image file at the given |
195 | * plug-in relative path. |
196 | * |
197 | * @generated |
198 | * @param path the path |
199 | * @return the image descriptor |
200 | */ |
201 | public static ImageDescriptor getBundledImageDescriptor(String path) { |
202 | return AbstractUIPlugin.imageDescriptorFromPlugin(ID, path); |
203 | } |
204 | |
205 | /** |
206 | * Respects images residing in any plug-in. If path is relative, |
207 | * then this bundle is looked up for the image, otherwise, for absolute |
208 | * path, first segment is taken as id of plug-in with image |
209 | * |
210 | * @generated |
211 | * @param path the path to image, either absolute (with plug-in id as first segment), or relative for bundled images |
212 | * @return the image descriptor |
213 | */ |
214 | public static ImageDescriptor findImageDescriptor(String path) { |
215 | final IPath p = new Path(path); |
216 | if (p.isAbsolute() && p.segmentCount() > 1) { |
217 | return AbstractUIPlugin.imageDescriptorFromPlugin(p.segment(0), p |
218 | .removeFirstSegments(1).makeAbsolute().toString()); |
219 | } else { |
220 | return getBundledImageDescriptor(p.makeAbsolute().toString()); |
221 | } |
222 | } |
223 | |
224 | /** |
225 | * Returns an image for the image file at the given plug-in relative path. |
226 | * Client do not need to dispose this image. Images will be disposed automatically. |
227 | * |
228 | * @generated |
229 | * @param path the path |
230 | * @return image instance |
231 | */ |
232 | public Image getBundledImage(String path) { |
233 | Image image = getImageRegistry().get(path); |
234 | if (image == null) { |
235 | getImageRegistry().put(path, getBundledImageDescriptor(path)); |
236 | image = getImageRegistry().get(path); |
237 | } |
238 | return image; |
239 | } |
240 | |
241 | /** |
242 | * Returns string from plug-in's resource bundle |
243 | * |
244 | * @generated |
245 | */ |
246 | public static String getString(String key) { |
247 | return Platform.getResourceString(getInstance().getBundle(), "%" + key); //$NON-NLS-1$ |
248 | } |
249 | |
250 | /** |
251 | * @generated |
252 | */ |
253 | public PalladioComponentModelDocumentProvider getDocumentProvider() { |
254 | if (documentProvider == null) { |
255 | documentProvider = new PalladioComponentModelDocumentProvider(); |
256 | } |
257 | return documentProvider; |
258 | } |
259 | |
260 | /** |
261 | * @generated |
262 | */ |
263 | public void logError(String error) { |
264 | logError(error, null); |
265 | } |
266 | |
267 | /** |
268 | * @generated |
269 | */ |
270 | public void logError(String error, Throwable throwable) { |
271 | if (error == null && throwable != null) { |
272 | error = throwable.getMessage(); |
273 | } |
274 | getLog().log( |
275 | new Status(IStatus.ERROR, |
276 | PalladioComponentModelDiagramEditorPlugin.ID, |
277 | IStatus.OK, error, throwable)); |
278 | debug(error, throwable); |
279 | } |
280 | |
281 | /** |
282 | * @generated |
283 | */ |
284 | public void logInfo(String message) { |
285 | logInfo(message, null); |
286 | } |
287 | |
288 | /** |
289 | * @generated |
290 | */ |
291 | public void logInfo(String message, Throwable throwable) { |
292 | if (message == null && throwable != null) { |
293 | message = throwable.getMessage(); |
294 | } |
295 | getLog().log( |
296 | new Status(IStatus.INFO, |
297 | PalladioComponentModelDiagramEditorPlugin.ID, |
298 | IStatus.OK, message, throwable)); |
299 | debug(message, throwable); |
300 | } |
301 | |
302 | /** |
303 | * @generated |
304 | */ |
305 | private void debug(String message, Throwable throwable) { |
306 | if (!isDebugging()) { |
307 | return; |
308 | } |
309 | if (message != null) { |
310 | System.err.println(message); |
311 | } |
312 | if (throwable != null) { |
313 | throwable.printStackTrace(); |
314 | } |
315 | } |
316 | } |