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