X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/WebUI.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/WebUI.java new file mode 100644 index 0000000..39a172e --- /dev/null +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/WebUI.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2004 Christopher Lenz and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Christopher Lenz - initial implementation + * + * $Id: WebUI.java,v 1.1 2004-09-02 18:26:49 jsurfer Exp $ + */ + +package net.sourceforge.phpeclipse.ui; + +import java.io.IOException; +import java.net.URL; + +import net.sourceforge.phpeclipse.ui.templates.template.HTMLContextType; +import net.sourceforge.phpeclipse.ui.templates.template.JSContextType; +import net.sourceforge.phpeclipse.ui.templates.template.XMLContextType; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.jface.text.templates.ContextTypeRegistry; +import org.eclipse.jface.text.templates.persistence.TemplateStore; +import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry; +import org.eclipse.ui.editors.text.templates.ContributionTemplateStore; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +/** + * The web development tools UI plugin. + */ +public class WebUI extends AbstractUIPlugin { + private static final String CUSTOM_TEMPLATES_KEY= "net.sourceforge.phpeclipse.ui.templates"; //$NON-NLS-1$ + + // Constants --------------------------------------------------------------- + + public static final String ICON_OVERLAY_ERROR = + "full/ovr16/error_co.gif"; //$NON-NLS-1$ + public static final String ICON_OVERLAY_WARNING = + "full/ovr16/warning_co.gif"; //$NON-NLS-1$ + + // Instance Variables ------------------------------------------------------ + + /** The shared instance. */ + private static WebUI plugin; + + /** The template store. */ + private TemplateStore fStore; + /** The context type registry. */ + private ContributionContextTypeRegistry fRegistry; + // Constructors ------------------------------------------------------------ + + /** + * The constructor. + */ + public WebUI() { + plugin = this; + } + + // Public Methods ---------------------------------------------------------- + + /** + * Returns the shared instance. + */ + public static WebUI getDefault() { + return plugin; + } + + // AbstractUIPlugin Implementation ----------------------------------------- + + /* + * @see AbstractUIPlugin#initializeImageRegistry(ImageRegistry) + */ + protected void initializeImageRegistry(ImageRegistry reg) { + reg.put(ICON_OVERLAY_ERROR, getImageDescriptor(ICON_OVERLAY_ERROR)); + reg.put(ICON_OVERLAY_WARNING, getImageDescriptor(ICON_OVERLAY_WARNING)); + } + + // Private Methods --------------------------------------------------------- + + /** + * Returns an image descriptor for the image corresponding to the specified + * key (which is the name of the image file). + * + * @param key The key of the image + * @return The descriptor for the requested image, or null if + * the image could not be found + */ + private ImageDescriptor getImageDescriptor(String key) { + try { + URL url = getBundle().getEntry("/icons/" + key); //$NON-NLS-1$ + return ImageDescriptor.createFromURL(url); + } catch (IllegalStateException e) { + return null; + } + } + + /** + * Returns this plug-in's template store. + * + * @return the template store of this plug-in instance + */ + public TemplateStore getTemplateStore() { + if (fStore == null) { + fStore= new ContributionTemplateStore(getContextTypeRegistry(), getDefault().getPreferenceStore(), CUSTOM_TEMPLATES_KEY); + try { + fStore.load(); + } catch (IOException e) { + WebUI.getDefault().getLog().log(new Status(IStatus.ERROR, "net.sourceforge.phpeclipse.ui", IStatus.OK, "", e)); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + return fStore; + } + + /** + * Returns this plug-in's context type registry. + * + * @return the context type registry for this plug-in instance + */ + public ContextTypeRegistry getContextTypeRegistry() { + if (fRegistry == null) { + // create an configure the contexts available in the editor + fRegistry= new ContributionContextTypeRegistry(); + fRegistry.addContextType(XMLContextType.XML_CONTEXT_TYPE); + fRegistry.addContextType(HTMLContextType.HTML_CONTEXT_TYPE); + fRegistry.addContextType(JSContextType.JS_CONTEXT_TYPE); + } + return fRegistry; + } +}