KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > valueeditors > ValueEditorsActivator


1 package org.apache.directory.ldapstudio.valueeditors;
2
3
4 import java.net.URL JavaDoc;
5
6 import org.eclipse.core.runtime.FileLocator;
7 import org.eclipse.core.runtime.Path;
8 import org.eclipse.jface.resource.ImageDescriptor;
9 import org.eclipse.swt.graphics.Image;
10 import org.eclipse.ui.plugin.AbstractUIPlugin;
11 import org.osgi.framework.BundleContext;
12
13
14 /**
15  * The activator class controls the plug-in life cycle
16  */

17 public class ValueEditorsActivator extends AbstractUIPlugin
18 {
19
20     /** The plug-in ID */
21     public static final String JavaDoc PLUGIN_ID = "org.apache.directory.ldapstudio.valueeditors";
22
23     /** The shared instance */
24     private static ValueEditorsActivator plugin;
25
26
27     /**
28      * The constructor
29      */

30     public ValueEditorsActivator()
31     {
32         plugin = this;
33     }
34
35
36     /**
37      * {@inheritDoc}
38      */

39     public void start( BundleContext context ) throws Exception JavaDoc
40     {
41         super.start( context );
42     }
43
44
45     /**
46      * {@inheritDoc}
47      */

48     public void stop( BundleContext context ) throws Exception JavaDoc
49     {
50         plugin = null;
51         super.stop( context );
52     }
53
54
55     /**
56      * Returns the shared instance
57      *
58      * @return the shared instance
59      */

60     public static ValueEditorsActivator getDefault()
61     {
62         return plugin;
63     }
64
65
66     /**
67      * Use this method to get SWT images. Use the IMG_ constants from
68      * ValueEditorConstants for the key.
69      *
70      * @param key
71      * The key (relative path to the image im filesystem)
72      * @return The image discriptor or null
73      */

74     public ImageDescriptor getImageDescriptor( String JavaDoc key )
75     {
76         if ( key != null )
77         {
78             URL JavaDoc url = FileLocator.find( getBundle(), new Path( key ), null );
79             if ( url != null )
80                 return ImageDescriptor.createFromURL( url );
81             else
82                 return null;
83         }
84         else
85         {
86             return null;
87         }
88     }
89
90
91     /**
92      * Use this method to get SWT images. Use the IMG_ constants from
93      * ValueEditorConstants for the key. A ImageRegistry is used to manage the
94      * the key->Image mapping.
95      * <p>
96      * Note: Don't dispose the returned SWT Image. It is disposed
97      * automatically when the plugin is stopped.
98      *
99      * @param key
100      * The key (relative path to the image im filesystem)
101      * @return The SWT Image or null
102      * @see ValueEditorsConstants
103      */

104     public Image getImage( String JavaDoc key )
105     {
106         Image image = getImageRegistry().get( key );
107         if ( image == null )
108         {
109             ImageDescriptor id = getImageDescriptor( key );
110             if ( id != null )
111             {
112                 image = id.createImage();
113                 getImageRegistry().put( key, image );
114             }
115         }
116         return image;
117     }
118     
119 }
120
Popular Tags