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.2 2006-10-21 23:14:13 pombredanne 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;
42 private DTDTextTools dtdTextTools;
51 resources = ResourceBundle
52 .getBundle("net.sourceforge.phpeclipse.xml.ui.XMLPluginResources"); //$NON-NLS-1$
53 } catch (MissingResourceException x) {
58 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
60 public void stop(BundleContext context) throws Exception {
62 if (xmlTextTools != null) {
63 xmlTextTools.dispose();
67 if (dtdTextTools != null) {
68 dtdTextTools.dispose();
77 * Returns the shared instance.
79 public static XMLPlugin getDefault() {
84 * Returns the string from the plugin's resource bundle, or 'key' if not
87 public static String getResourceString(String key) {
88 ResourceBundle bundle = XMLPlugin.getDefault().getResourceBundle();
90 return bundle.getString(key);
91 } catch (MissingResourceException e) {
97 * Returns the plugin's resource bundle.
99 public ResourceBundle getResourceBundle() {
104 * Returns instance of text tools for XML.
106 public XMLTextTools getXMLTextTools() {
107 if (xmlTextTools == null) {
108 xmlTextTools = new XMLTextTools(getPreferenceStore());
114 * Returns instance of text tools for DTD.
116 public DTDTextTools getDTDTextTools() {
117 if (dtdTextTools == null) {
118 dtdTextTools = new DTDTextTools(getPreferenceStore());
124 * @see AbstractUIPlugin#initializeImageRegistry(ImageRegistry)
126 protected void initializeImageRegistry(ImageRegistry reg) {
127 reg.put(ICON_ELEMENT, getImageDescriptor(ICON_ELEMENT));
131 * Returns an image descriptor for the image corresponding to the specified
132 * key (which is the name of the image file).
135 * The key of the image
136 * @return The descriptor for the requested image, or <code>null</code> if
137 * the image could not be found
139 private ImageDescriptor getImageDescriptor(String key) {
141 URL url = getBundle().getEntry("/icons/" + key); //$NON-NLS-1$
142 return ImageDescriptor.createFromURL(url);
143 } catch (IllegalStateException e) {