]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/Activator.java
Sync git svn branch with SVN repository r33290.
[simantics/platform.git] / bundles / org.simantics.tests.modelled.ui / src / org / simantics / tests / modelled / ui / Activator.java
1 package org.simantics.tests.modelled.ui;\r
2 \r
3 import java.net.URL;\r
4 import java.util.ArrayList;\r
5 import java.util.List;\r
6 \r
7 import org.eclipse.jface.resource.ImageDescriptor;\r
8 import org.eclipse.swt.graphics.Image;\r
9 import org.eclipse.ui.plugin.AbstractUIPlugin;\r
10 import org.osgi.framework.BundleContext;\r
11 \r
12 /**\r
13  * The activator class controls the plug-in life cycle\r
14  */\r
15 public class Activator extends AbstractUIPlugin {\r
16 \r
17         // The plug-in ID\r
18         public static final String PLUGIN_ID = "org.simantics.tests.modelled.ui"; //$NON-NLS-1$\r
19 \r
20         // The shared instance\r
21         private static Activator plugin;\r
22         \r
23         /**\r
24          * The constructor\r
25          */\r
26         public Activator() {\r
27         }\r
28 \r
29         /*\r
30          * (non-Javadoc)\r
31          * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)\r
32          */\r
33         public void start(BundleContext context) throws Exception {\r
34                 super.start(context);\r
35                 plugin = this;\r
36         }\r
37 \r
38         /*\r
39          * (non-Javadoc)\r
40          * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)\r
41          */\r
42         public void stop(BundleContext context) throws Exception {\r
43                 plugin = null;\r
44                 for (Image image : imagesToDispose)\r
45                     image.dispose();\r
46                 super.stop(context);\r
47         }\r
48 \r
49         /**\r
50          * Returns the shared instance\r
51          *\r
52          * @return the shared instance\r
53          */\r
54         public static Activator getDefault() {\r
55                 return plugin;\r
56         }\r
57 \r
58     public static ImageDescriptor getImageDescriptor(String relativePath) {\r
59         URL url = getDefault().getBundle().getEntry(relativePath);\r
60         return ImageDescriptor.createFromURL(url);\r
61     }\r
62     \r
63     private static List<Image> imagesToDispose = new ArrayList<>();\r
64 \r
65     public static Image createManagedImage(ImageDescriptor descriptor) {\r
66         Image image= descriptor.createImage();\r
67         if (image == null) {\r
68             image= ImageDescriptor.getMissingImageDescriptor().createImage();\r
69         }\r
70         imagesToDispose.add(image);\r
71         return image;\r
72     }\r
73 }\r