2 * Copyright (c) 2003-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 API and implementation
11 * $Id: CssUI.java,v 1.1 2004-09-02 18:11:51 jsurfer Exp $
14 package net.sourceforge.phpeclipse.css.ui;
18 import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences;
19 import net.sourceforge.phpeclipse.css.ui.internal.properties.CssPropertiesAdapterFactory;
20 import net.sourceforge.phpeclipse.css.ui.text.CssTextTools;
22 import org.eclipse.core.runtime.IStatus;
23 import org.eclipse.core.runtime.Platform;
24 import org.eclipse.core.runtime.Status;
25 import org.eclipse.jface.preference.IPreferenceStore;
26 import org.eclipse.jface.resource.ImageDescriptor;
27 import org.eclipse.jface.resource.ImageRegistry;
28 import org.eclipse.ui.editors.text.TextEditorPreferenceConstants;
29 import org.eclipse.ui.plugin.AbstractUIPlugin;
30 import org.osgi.framework.BundleContext;
33 * The main plugin class.
35 public final class CssUI extends AbstractUIPlugin {
37 // Constants ---------------------------------------------------------------
39 public static final String ICON_STYLE_SHEET =
40 "style_sheet_obj.gif"; //$NON-NLS-1$
41 public static final String ICON_AT_RULE =
42 "at_rule_obj.gif"; //$NON-NLS-1$
43 public static final String ICON_STYLE_RULE =
44 "style_rule_obj.gif"; //$NON-NLS-1$
45 public static final String ICON_PROPERTY =
46 "property_obj.gif"; //$NON-NLS-1$
47 public static final String ICON_SHORTHAND =
48 "shorthand_obj.gif"; //$NON-NLS-1$
49 public static final String ICON_PSEUDO_CLASS =
50 "pseudo_class_obj.gif"; //$NON-NLS-1$
51 public static final String ICON_IMPORTANT =
52 "important_obj.gif"; //$NON-NLS-1$
53 public static final String ICON_OVERLAY_ERROR =
54 "full/ovr16/error_co.gif"; //$NON-NLS-1$
55 public static final String ICON_OVERLAY_WARNING =
56 "full/ovr16/warning_co.gif"; //$NON-NLS-1$
58 // Class Variables ---------------------------------------------------------
61 * Singleton instance of the plugin.
63 private static CssUI plugin;
65 // Instance Variables ------------------------------------------------------
68 * The text tools collection.
70 private CssTextTools textTools;
72 // Constructors ------------------------------------------------------------
77 * @param descriptor the plugin descriptor.
83 // Static Methods ----------------------------------------------------------
86 * Returns the singleton instance of the plugin.
88 * @return the plugin instance
90 public static CssUI getDefault() {
95 * Returns the plugin ID.
97 * @return the plugin ID
99 public static String getPluginId() {
100 return getDefault().getBundle().getSymbolicName();
103 // Public Methods ----------------------------------------------------------
106 * Returns the CSS text tools that are used primarily for partitioning and
107 * syntax highlighting of CSS source.
109 * @return the CSS text tools
111 public synchronized CssTextTools getTextTools() {
112 if (textTools == null) {
113 textTools = new CssTextTools(getPreferenceStore());
119 * Returns an image descriptor for the image corresponding to the specified
120 * key (which is the name of the image file).
122 * @param key The key of the image
123 * @return The descriptor for the requested image, or <code>null</code> if
124 * the image could not be found
126 public ImageDescriptor getImageDescriptor(String key) {
128 URL url = getBundle().getEntry("/icons/" + key); //$NON-NLS-1$
129 return ImageDescriptor.createFromURL(url);
130 } catch (IllegalStateException e) {
136 * Writes a status message and the associated exception stack trace (if
137 * provided) to the error log.
139 * @param status the status to log
141 public static void log(IStatus status) {
142 getDefault().getLog().log(status);
143 if (status.getException() != null) {
144 status.getException().printStackTrace(System.err);
149 * Writes the specified error message and exception stack trace to the error
152 * @param message the error message
153 * @param e the exception that caused the error, or <tt>null</tt> to omit
154 * the stack trace in the log
156 public static void log(String message, Throwable e) {
157 IStatus status = new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR,
163 * Writes the specified error message to the error log.
165 * @param message the error message
167 public static void log(String message) {
168 IStatus status = new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR,
174 * Writes the stack trace of the given exception to the error log.
176 * @param e the exception that caused the error
178 public static void log(Throwable e) {
179 log(e.getMessage(), e);
182 // AbstractUIPlugin Implementation -----------------------------------------
185 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
187 public void start(BundleContext context) throws Exception {
188 super.start(context);
189 CssPropertiesAdapterFactory.register(Platform.getAdapterManager());
193 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
195 public void stop(BundleContext context) throws Exception {
197 if (textTools != null) {
207 * @see AbstractUIPlugin#initializeDefaultPreferences(IPreferenceStore)
209 protected void initializeDefaultPreferences(IPreferenceStore store) {
210 TextEditorPreferenceConstants.initializeDefaultValues(store);
211 CssUIPreferences.initializeDefaultValues(store);
215 * @see AbstractUIPlugin#initializeImageRegistry(ImageRegistry)
217 protected void initializeImageRegistry(ImageRegistry reg) {
218 reg.put(ICON_AT_RULE, getImageDescriptor(ICON_AT_RULE));
219 reg.put(ICON_STYLE_RULE, getImageDescriptor(ICON_STYLE_RULE));
220 reg.put(ICON_STYLE_SHEET, getImageDescriptor(ICON_STYLE_SHEET));
221 reg.put(ICON_PROPERTY, getImageDescriptor(ICON_PROPERTY));
222 reg.put(ICON_SHORTHAND, getImageDescriptor(ICON_SHORTHAND));
223 reg.put(ICON_PSEUDO_CLASS, getImageDescriptor(ICON_PSEUDO_CLASS));
224 reg.put(ICON_IMPORTANT, getImageDescriptor(ICON_IMPORTANT));
225 reg.put(ICON_OVERLAY_ERROR, getImageDescriptor(ICON_OVERLAY_ERROR));
226 reg.put(ICON_OVERLAY_WARNING, getImageDescriptor(ICON_OVERLAY_WARNING));