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