KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > EditorPlugin


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * Project author: Daniel Mazurek <Daniel.Mazurek [at] nightlabs [dot] org> *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin St, Fifth Floor, *
20  * Boston, MA 02110-1301 USA *
21  * *
22  * Or get it online : *
23  * http://www.gnu.org/copyleft/lesser.html *
24  * *
25  * *
26  ******************************************************************************/

27
28 package org.nightlabs.editor2d;
29
30 import org.eclipse.core.runtime.Platform;
31 import org.eclipse.ui.plugin.*;
32 import org.osgi.framework.BundleContext;
33 import java.util.*;
34
35 /**
36  * The main plugin class to be used in the desktop.
37  */

38 public class EditorPlugin
39 extends AbstractUIPlugin
40 {
41     //The shared instance.
42
private static EditorPlugin plugin;
43     //Resource bundle.
44
private static ResourceBundle resourceBundle;
45     
46     public static String JavaDoc PLUGIN_ID = "org.nightlabs.editor2d";
47     
48     /**
49      * The constructor.
50      */

51     public EditorPlugin()
52     {
53         super();
54         plugin = this;
55     }
56
57     /**
58      * This method is called upon plug-in activation
59      */

60     public void start(BundleContext context) throws Exception JavaDoc
61     {
62         super.start(context);
63         resourceBundle = Platform.getResourceBundle(getBundle());
64     }
65
66     /**
67      * This method is called when the plug-in is stopped
68      */

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

79     public static EditorPlugin getDefault() {
80         return plugin;
81     }
82
83     /**
84      * Returns a string from the resource bundle, knowing its key. Note: the generated
85      * code is not strong enough because a NullPointerException is raised if there is no
86      * resource bundle, instead of 'key' to be returned for consistency.
87      *
88      * @return The string from the plugin's resource bundle, or 'key' if not found.
89      */

90     public static String JavaDoc getResourceString(String JavaDoc key) {
91         try {
92             return resourceBundle.getString(key);
93         } catch (Exception JavaDoc e) {
94             return key;
95         }
96     }
97
98     /**
99      * Returns the plugin's resource bundle. Note that for this plugin, the resource
100      * bundle is the same as the plugin descriptor resource bundle.
101      *
102      * @return The plugin's resource bundle
103      */

104     public ResourceBundle getResourceBundle() {
105         return resourceBundle;
106     }
107     
108 // /**
109
// * Returns the string from the plugin's resource bundle,
110
// * or 'key' if not found.
111
// */
112
// public static String getResourceString(String key) {
113
// ResourceBundle bundle = EditorPlugin.getDefault().getResourceBundle();
114
// try {
115
// return (bundle != null) ? bundle.getString(key) : key;
116
// } catch (MissingResourceException e) {
117
// return key;
118
// }
119
// }
120
//
121
// /**
122
// * Returns the plugin's resource bundle,
123
// */
124
// public ResourceBundle getResourceBundle()
125
// {
126
// if (resourceBundle == null)
127
// {
128
// try {
129
// resourceBundle = ResourceBundle.getBundle("org.nightlabs.editor2d.plugin");
130
// } catch (MissingResourceException x) {
131
// resourceBundle = null;
132
// }
133
// }
134
// return resourceBundle;
135
// }
136
}
137
Popular Tags