package org.hibernate.eclipse.console.test; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.MissingResourceException; import java.util.ResourceBundle; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The main plugin class to be used in the desktop. */ public class HibernateConsoleTestPlugin extends AbstractUIPlugin { //The shared instance. private static HibernateConsoleTestPlugin plugin; //Resource bundle. private ResourceBundle resourceBundle; /** * The constructor. */ public HibernateConsoleTestPlugin() { setPlugin(this); } /** * This method is called upon plug-in activation */ public void start(BundleContext context) throws Exception { super.start(context); } /** * This method is called when the plug-in is stopped */ public void stop(BundleContext context) throws Exception { super.stop(context); setPlugin(null); resourceBundle = null; } /** * Returns the shared instance. */ public static HibernateConsoleTestPlugin getDefault() { return plugin; } private static void setPlugin(HibernateConsoleTestPlugin plugin) { HibernateConsoleTestPlugin.plugin = plugin; } /** * Returns the string from the plugin's resource bundle, * or 'key' if not found. */ public static String getResourceString(String key) { ResourceBundle bundle = getDefault().getResourceBundle(); try { return (bundle != null) ? bundle.getString(key) : key; } catch (MissingResourceException e) { return key; } } /** * Returns the plugin's resource bundle, */ public ResourceBundle getResourceBundle() { try { if (resourceBundle == null) resourceBundle = ResourceBundle.getBundle("org.hibernate.eclipse.console.test.test.HibernateConsoleTestPluginResources"); //$NON-NLS-1$ } catch (MissingResourceException x) { resourceBundle = null; } return resourceBundle; } /** * Returns an image descriptor for the image file at the given * plug-in relative path. * * @param path the path * @return the image descriptor */ public static ImageDescriptor getImageDescriptor(String path) { return AbstractUIPlugin.imageDescriptorFromPlugin("org.hibernate.eclipse.console.test.test", path); //$NON-NLS-1$ } public File getFileInPlugin(IPath path) throws CoreException { try { URL installURL= new URL(getBundle().getEntry("/"), path.toString()); //$NON-NLS-1$ URL localURL= FileLocator.toFileURL(installURL); return new File(localURL.getFile()); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, "org.hibernate.eclipse.console.test", IStatus.ERROR, e.getMessage(), e)); //$NON-NLS-1$ } } }