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