1 package net.sourceforge.phpeclipse.externaltools;
 
   3 /**********************************************************************
 
   4  Copyright (c) 2002 IBM Corp. and others. All rights reserved.
 
   5  This file is made available under the terms of the Common Public License v1.0
 
   6  which accompanies this distribution, and is available at
 
   7  http://www.eclipse.org/legal/cpl-v10.html
 
  10  **********************************************************************/
 
  12 import java.net.MalformedURLException;
 
  15 import net.sourceforge.phpdt.externaltools.internal.model.ColorManager;
 
  16 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsImages;
 
  17 import net.sourceforge.phpdt.externaltools.internal.model.IPreferenceConstants;
 
  18 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
 
  19 import net.sourceforge.phpdt.externaltools.internal.registry.ArgumentVariableRegistry;
 
  20 import net.sourceforge.phpdt.externaltools.internal.registry.PathLocationVariableRegistry;
 
  21 import net.sourceforge.phpdt.externaltools.internal.registry.RefreshScopeVariableRegistry;
 
  22 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
 
  23 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
  25 import org.eclipse.core.runtime.CoreException;
 
  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.preference.PreferenceConverter;
 
  30 import org.eclipse.jface.resource.ImageDescriptor;
 
  31 import org.eclipse.jface.resource.ImageRegistry;
 
  32 import org.eclipse.swt.graphics.Color;
 
  33 import org.eclipse.swt.graphics.RGB;
 
  34 import org.eclipse.swt.widgets.Display;
 
  35 import org.eclipse.ui.IWorkbenchWindow;
 
  36 import org.eclipse.ui.plugin.AbstractUIPlugin;
 
  37 import org.osgi.framework.Bundle;
 
  40  * External tools plug-in class
 
  42 public final class ExternalToolsPlugin extends AbstractUIPlugin {
 
  44    * Status representing no problems encountered during operation.
 
  46   public static final IStatus OK_STATUS = new Status(IStatus.OK, IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
 
  48   private static ExternalToolsPlugin plugin;
 
  50   private RefreshScopeVariableRegistry refreshVarRegistry;
 
  52   private PathLocationVariableRegistry fileLocVarRegistry;
 
  54   private PathLocationVariableRegistry dirLocVarRegistry;
 
  56   private ArgumentVariableRegistry argumentVarRegistry;
 
  59    * Create an instance of the External Tools plug-in.
 
  61   public ExternalToolsPlugin() { // IPluginDescriptor descriptor) {
 
  67    * Returns the default instance of the receiver. This represents the runtime plugin.
 
  69   public static ExternalToolsPlugin getDefault() {
 
  74    * Returns a new <code>IStatus</code> for this plug-in
 
  76   public static IStatus newErrorStatus(String message, Throwable exception) {
 
  77     return new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception);
 
  81    * Returns a new <code>CoreException</code> for this plug-in
 
  83   public static CoreException newError(String message, Throwable exception) {
 
  84     return new CoreException(new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception));
 
  88    * Returns the registry of refresh scope variables.
 
  90   public ArgumentVariableRegistry getArgumentVariableRegistry() {
 
  91     if (argumentVarRegistry == null)
 
  92       argumentVarRegistry = new ArgumentVariableRegistry();
 
  93     return argumentVarRegistry;
 
  97    * Returns the registry of directory location variables.
 
  99   public PathLocationVariableRegistry getDirectoryLocationVariableRegistry() {
 
 100     if (dirLocVarRegistry == null)
 
 101       dirLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_DIRECTORY_VARIABLES);
 
 102     return dirLocVarRegistry;
 
 106    * Returns the registry of file location variables.
 
 108   public PathLocationVariableRegistry getFileLocationVariableRegistry() {
 
 109     if (fileLocVarRegistry == null)
 
 110       fileLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_FILE_VARIABLES);
 
 111     return fileLocVarRegistry;
 
 115    * Returns the registry of refresh scope variables.
 
 117   public RefreshScopeVariableRegistry getRefreshVariableRegistry() {
 
 118     if (refreshVarRegistry == null)
 
 119       refreshVarRegistry = new RefreshScopeVariableRegistry();
 
 120     return refreshVarRegistry;
 
 124    * Writes the message to the plug-in's log
 
 127    *          the text to write to the log
 
 129   public void log(String message, Throwable exception) {
 
 130     IStatus status = newErrorStatus(message, exception);
 
 131     //  getLog().log(status);
 
 132     PHPeclipsePlugin.log(status);
 
 136    * Returns the ImageDescriptor for the icon with the given path
 
 138    * @return the ImageDescriptor object
 
 140   public ImageDescriptor getImageDescriptor(String path) {
 
 142       Bundle bundle = PHPeclipsePlugin.getDefault().getBundle();
 
 143       URL installURL = bundle.getEntry("/"); //$NON-NLS-1$
 
 144       URL url = new URL(installURL, path);
 
 145       return ImageDescriptor.createFromURL(url);
 
 146     } catch (MalformedURLException e) {
 
 152    * (non-Javadoc) Method declared in AbstractUIPlugin.
 
 154   public void initializeDefaultPreferences(IPreferenceStore prefs) {
 
 155     prefs.setDefault(IPreferenceConstants.PROMPT_FOR_MIGRATION, true);
 
 157     PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_ERROR_RGB, new RGB(255, 0, 0)); // red - exactly the same as
 
 159     PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_WARNING_RGB, new RGB(255, 100, 0)); // orange
 
 160     PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_INFO_RGB, new RGB(0, 0, 255)); // blue
 
 161     PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_VERBOSE_RGB, new RGB(0, 200, 125)); // green
 
 162     PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_DEBUG_RGB, new RGB(0, 0, 0)); // black
 
 165   public static IWorkbenchWindow getActiveWorkbenchWindow() {
 
 166     return PHPeclipsePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
 
 170    * Returns the standard display to be used. The method first checks, if the thread calling this method has an associated display.
 
 171    * If so, this display is returned. Otherwise the method returns the default display.
 
 173   public static Display getStandardDisplay() {
 
 174     Display display = Display.getCurrent();
 
 175     if (display == null) {
 
 176       display = Display.getDefault();
 
 182    * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
 
 184   protected ImageRegistry createImageRegistry() {
 
 185     return ExternalToolsImages.initializeImageRegistry();
 
 189    * @see org.eclipse.core.runtime.Plugin#startup()
 
 191   public void startup() throws CoreException {
 
 193     getStandardDisplay().asyncExec(new Runnable() {
 
 195         //initialize the variable context manager
 
 196         VariableContextManager.getDefault();
 
 202    * @see org.eclipse.core.runtime.Plugin#shutdown()
 
 204   public void shutdown() throws CoreException {
 
 206     ColorManager.getDefault().dispose();
 
 210    * Returns the preference color, identified by the given preference.
 
 212   public static Color getPreferenceColor(String pref) {
 
 213     return ColorManager.getDefault().getColor(
 
 214         PreferenceConverter.getColor(PHPeclipsePlugin.getDefault().getPreferenceStore(), pref));