1 package net.sourceforge.phpdt.externaltools.internal.model;
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.registry.ArgumentVariableRegistry;
16 import net.sourceforge.phpdt.externaltools.internal.registry.PathLocationVariableRegistry;
17 import net.sourceforge.phpdt.externaltools.internal.registry.RefreshScopeVariableRegistry;
18 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
19 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.core.runtime.IStatus;
23 import org.eclipse.core.runtime.Status;
24 import org.eclipse.jface.preference.IPreferenceStore;
25 import org.eclipse.jface.preference.PreferenceConverter;
26 import org.eclipse.jface.resource.ImageDescriptor;
27 import org.eclipse.jface.resource.ImageRegistry;
28 import org.eclipse.swt.graphics.Color;
29 import org.eclipse.swt.graphics.RGB;
30 import org.eclipse.ui.IWorkbenchWindow;
31 import org.osgi.framework.Bundle;
34 * External tools plug-in class
36 public final class ExternalToolsPlugin { // extends AbstractUIPlugin {
38 * Status representing no problems encountered during operation.
40 public static final IStatus OK_STATUS = new Status(IStatus.OK, IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
42 private static ExternalToolsPlugin plugin;
44 private RefreshScopeVariableRegistry refreshVarRegistry;
45 private PathLocationVariableRegistry fileLocVarRegistry;
46 private PathLocationVariableRegistry dirLocVarRegistry;
47 private ArgumentVariableRegistry argumentVarRegistry;
50 * Create an instance of the External Tools plug-in.
52 public ExternalToolsPlugin() { // IPluginDescriptor descriptor) {
58 * Returns the default instance of the receiver.
59 * This represents the runtime plugin.
61 public static ExternalToolsPlugin getDefault() {
66 * Returns a new <code>IStatus</code> for this plug-in
68 public static IStatus newErrorStatus(String message, Throwable exception) {
69 return new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception);
73 * Returns a new <code>CoreException</code> for this plug-in
75 public static CoreException newError(String message, Throwable exception) {
76 return new CoreException(new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception));
80 * Returns the registry of refresh scope variables.
82 public ArgumentVariableRegistry getArgumentVariableRegistry() {
83 if (argumentVarRegistry == null)
84 argumentVarRegistry = new ArgumentVariableRegistry();
85 return argumentVarRegistry;
89 * Returns the registry of directory location variables.
91 public PathLocationVariableRegistry getDirectoryLocationVariableRegistry() {
92 if (dirLocVarRegistry == null)
93 dirLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_DIRECTORY_VARIABLES);
94 return dirLocVarRegistry;
98 * Returns the registry of file location variables.
100 public PathLocationVariableRegistry getFileLocationVariableRegistry() {
101 if (fileLocVarRegistry == null)
102 fileLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_FILE_VARIABLES);
103 return fileLocVarRegistry;
107 * Returns the registry of refresh scope variables.
109 public RefreshScopeVariableRegistry getRefreshVariableRegistry() {
110 if (refreshVarRegistry == null)
111 refreshVarRegistry = new RefreshScopeVariableRegistry();
112 return refreshVarRegistry;
116 * Writes the message to the plug-in's log
118 * @param message the text to write to the log
120 public void log(String message, Throwable exception) {
121 IStatus status = newErrorStatus(message, exception);
122 // getLog().log(status);
123 PHPeclipsePlugin.log(status);
127 * Returns the ImageDescriptor for the icon with the given path
129 * @return the ImageDescriptor object
131 public ImageDescriptor getImageDescriptor(String path) {
133 Bundle bundle= PHPeclipsePlugin.getDefault().getBundle();
134 URL installURL = bundle.getEntry("/"); //$NON-NLS-1$
135 URL url = new URL(installURL, path);
136 return ImageDescriptor.createFromURL(url);
137 } catch (MalformedURLException e) {
143 * Method declared in AbstractUIPlugin.
145 public void initializeDefaultPreferences(IPreferenceStore prefs) {
146 prefs.setDefault(IPreferenceConstants.PROMPT_FOR_MIGRATION, true);
148 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_ERROR_RGB, new RGB(255, 0, 0)); // red - exactly the same as debug Consol
149 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_WARNING_RGB, new RGB(255, 100, 0)); // orange
150 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_INFO_RGB, new RGB(0, 0, 255)); // blue
151 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_VERBOSE_RGB, new RGB(0, 200, 125)); // green
152 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_DEBUG_RGB, new RGB(0, 0, 0)); // black
155 public static IWorkbenchWindow getActiveWorkbenchWindow() {
156 return PHPeclipsePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
160 * Returns the standard display to be used. The method first checks, if
161 * the thread calling this method has an associated display. If so, this
162 * display is returned. Otherwise the method returns the default display.
164 // public static Display getStandardDisplay() {
165 // Display display = Display.getCurrent();
166 // if (display == null) {
167 // display = Display.getDefault();
173 * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
175 protected ImageRegistry createImageRegistry() {
176 return ExternalToolsImages.initializeImageRegistry();
180 * @see org.eclipse.core.runtime.Plugin#startup()
182 // public void startup() throws CoreException {
183 //// super.startup();
184 // getStandardDisplay().asyncExec(
186 // public void run() {
187 // //initialize the variable context manager
188 // VariableContextManager.getDefault();
194 // * @see org.eclipse.core.runtime.Plugin#shutdown()
196 // public void shutdown() throws CoreException {
197 // // super.shutdown();
198 // ColorManager.getDefault().dispose();
202 * Returns the preference color, identified by the given preference.
204 public static Color getPreferenceColor(String pref) {
205 return ColorManager.getDefault().getColor(PreferenceConverter.getColor(PHPeclipsePlugin.getDefault().getPreferenceStore(), pref));