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.5 2005-09-25 16:29:45 axelcl 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.SmartyContextType;
22 import net.sourceforge.phpeclipse.ui.templates.template.XMLContextType;
24 import org.eclipse.core.resources.IWorkspace;
25 import org.eclipse.core.resources.ResourcesPlugin;
26 import org.eclipse.core.runtime.IStatus;
27 import org.eclipse.core.runtime.Status;
28 import org.eclipse.jface.preference.IPreferenceStore;
29 import org.eclipse.jface.resource.ImageDescriptor;
30 import org.eclipse.jface.resource.ImageRegistry;
31 import org.eclipse.jface.text.templates.ContextTypeRegistry;
32 import org.eclipse.jface.text.templates.persistence.TemplateStore;
33 import org.eclipse.swt.widgets.Shell;
34 import org.eclipse.ui.IWorkbenchPage;
35 import org.eclipse.ui.IWorkbenchWindow;
36 import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
37 import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
38 import org.eclipse.ui.plugin.AbstractUIPlugin;
41 * The web development tools UI plugin.
43 public class WebUI extends AbstractUIPlugin implements IPreferenceConstants {
44 private static final String CUSTOM_TEMPLATES_KEY = "net.sourceforge.phpeclipse.ui.templates"; //$NON-NLS-1$
46 // Constants ---------------------------------------------------------------
48 public static final String ICON_OVERLAY_ERROR = "full/ovr16/error_co.gif"; //$NON-NLS-1$
50 public static final String ICON_OVERLAY_WARNING = "full/ovr16/warning_co.gif"; //$NON-NLS-1$
52 // Instance Variables ------------------------------------------------------
54 /** The shared instance. */
55 private static WebUI plugin;
57 public static IWorkbenchPage getActivePage() {
58 return getDefault().internalGetActivePage();
61 private IWorkbenchPage internalGetActivePage() {
62 return getWorkbench().getActiveWorkbenchWindow().getActivePage();
65 public static Shell getActiveWorkbenchShell() {
66 return getActiveWorkbenchWindow().getShell();
69 public static IWorkbenchWindow getActiveWorkbenchWindow() {
70 return getDefault().getWorkbench().getActiveWorkbenchWindow();
72 // Public Methods ----------------------------------------------------------
75 * Returns the shared instance.
77 public static WebUI getDefault() {
82 * Returns the workspace instance.
84 public static IWorkspace getWorkspace() {
85 return ResourcesPlugin.getWorkspace();
88 /** The context type registry. */
89 private ContributionContextTypeRegistry fRegistry;
91 /** The template store. */
92 private TemplateStore fStore;
94 // Constructors ------------------------------------------------------------
104 * Returns this plug-in's context type registry.
106 * @return the context type registry for this plug-in instance
108 public ContextTypeRegistry getContextTypeRegistry() {
109 if (fRegistry == null) {
110 // create an configure the contexts available in the editor
111 fRegistry = new ContributionContextTypeRegistry();
112 fRegistry.addContextType(XMLContextType.XML_CONTEXT_TYPE);
113 fRegistry.addContextType(HTMLContextType.HTML_CONTEXT_TYPE);
114 fRegistry.addContextType(SmartyContextType.SMARTY_CONTEXT_TYPE);
115 fRegistry.addContextType(JSContextType.JS_CONTEXT_TYPE);
120 // Private Methods ---------------------------------------------------------
123 * Returns an image descriptor for the image corresponding to the specified key (which is the name of the image file).
126 * The key of the image
127 * @return The descriptor for the requested image, or <code>null</code> if the image could not be found
129 private ImageDescriptor getImageDescriptor(String key) {
131 URL url = getBundle().getEntry("/icons/" + key); //$NON-NLS-1$
132 return ImageDescriptor.createFromURL(url);
133 } catch (IllegalStateException e) {
139 * Returns this plug-in's template store.
141 * @return the template store of this plug-in instance
143 public TemplateStore getTemplateStore() {
144 if (fStore == null) {
145 fStore = new ContributionTemplateStore(getContextTypeRegistry(), getDefault().getPreferenceStore(), CUSTOM_TEMPLATES_KEY);
148 } catch (IOException e) {
149 WebUI.getDefault().getLog().log(new Status(IStatus.ERROR, "net.sourceforge.phpeclipse.ui", IStatus.OK, "", e)); //$NON-NLS-1$ //$NON-NLS-2$
155 protected void initializeDefaultPreferences(IPreferenceStore store) {
156 store.setDefault(PHP_LOCALHOST_PREF, "http://localhost");
157 store.setDefault(PHP_DOCUMENTROOT_PREF, getWorkspace().getRoot().getLocation().toString());
158 store.setDefault(PHP_BOOKMARK_DEFAULT, "");
160 store.setDefault(PHP_AUTO_PREVIEW_DEFAULT, "true");
161 store.setDefault(PHP_BRING_TO_TOP_PREVIEW_DEFAULT, "true");
162 // store.setDefault(PHP_SHOW_HTML_FILES_LOCAL, "true");
163 // store.setDefault(PHP_SHOW_XML_FILES_LOCAL, "false");
167 * @see AbstractUIPlugin#initializeImageRegistry(ImageRegistry)
169 protected void initializeImageRegistry(ImageRegistry reg) {
170 reg.put(ICON_OVERLAY_ERROR, getImageDescriptor(ICON_OVERLAY_ERROR));
171 reg.put(ICON_OVERLAY_WARNING, getImageDescriptor(ICON_OVERLAY_WARNING));
173 // private IWorkbenchPage internalGetActivePage() {
174 // IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
175 // if (window != null)
176 // return window.getActivePage();