2  * Copyright (c) 2002-2004 Widespace, OU and others.
 
   3  * All rights reserved. This program and the accompanying materials
 
   4  * are made available under the terms of the Common Public License v1.0
 
   5  * which accompanies this distribution, and is available at
 
   6  * http://www.eclipse.org/legal/cpl-v10.html
 
   9  *     Igor Malinin - initial contribution
 
  11  * $Id: XMLPlugin.java,v 1.1 2004-09-02 18:28:04 jsurfer Exp $
 
  14 package net.sourceforge.phpeclipse.xml.ui;
 
  17 import java.util.MissingResourceException;
 
  18 import java.util.ResourceBundle;
 
  20 import net.sourceforge.phpeclipse.xml.ui.text.DTDTextTools;
 
  21 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
 
  23 import org.eclipse.jface.resource.ImageDescriptor;
 
  24 import org.eclipse.jface.resource.ImageRegistry;
 
  25 import org.eclipse.ui.plugin.AbstractUIPlugin;
 
  26 import org.osgi.framework.BundleContext;
 
  29  * The main plugin class to be used in the desktop.
 
  31 public class XMLPlugin extends AbstractUIPlugin {
 
  32         public static final String ICON_ELEMENT = "element_obj.gif"; //$NON-NLS-1$
 
  34         // The shared instance.
 
  35         private static XMLPlugin plugin;
 
  38         private ResourceBundle resources;
 
  40         private XMLTextTools xmlTextTools;
 
  41         private DTDTextTools dtdTextTools;
 
  50                         resources = ResourceBundle.getBundle(
 
  51                                 "net.sourceforge.phpeclipse.xml.ui.XMLPluginResources"); //$NON-NLS-1$
 
  52                 } catch (MissingResourceException x) {
 
  57          * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
 
  59         public void stop(BundleContext context) throws Exception {
 
  61                         if (xmlTextTools != null) {
 
  62                                 xmlTextTools.dispose();
 
  66                         if (dtdTextTools != null) {
 
  67                                 dtdTextTools.dispose();
 
  76          * Returns the shared instance.
 
  78         public static XMLPlugin getDefault() {
 
  83          * Returns the string from the plugin's resource bundle, or 'key' if not
 
  86         public static String getResourceString(String key) {
 
  87                 ResourceBundle bundle = XMLPlugin.getDefault().getResourceBundle();
 
  89                         return bundle.getString(key);
 
  90                 } catch (MissingResourceException e) {
 
  96          * Returns the plugin's resource bundle.
 
  98         public ResourceBundle getResourceBundle() {
 
 103          * Returns instance of text tools for XML.
 
 105         public XMLTextTools getXMLTextTools() {
 
 106                 if (xmlTextTools == null) {
 
 107                         xmlTextTools = new XMLTextTools(getPreferenceStore());
 
 113          * Returns instance of text tools for DTD.
 
 115         public DTDTextTools getDTDTextTools() {
 
 116                 if (dtdTextTools == null) {
 
 117                         dtdTextTools = new DTDTextTools(getPreferenceStore());
 
 123          * @see AbstractUIPlugin#initializeImageRegistry(ImageRegistry)
 
 125         protected void initializeImageRegistry(ImageRegistry reg) {
 
 126                 reg.put(ICON_ELEMENT, getImageDescriptor(ICON_ELEMENT));
 
 130          * Returns an image descriptor for the image corresponding to the specified
 
 131          * key (which is the name of the image file).
 
 133          * @param key The key of the image
 
 134          * @return The descriptor for the requested image, or <code>null</code> if 
 
 135          *         the image could not be found
 
 137         private ImageDescriptor getImageDescriptor(String key) {
 
 139                         URL url = getBundle().getEntry("/icons/" + key); //$NON-NLS-1$
 
 140                         return ImageDescriptor.createFromURL(url);
 
 141                 } catch (IllegalStateException e) {