KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > BrowserUIPlugin


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.ui;
22
23
24 import java.net.URL JavaDoc;
25
26 import org.eclipse.core.runtime.Path;
27 import org.eclipse.jface.resource.ImageDescriptor;
28 import org.eclipse.swt.graphics.Image;
29 import org.eclipse.ui.plugin.AbstractUIPlugin;
30 import org.osgi.framework.BundleContext;
31
32
33 /**
34  * The main plugin class to be used in the desktop.
35  */

36 public class BrowserUIPlugin extends AbstractUIPlugin
37 {
38
39     /** The plugin ID */
40     public static final String JavaDoc PLUGIN_ID = "org.apache.directory.ldapstudio.browser.ui";
41
42     /** The shared instance */
43     private static BrowserUIPlugin plugin;
44
45     
46     /**
47      * The constructor.
48      */

49     public BrowserUIPlugin()
50     {
51         plugin = this;
52     }
53
54
55     /**
56      * This method is called upon plug-in activation
57      */

58     public void start( BundleContext context ) throws Exception JavaDoc
59     {
60         super.start( context );
61     }
62
63
64     /**
65      * This method is called when the plug-in is stopped
66      */

67     public void stop( BundleContext context ) throws Exception JavaDoc
68     {
69         super.stop( context );
70         plugin = null;
71     }
72
73
74     /**
75      * Returns the shared instance.
76      */

77     public static BrowserUIPlugin getDefault()
78     {
79         return plugin;
80     }
81
82
83 // public static String getResourceString( String key )
84
// {
85
// ResourceBundle bundle = getDefault().getResourceBundle();
86
// try
87
// {
88
// return ( bundle != null ) ? bundle.getString( key ) : key;
89
// }
90
// catch ( MissingResourceException e )
91
// {
92
// return key;
93
// }
94
// }
95

96
97     /**
98      * Use this method to get SWT images. Use the IMG_ constants from
99      * BrowserUIConstants for the key.
100      *
101      * @param key
102      * The key (relative path to the image im filesystem)
103      * @return The image discriptor or null
104      */

105     public ImageDescriptor getImageDescriptor( String JavaDoc key )
106     {
107         if ( key != null )
108         {
109             URL JavaDoc url = this.find( new Path( key ) );
110             if ( url != null )
111                 return ImageDescriptor.createFromURL( url );
112             else
113                 return null;
114         }
115         else
116         {
117             return null;
118         }
119     }
120
121
122     /**
123      * Use this method to get SWT images. Use the IMG_ constants from
124      * BrowserUIConstants for the key. A ImageRegistry is used to manage the
125      * the key->Image mapping.
126      * <p>
127      * Note: Don't dispose the returned SWT Image. It is disposed
128      * automatically when the plugin is stopped.
129      *
130      * @param key
131      * The key (relative path to the image im filesystem)
132      * @return The SWT Image or null
133      * @see BrowserUIConstants
134      */

135     public Image getImage( String JavaDoc key )
136     {
137         Image image = getImageRegistry().get( key );
138         if ( image == null )
139         {
140             ImageDescriptor id = this.getImageDescriptor( key );
141             if ( id != null )
142             {
143                 image = id.createImage();
144                 getImageRegistry().put( key, image );
145             }
146         }
147         return image;
148     }
149
150 }
151
Popular Tags