2 * Copyright (c) 2004 Christopher Lenz 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 * Christopher Lenz - initial implementation
11 * $Id: WebUI.java,v 1.1 2004-09-02 18:26:49 jsurfer Exp $
14 package net.sourceforge.phpeclipse.ui;
16 import java.io.IOException;
19 import net.sourceforge.phpeclipse.ui.templates.template.HTMLContextType;
20 import net.sourceforge.phpeclipse.ui.templates.template.JSContextType;
21 import net.sourceforge.phpeclipse.ui.templates.template.XMLContextType;
23 import org.eclipse.core.runtime.IStatus;
24 import org.eclipse.core.runtime.Status;
25 import org.eclipse.jface.resource.ImageDescriptor;
26 import org.eclipse.jface.resource.ImageRegistry;
27 import org.eclipse.jface.text.templates.ContextTypeRegistry;
28 import org.eclipse.jface.text.templates.persistence.TemplateStore;
29 import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
30 import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
31 import org.eclipse.ui.plugin.AbstractUIPlugin;
34 * The web development tools UI plugin.
36 public class WebUI extends AbstractUIPlugin {
37 private static final String CUSTOM_TEMPLATES_KEY= "net.sourceforge.phpeclipse.ui.templates"; //$NON-NLS-1$
39 // Constants ---------------------------------------------------------------
41 public static final String ICON_OVERLAY_ERROR =
42 "full/ovr16/error_co.gif"; //$NON-NLS-1$
43 public static final String ICON_OVERLAY_WARNING =
44 "full/ovr16/warning_co.gif"; //$NON-NLS-1$
46 // Instance Variables ------------------------------------------------------
48 /** The shared instance. */
49 private static WebUI plugin;
51 /** The template store. */
52 private TemplateStore fStore;
53 /** The context type registry. */
54 private ContributionContextTypeRegistry fRegistry;
55 // Constructors ------------------------------------------------------------
64 // Public Methods ----------------------------------------------------------
67 * Returns the shared instance.
69 public static WebUI getDefault() {
73 // AbstractUIPlugin Implementation -----------------------------------------
76 * @see AbstractUIPlugin#initializeImageRegistry(ImageRegistry)
78 protected void initializeImageRegistry(ImageRegistry reg) {
79 reg.put(ICON_OVERLAY_ERROR, getImageDescriptor(ICON_OVERLAY_ERROR));
80 reg.put(ICON_OVERLAY_WARNING, getImageDescriptor(ICON_OVERLAY_WARNING));
83 // Private Methods ---------------------------------------------------------
86 * Returns an image descriptor for the image corresponding to the specified
87 * key (which is the name of the image file).
89 * @param key The key of the image
90 * @return The descriptor for the requested image, or <code>null</code> if
91 * the image could not be found
93 private ImageDescriptor getImageDescriptor(String key) {
95 URL url = getBundle().getEntry("/icons/" + key); //$NON-NLS-1$
96 return ImageDescriptor.createFromURL(url);
97 } catch (IllegalStateException e) {
103 * Returns this plug-in's template store.
105 * @return the template store of this plug-in instance
107 public TemplateStore getTemplateStore() {
108 if (fStore == null) {
109 fStore= new ContributionTemplateStore(getContextTypeRegistry(), getDefault().getPreferenceStore(), CUSTOM_TEMPLATES_KEY);
112 } catch (IOException e) {
113 WebUI.getDefault().getLog().log(new Status(IStatus.ERROR, "net.sourceforge.phpeclipse.ui", IStatus.OK, "", e)); //$NON-NLS-1$ //$NON-NLS-2$
120 * Returns this plug-in's context type registry.
122 * @return the context type registry for this plug-in instance
124 public ContextTypeRegistry getContextTypeRegistry() {
125 if (fRegistry == null) {
126 // create an configure the contexts available in the editor
127 fRegistry= new ContributionContextTypeRegistry();
128 fRegistry.addContextType(XMLContextType.XML_CONTEXT_TYPE);
129 fRegistry.addContextType(HTMLContextType.HTML_CONTEXT_TYPE);
130 fRegistry.addContextType(JSContextType.JS_CONTEXT_TYPE);