]> git.argeo.org Git - lgpl/argeo-commons.git/blob - demo/plugins/org.argeo.demo.i18n/src/main/java/org/argeo/demo/i18n/I18nDemoPlugin.java
Keyring login module
[lgpl/argeo-commons.git] / demo / plugins / org.argeo.demo.i18n / src / main / java / org / argeo / demo / i18n / I18nDemoPlugin.java
1 package org.argeo.demo.i18n;
2
3 import java.util.ResourceBundle;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.eclipse.jface.resource.ImageDescriptor;
8 import org.eclipse.ui.plugin.AbstractUIPlugin;
9 import org.osgi.framework.BundleContext;
10
11 /**
12 * The activator class controls the plug-in life cycle
13 */
14 public class I18nDemoPlugin extends AbstractUIPlugin {
15 private final static Log log = LogFactory.getLog(I18nDemoPlugin.class);
16 private ResourceBundle messages;
17
18 // The plug-in ID
19 public static final String ID = "org.argeo.demo.i18n"; //$NON-NLS-1$
20
21 // The shared instance
22 private static I18nDemoPlugin plugin;
23
24 /**
25 * The constructor
26 */
27 public I18nDemoPlugin() {
28 }
29
30 /*
31 * (non-Javadoc)
32 *
33 * @see
34 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
35 * )
36 */
37 public void start(BundleContext context) throws Exception {
38 super.start(context);
39 plugin = this;
40 messages = ResourceBundle.getBundle("org.argeo.demo.i18n.messages");
41 }
42
43 /*
44 * (non-Javadoc)
45 *
46 * @see
47 * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
48 * )
49 */
50 public void stop(BundleContext context) throws Exception {
51 plugin = null;
52 super.stop(context);
53 }
54
55 /**
56 * Returns the shared instance
57 *
58 * @return the shared instance
59 */
60 public static I18nDemoPlugin getDefault() {
61 return plugin;
62 }
63
64 public static ImageDescriptor getImageDescriptor(String path) {
65 return imageDescriptorFromPlugin(ID, path);
66 }
67
68 /** Returns the internationalized label for the given key */
69 public static String getMessage(String key) {
70 try {
71 return getDefault().messages.getString(key);
72 } catch (NullPointerException npe) {
73 log.warn(key + " not found.");
74 return key;
75 }
76 }
77
78 /**
79 * Gives access to the internationalization message bundle. Returns null in
80 * case the ClientUiPlugin is not started (for JUnit tests, by instance)
81 */
82 public static ResourceBundle getMessagesBundle() {
83 if (getDefault() != null)
84 // To avoid NPE
85 return getDefault().messages;
86 else
87 return null;
88 }
89 }