1 | package org.modelica.mdt.ui; |
---|
2 | |
---|
3 | import org.eclipse.swt.widgets.Display; |
---|
4 | import org.eclipse.swt.widgets.Widget; |
---|
5 | import org.eclipse.ui.plugin.AbstractUIPlugin; |
---|
6 | import org.eclipse.core.runtime.IAdapterFactory; |
---|
7 | import org.eclipse.core.runtime.IAdapterManager; |
---|
8 | import org.eclipse.core.runtime.Platform; |
---|
9 | import org.modelica.mdt.core.IModelicaElement; |
---|
10 | import org.osgi.framework.BundleContext; |
---|
11 | |
---|
12 | /** |
---|
13 | * The main plugin class for the org.modelica.mdt.ui plugin |
---|
14 | */ |
---|
15 | public class UIPlugin extends AbstractUIPlugin |
---|
16 | { |
---|
17 | |
---|
18 | /* the shared instance */ |
---|
19 | private static UIPlugin plugin; |
---|
20 | |
---|
21 | public UIPlugin() |
---|
22 | { |
---|
23 | plugin = this; |
---|
24 | } |
---|
25 | |
---|
26 | /** |
---|
27 | * This method is called upon plug-in activation |
---|
28 | */ |
---|
29 | public void start(BundleContext context) throws Exception |
---|
30 | { |
---|
31 | super.start(context); |
---|
32 | |
---|
33 | IAdapterManager manager = Platform.getAdapterManager(); |
---|
34 | IAdapterFactory factory = new ModelicaElementAdapterFactory(); |
---|
35 | manager.registerAdapters(factory, IModelicaElement.class); |
---|
36 | } |
---|
37 | |
---|
38 | /** |
---|
39 | * This method is called when the plug-in is stopped |
---|
40 | */ |
---|
41 | public void stop(BundleContext context) throws Exception |
---|
42 | { |
---|
43 | super.stop(context); |
---|
44 | plugin = null; |
---|
45 | } |
---|
46 | |
---|
47 | /** |
---|
48 | * Returns the shared instance. |
---|
49 | */ |
---|
50 | public static UIPlugin getDefault() |
---|
51 | { |
---|
52 | return plugin; |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * Returns the standard display to be used. The method first checks, if |
---|
57 | * the thread calling this method has an associated display. If so, this |
---|
58 | * display is returned. Otherwise the method returns the default display. |
---|
59 | */ |
---|
60 | public static Display getStandardDisplay() |
---|
61 | { |
---|
62 | Display display; |
---|
63 | display = Display.getCurrent(); |
---|
64 | if (display == null) |
---|
65 | display = Display.getDefault(); |
---|
66 | return display; |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * @return returns this plugins symbolic name e.g. stuff like org.foo.bar |
---|
71 | */ |
---|
72 | public static String getSymbolicName() |
---|
73 | { |
---|
74 | return getDefault().getBundle().getSymbolicName(); |
---|
75 | } |
---|
76 | |
---|
77 | /** |
---|
78 | * set an abbot tag, used by GUI regressions tests to find |
---|
79 | * specific widgets. |
---|
80 | * |
---|
81 | * @param widget the widget to tag |
---|
82 | * @param tag the tag to set |
---|
83 | */ |
---|
84 | public static void tag(Widget widget, String tag) |
---|
85 | { |
---|
86 | widget.setData("name", tag); |
---|
87 | } |
---|
88 | } |
---|