diff --git a/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/RSESamplesPlugin.html b/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/RSESamplesPlugin.html index 8a48717f16c..c5f37e115be 100755 --- a/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/RSESamplesPlugin.html +++ b/rse/doc/org.eclipse.rse.doc.isv/guide/tutorial/RSESamplesPlugin.html @@ -12,14 +12,14 @@
-package samples; +- ++package rsesamples; import java.util.MissingResourceException; import java.util.ResourceBundle; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Platform; import org.eclipse.rse.services.clientserver.messages.SystemMessage; import org.eclipse.rse.services.clientserver.messages.SystemMessageFile; import org.eclipse.rse.ui.SystemBasePlugin; @@ -28,114 +28,146 @@ import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ -public class RSESamplesPlugin extends SystemBasePlugin { +public class RSESamplesPlugin extends SystemBasePlugin { - //The shared instance. + // The plug-in ID + public static final String PLUGIN_ID = "RSESamples"; + + // The shared instance private static RSESamplesPlugin plugin; - - //Resource bundle. + + // ResourceBundle private ResourceBundle resourceBundle = null; - private static SystemMessageFile messageFile = null; + + // Message file + private SystemMessageFile messageFile = null; /** - * The constructor. + * The constructor */ public RSESamplesPlugin() { super(); } - /** - * This method is called upon plug-in activation + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ public void start(BundleContext context) throws Exception { super.start(context); - plugin = this; - messageFile = getMessageFile("rseSamplesMessages.xml"); + plugin = this; } - /** - * This method is called when the plug-in is stopped + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext context) throws Exception { - plugin = null; - resourceBundle = null; + plugin = null; super.stop(context); } - - /** - * Returns the shared instance. + + /* (non-Javadoc) + * @see org.eclipse.rse.ui.SystemBasePlugin#initializeImageRegistry() */ - public static RSESamplesPlugin getDefault() { - return plugin; - } - + protected void initializeImageRegistry() { + } + /** - * Returns the workspace instance. + * Retrieves the string resource bundle associated with this plugin. + * @return the ResourceBundle or null if the bundle could not be loaded. */ - public static IWorkspace getWorkspace() { - return ResourcesPlugin.getWorkspace(); - } - - /** - * Returns the string from the plugin's resource bundle, - * or 'key' if not found. - */ - public static String getResourceString(String key) { - ResourceBundle bundle= RSESamplesPlugin.getDefault().getResourceBundle(); + public ResourceBundle getResourceBundle() { try { - return (bundle != null) ? bundle.getString(key) : key; + if (resourceBundle == null) { + resourceBundle = ResourceBundle.getBundle("rseSamplesResources.properties"); + } } catch (MissingResourceException e) { - return key; - } - } - - /** - * Returns the plugin's resource bundle, - */ - public ResourceBundle getResourceBundle() { - try { - if (resourceBundle == null) - resourceBundle = ResourceBundle.getBundle("samples.rseSamplesResources"); - } catch (MissingResourceException x) { - resourceBundle = null; + SystemBasePlugin.logError("Missing rseSamplesResources.properties", e); } return resourceBundle; - } - - /** - * Initialize the image registry by declaring all of the required graphics. - */ - protected void initializeImageRegistry() - { } /** - * Load a message file for this plugin. - * @param messageFileName - the name of the message xml file. Will look for it in this plugin's install folder. - * @return a message file object containing the parsed contents of the message file, or null if not found. + * Retrieves the SystemMessageFile associated with this plugin. + * @return the SystemMessageFile or null if the message file + * could not be loaded. */ - public SystemMessageFile getMessageFile(String messageFileName) - { - return loadMessageFile(getBundle(), messageFileName); - } - - /** - * Return our message file - */ - public static SystemMessageFile getPluginMessageFile() - { + public SystemMessageFile getMessageFile() { + if (messageFile == null) { + messageFile = loadMessageFile(this.getBundle(), "rseSamplesMessages.xml"); //$NON-NLS-1$ + } return messageFile; - } + } /** - * Retrieve a message from this plugin's message file + * Retrieves the singleton workspace for this workbench. + * This is a convenience method, fully equivalent to + * ResourcesPlugin.getWorkspace(). + * @return the singleton workspace */ - public static SystemMessage getPluginMessage(String msgId) - { - return getMessage(messageFile, msgId); - } + public static IWorkspace getWorkspace() { + return ResourcesPlugin.getWorkspace(); + } + + /** + * Retrieve a string from the plugin's resource bundle. + * @param key the key to the string + * @return the retrieved string or the key if the string could not be + * found or the bundle could not be loaded. + */ + public static String getResourceString(String key) { + String result = null; + ResourceBundle bundle = RSESamplesPlugin.getDefault().getResourceBundle(); + if (bundle != null) { + try { + result = bundle.getString(key); + } catch (MissingResourceException e) { + SystemBasePlugin.logError("Missing key in bundle", e); + } + } + if (result == null) { + result = key; + } + return result; + } + + /** + * Retrieve the SystemMessageFile for this plugin. + * @return the SystemMessageFile or null if the message file + * could not be loaded. + */ + public static SystemMessageFile getPluginMessageFile() { + return RSESamplesPlugin.getDefault().getMessageFile(); + } + + /** + * Retrieve a SystemMessage from the message file for this + * plugin given its message id. + * @param messageId the message id to retrieve + * @return the retrieved SystemMessage or null if the message + * was not found in the message file or the message file + * could not be loaded. + */ + public static SystemMessage getPluginMessage(String messageId) { + SystemMessage message = null; + SystemMessageFile messageFile = getPluginMessageFile(); + if (messageFile != null) { + message = messageFile.getMessage(messageId); + } + return message; + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static RSESamplesPlugin getDefault() { + return plugin; + } + } -