/* * Copyright (c) 2003-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 API and implementation * * $Id: CssUI.java,v 1.1 2004-09-02 18:11:51 jsurfer Exp $ */ package net.sourceforge.phpeclipse.css.ui; import java.net.URL; import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences; import net.sourceforge.phpeclipse.css.ui.internal.properties.CssPropertiesAdapterFactory; import net.sourceforge.phpeclipse.css.ui.text.CssTextTools; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.ui.editors.text.TextEditorPreferenceConstants; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The main plugin class. */ public final class CssUI extends AbstractUIPlugin { // Constants --------------------------------------------------------------- public static final String ICON_STYLE_SHEET = "style_sheet_obj.gif"; //$NON-NLS-1$ public static final String ICON_AT_RULE = "at_rule_obj.gif"; //$NON-NLS-1$ public static final String ICON_STYLE_RULE = "style_rule_obj.gif"; //$NON-NLS-1$ public static final String ICON_PROPERTY = "property_obj.gif"; //$NON-NLS-1$ public static final String ICON_SHORTHAND = "shorthand_obj.gif"; //$NON-NLS-1$ public static final String ICON_PSEUDO_CLASS = "pseudo_class_obj.gif"; //$NON-NLS-1$ public static final String ICON_IMPORTANT = "important_obj.gif"; //$NON-NLS-1$ 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$ // Class Variables --------------------------------------------------------- /** * Singleton instance of the plugin. */ private static CssUI plugin; // Instance Variables ------------------------------------------------------ /** * The text tools collection. */ private CssTextTools textTools; // Constructors ------------------------------------------------------------ /** * Constructor. * * @param descriptor the plugin descriptor. */ public CssUI() { plugin = this; } // Static Methods ---------------------------------------------------------- /** * Returns the singleton instance of the plugin. * * @return the plugin instance */ public static CssUI getDefault() { return plugin; } /** * Returns the plugin ID. * * @return the plugin ID */ public static String getPluginId() { return getDefault().getBundle().getSymbolicName(); } // Public Methods ---------------------------------------------------------- /** * Returns the CSS text tools that are used primarily for partitioning and * syntax highlighting of CSS source. * * @return the CSS text tools */ public synchronized CssTextTools getTextTools() { if (textTools == null) { textTools = new CssTextTools(getPreferenceStore()); } return textTools; } /** * 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 */ public ImageDescriptor getImageDescriptor(String key) { try { URL url = getBundle().getEntry("/icons/" + key); //$NON-NLS-1$ return ImageDescriptor.createFromURL(url); } catch (IllegalStateException e) { return null; } } /** * Writes a status message and the associated exception stack trace (if * provided) to the error log. * * @param status the status to log */ public static void log(IStatus status) { getDefault().getLog().log(status); if (status.getException() != null) { status.getException().printStackTrace(System.err); } } /** * Writes the specified error message and exception stack trace to the error * log. * * @param message the error message * @param e the exception that caused the error, or null to omit * the stack trace in the log */ public static void log(String message, Throwable e) { IStatus status = new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, message, e); log(status); } /** * Writes the specified error message to the error log. * * @param message the error message */ public static void log(String message) { IStatus status = new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, message, null); log(status); } /** * Writes the stack trace of the given exception to the error log. * * @param e the exception that caused the error */ public static void log(Throwable e) { log(e.getMessage(), e); } // AbstractUIPlugin Implementation ----------------------------------------- /* * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ public void start(BundleContext context) throws Exception { super.start(context); CssPropertiesAdapterFactory.register(Platform.getAdapterManager()); } /* * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext context) throws Exception { try { if (textTools != null) { textTools.dispose(); textTools = null; } } finally { super.stop(context); } } /* * @see AbstractUIPlugin#initializeDefaultPreferences(IPreferenceStore) */ protected void initializeDefaultPreferences(IPreferenceStore store) { TextEditorPreferenceConstants.initializeDefaultValues(store); CssUIPreferences.initializeDefaultValues(store); } /* * @see AbstractUIPlugin#initializeImageRegistry(ImageRegistry) */ protected void initializeImageRegistry(ImageRegistry reg) { reg.put(ICON_AT_RULE, getImageDescriptor(ICON_AT_RULE)); reg.put(ICON_STYLE_RULE, getImageDescriptor(ICON_STYLE_RULE)); reg.put(ICON_STYLE_SHEET, getImageDescriptor(ICON_STYLE_SHEET)); reg.put(ICON_PROPERTY, getImageDescriptor(ICON_PROPERTY)); reg.put(ICON_SHORTHAND, getImageDescriptor(ICON_SHORTHAND)); reg.put(ICON_PSEUDO_CLASS, getImageDescriptor(ICON_PSEUDO_CLASS)); reg.put(ICON_IMPORTANT, getImageDescriptor(ICON_IMPORTANT)); reg.put(ICON_OVERLAY_ERROR, getImageDescriptor(ICON_OVERLAY_ERROR)); reg.put(ICON_OVERLAY_WARNING, getImageDescriptor(ICON_OVERLAY_WARNING)); } }