001 /*
002 * file ScoutPlugin.java
003 *
004 * Licensed Materials - Property of IBM
005 * Restricted Materials of IBM - you are allowed to copy, modify and
006 * redistribute this file as part of any program that interfaces with
007 * IBM Rational CM API.
008 *
009 * com.ibm.rational.teamapi.scout.ScoutPlugin
010 *
011 * © Copyright IBM Corporation 2004, 2008. All Rights Reserved.
012 * Note to U.S. Government Users Restricted Rights: Use, duplication or
013 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
014 */
015 package com.ibm.rational.teamapi.scout;
016
017 import java.util.MissingResourceException;
018 import java.util.ResourceBundle;
019
020 import org.eclipse.core.resources.IWorkspace;
021 import org.eclipse.core.resources.ResourcesPlugin;
022 import org.eclipse.jface.resource.ImageDescriptor;
023 import org.eclipse.ui.plugin.AbstractUIPlugin;
024
025 /**
026 * The main plugin class to be used in the Eclipse desktop.
027 */
028 public class ScoutPlugin extends AbstractUIPlugin {
029 //The shared instance.
030 private static ScoutPlugin plugin;
031 //Resource bundle.
032 private ResourceBundle resourceBundle;
033
034 /**
035 * The constructor.
036 */
037 public ScoutPlugin() {
038 super();
039 plugin = this;
040 try {
041 resourceBundle = ResourceBundle
042 .getBundle("com.ibm.rational.teamapi.scout.ScoutPluginResources");
043 } catch (MissingResourceException x) {
044 resourceBundle = null;
045 }
046 }
047
048 /**
049 * Returns the shared instance.
050 */
051 public static ScoutPlugin getDefault() {
052 return plugin;
053 }
054
055 /**
056 * Returns the workspace instance.
057 */
058 public static IWorkspace getWorkspace() {
059 return ResourcesPlugin.getWorkspace();
060 }
061
062 /**
063 * Returns the string from the plugin's resource bundle,
064 * or 'key' if not found.
065 */
066 public static String getResourceString(String key) {
067 ResourceBundle bundle = ScoutPlugin.getDefault().getResourceBundle();
068 try {
069 return (bundle != null) ? bundle.getString(key) : key;
070 } catch (MissingResourceException e) {
071 return key;
072 }
073 }
074
075 /**
076 * Returns the plugin's resource bundle,
077 */
078 public ResourceBundle getResourceBundle() {
079 return resourceBundle;
080 }
081
082 /**
083 * Returns the image descriptor for a named icon.
084 * @param name The simple file name for the icon; e.g. "foldergif"
085 * @return An ImageDescriptor for the icon; will not be null, but may be
086 * the descriptor for the "missing image" if the requested icon is not found.
087 */
088 public static ImageDescriptor getImageDescriptor(String name) {
089 ImageDescriptor result =
090 imageDescriptorFromPlugin("com.ibm.rational.teamapi.scout",
091 "icons/"+name);
092
093 if (result == null)
094 result = ImageDescriptor.getMissingImageDescriptor();
095
096 return result;
097 }
098 }