1 | /* |
2 | *Copyright 2007, IPD, SDQ, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.repository.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.reliability.provider.ReliabilityItemProviderAdapterFactory; |
39 | import de.uka.ipd.sdq.pcm.repository.provider.RepositoryItemProviderAdapterFactory; |
40 | import de.uka.ipd.sdq.pcm.resourceenvironment.provider.ResourceenvironmentItemProviderAdapterFactory; |
41 | import de.uka.ipd.sdq.pcm.resourcetype.provider.ResourcetypeItemProviderAdapterFactory; |
42 | import de.uka.ipd.sdq.pcm.seff.provider.SeffItemProviderAdapterFactory; |
43 | import de.uka.ipd.sdq.pcm.seff.seff_performance.provider.Seff_performanceItemProviderAdapterFactory; |
44 | import de.uka.ipd.sdq.pcm.seff.seff_reliability.provider.Seff_reliabilityItemProviderAdapterFactory; |
45 | import de.uka.ipd.sdq.pcm.subsystem.provider.SubsystemItemProviderAdapterFactory; |
46 | import de.uka.ipd.sdq.pcm.system.provider.SystemItemProviderAdapterFactory; |
47 | import de.uka.ipd.sdq.pcm.usagemodel.provider.UsagemodelItemProviderAdapterFactory; |
48 | import de.uka.ipd.sdq.pcmbench.ui.provider.PalladioItemProviderAdapterFactory; |
49 | import de.uka.ipd.sdq.probfunction.provider.ProbfunctionItemProviderAdapterFactory; |
50 | import de.uka.ipd.sdq.stoex.provider.StoexItemProviderAdapterFactory; |
51 | import de.uka.ipd.sdq.units.provider.UnitsItemProviderAdapterFactory; |
52 | |
53 | /** |
54 | * @generated |
55 | */ |
56 | public class PalladioComponentModelRepositoryDiagramEditorPlugin extends |
57 | AbstractUIPlugin { |
58 | |
59 | /** |
60 | * @generated |
61 | */ |
62 | public static final String ID = "de.uka.ipd.sdq.pcm.gmf.repository"; //$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 PalladioComponentModelRepositoryDiagramEditorPlugin 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 PalladioComponentModelRepositoryDiagramEditorPlugin() { |
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 PalladioComponentModelRepositoryDiagramEditorPlugin 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 | return (PalladioItemProviderAdapterFactory) adapterFactory; |
130 | } |
131 | |
132 | }; |
133 | return new PalladioItemProviderAdapterFactory(caf); |
134 | } |
135 | |
136 | /** |
137 | * @generated |
138 | */ |
139 | protected void fillItemProviderFactories(List factories) { |
140 | factories.add(new PcmItemProviderAdapterFactory()); |
141 | factories.add(new CoreItemProviderAdapterFactory()); |
142 | factories.add(new EntityItemProviderAdapterFactory()); |
143 | factories.add(new CompositionItemProviderAdapterFactory()); |
144 | factories.add(new UsagemodelItemProviderAdapterFactory()); |
145 | factories.add(new RepositoryItemProviderAdapterFactory()); |
146 | factories.add(new ResourcetypeItemProviderAdapterFactory()); |
147 | factories.add(new ProtocolItemProviderAdapterFactory()); |
148 | factories.add(new ParameterItemProviderAdapterFactory()); |
149 | factories.add(new ReliabilityItemProviderAdapterFactory()); |
150 | factories.add(new SeffItemProviderAdapterFactory()); |
151 | factories |
152 | .add(new de.uka.ipd.sdq.pcm.seff.seff_performance.provider.Seff_performanceItemProviderAdapterFactory()); |
153 | factories |
154 | .add(new de.uka.ipd.sdq.pcm.seff.seff_reliability.provider.Seff_reliabilityItemProviderAdapterFactory()); |
155 | factories.add(new QosannotationsItemProviderAdapterFactory()); |
156 | factories |
157 | .add(new de.uka.ipd.sdq.pcm.qosannotations.qos_performance.provider.Qos_performanceItemProviderAdapterFactory()); |
158 | factories |
159 | .add(new de.uka.ipd.sdq.pcm.qosannotations.qos_reliability.provider.Qos_reliabilityItemProviderAdapterFactory()); |
160 | factories.add(new SystemItemProviderAdapterFactory()); |
161 | factories.add(new ResourceenvironmentItemProviderAdapterFactory()); |
162 | factories.add(new AllocationItemProviderAdapterFactory()); |
163 | factories.add(new SubsystemItemProviderAdapterFactory()); |
164 | factories.add(new IdentifierItemProviderAdapterFactory()); |
165 | factories.add(new ProbfunctionItemProviderAdapterFactory()); |
166 | factories.add(new StoexItemProviderAdapterFactory()); |
167 | factories.add(new UnitsItemProviderAdapterFactory()); |
168 | factories.add(new ResourceItemProviderAdapterFactory()); |
169 | factories.add(new ReflectiveItemProviderAdapterFactory()); |
170 | } |
171 | |
172 | /** |
173 | * @generated |
174 | */ |
175 | public AdapterFactory getItemProvidersAdapterFactory() { |
176 | return adapterFactory; |
177 | } |
178 | |
179 | /** |
180 | * @generated |
181 | */ |
182 | public ImageDescriptor getItemImageDescriptor(Object item) { |
183 | IItemLabelProvider labelProvider = (IItemLabelProvider) adapterFactory |
184 | .adapt(item, IItemLabelProvider.class); |
185 | if (labelProvider != null) { |
186 | return ExtendedImageRegistry.getInstance().getImageDescriptor( |
187 | labelProvider.getImage(item)); |
188 | } |
189 | return null; |
190 | } |
191 | |
192 | /** |
193 | * Returns an image descriptor for the image file at the given |
194 | * plug-in relative path. |
195 | * |
196 | * @generated |
197 | * @param path the path |
198 | * @return the image descriptor |
199 | */ |
200 | public static ImageDescriptor getBundledImageDescriptor(String path) { |
201 | return AbstractUIPlugin.imageDescriptorFromPlugin(ID, path); |
202 | } |
203 | |
204 | /** |
205 | * Respects images residing in any plug-in. If path is relative, |
206 | * then this bundle is looked up for the image, otherwise, for absolute |
207 | * path, first segment is taken as id of plug-in with image |
208 | * |
209 | * @generated |
210 | * @param path the path to image, either absolute (with plug-in id as first segment), or relative for bundled images |
211 | * @return the image descriptor |
212 | */ |
213 | public static ImageDescriptor findImageDescriptor(String path) { |
214 | final IPath p = new Path(path); |
215 | if (p.isAbsolute() && p.segmentCount() > 1) { |
216 | return AbstractUIPlugin.imageDescriptorFromPlugin(p.segment(0), p |
217 | .removeFirstSegments(1).makeAbsolute().toString()); |
218 | } else { |
219 | return getBundledImageDescriptor(p.makeAbsolute().toString()); |
220 | } |
221 | } |
222 | |
223 | /** |
224 | * Returns string from plug-in's resource bundle |
225 | * @generated |
226 | */ |
227 | public static String getString(String key) { |
228 | return Platform.getResourceString(getInstance().getBundle(), "%" + key); //$NON-NLS-1$ |
229 | } |
230 | |
231 | /** |
232 | * Returns an image for the image file at the given plug-in relative path. |
233 | * Client do not need to dispose this image. Images will be disposed automatically. |
234 | * |
235 | * @generated |
236 | * @param path the path |
237 | * @return image instance |
238 | */ |
239 | public Image getBundledImage(String path) { |
240 | Image image = getImageRegistry().get(path); |
241 | if (image == null) { |
242 | getImageRegistry().put(path, getBundledImageDescriptor(path)); |
243 | image = getImageRegistry().get(path); |
244 | } |
245 | return image; |
246 | } |
247 | |
248 | /** |
249 | * @generated |
250 | */ |
251 | public PalladioComponentModelDocumentProvider getDocumentProvider() { |
252 | if (documentProvider == null) { |
253 | documentProvider = new PalladioComponentModelDocumentProvider(); |
254 | } |
255 | return documentProvider; |
256 | } |
257 | |
258 | /** |
259 | * @generated |
260 | */ |
261 | public void logError(String error) { |
262 | logError(error, null); |
263 | } |
264 | |
265 | /** |
266 | * @param throwable actual error or null could be passed |
267 | * @generated |
268 | */ |
269 | public void logError(String error, Throwable throwable) { |
270 | if (error == null && throwable != null) { |
271 | error = throwable.getMessage(); |
272 | } |
273 | getLog().log( |
274 | new Status(IStatus.ERROR, |
275 | PalladioComponentModelRepositoryDiagramEditorPlugin.ID, |
276 | IStatus.OK, error, throwable)); |
277 | debug(error, throwable); |
278 | } |
279 | |
280 | /** |
281 | * @generated |
282 | */ |
283 | public void logInfo(String message) { |
284 | logInfo(message, null); |
285 | } |
286 | |
287 | /** |
288 | * @param throwable actual error or null could be passed |
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 | PalladioComponentModelRepositoryDiagramEditorPlugin.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 | } |