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;
33 * External tools plug-in class
35 public final class ExternalToolsPlugin { // extends AbstractUIPlugin {
37 * Status representing no problems encountered during operation.
39 public static final IStatus OK_STATUS = new Status(IStatus.OK, IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
41 private static ExternalToolsPlugin plugin;
43 private RefreshScopeVariableRegistry refreshVarRegistry;
44 private PathLocationVariableRegistry fileLocVarRegistry;
45 private PathLocationVariableRegistry dirLocVarRegistry;
46 private ArgumentVariableRegistry argumentVarRegistry;
49 * Create an instance of the External Tools plug-in.
51 public ExternalToolsPlugin() { // IPluginDescriptor descriptor) {
57 * Returns the default instance of the receiver.
58 * This represents the runtime plugin.
60 public static ExternalToolsPlugin getDefault() {
65 * Returns a new <code>IStatus</code> for this plug-in
67 public static IStatus newErrorStatus(String message, Throwable exception) {
68 return new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception);
72 * Returns a new <code>CoreException</code> for this plug-in
74 public static CoreException newError(String message, Throwable exception) {
75 return new CoreException(new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception));
79 * Returns the registry of refresh scope variables.
81 public ArgumentVariableRegistry getArgumentVariableRegistry() {
82 if (argumentVarRegistry == null)
83 argumentVarRegistry = new ArgumentVariableRegistry();
84 return argumentVarRegistry;
88 * Returns the registry of directory location variables.
90 public PathLocationVariableRegistry getDirectoryLocationVariableRegistry() {
91 if (dirLocVarRegistry == null)
92 dirLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_DIRECTORY_VARIABLES);
93 return dirLocVarRegistry;
97 * Returns the registry of file location variables.
99 public PathLocationVariableRegistry getFileLocationVariableRegistry() {
100 if (fileLocVarRegistry == null)
101 fileLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_FILE_VARIABLES);
102 return fileLocVarRegistry;
106 * Returns the registry of refresh scope variables.
108 public RefreshScopeVariableRegistry getRefreshVariableRegistry() {
109 if (refreshVarRegistry == null)
110 refreshVarRegistry = new RefreshScopeVariableRegistry();
111 return refreshVarRegistry;
115 * Writes the message to the plug-in's log
117 * @param message the text to write to the log
119 public void log(String message, Throwable exception) {
120 IStatus status = newErrorStatus(message, exception);
121 // getLog().log(status);
122 PHPeclipsePlugin.log(status);
126 * Returns the ImageDescriptor for the icon with the given path
128 * @return the ImageDescriptor object
130 public ImageDescriptor getImageDescriptor(String path) {
132 URL installURL = PHPeclipsePlugin.getDefault().getDescriptor().getInstallURL();
133 URL url = new URL(installURL, path);
134 return ImageDescriptor.createFromURL(url);
135 } catch (MalformedURLException e) {
141 * Method declared in AbstractUIPlugin.
143 public void initializeDefaultPreferences(IPreferenceStore prefs) {
144 prefs.setDefault(IPreferenceConstants.PROMPT_FOR_MIGRATION, true);
146 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_ERROR_RGB, new RGB(255, 0, 0)); // red - exactly the same as debug Consol
147 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_WARNING_RGB, new RGB(255, 100, 0)); // orange
148 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_INFO_RGB, new RGB(0, 0, 255)); // blue
149 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_VERBOSE_RGB, new RGB(0, 200, 125)); // green
150 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_DEBUG_RGB, new RGB(0, 0, 0)); // black
153 public static IWorkbenchWindow getActiveWorkbenchWindow() {
154 return PHPeclipsePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
158 * Returns the standard display to be used. The method first checks, if
159 * the thread calling this method has an associated display. If so, this
160 * display is returned. Otherwise the method returns the default display.
162 // public static Display getStandardDisplay() {
163 // Display display = Display.getCurrent();
164 // if (display == null) {
165 // display = Display.getDefault();
171 * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
173 protected ImageRegistry createImageRegistry() {
174 return ExternalToolsImages.initializeImageRegistry();
178 * @see org.eclipse.core.runtime.Plugin#startup()
180 // public void startup() throws CoreException {
181 //// super.startup();
182 // getStandardDisplay().asyncExec(
184 // public void run() {
185 // //initialize the variable context manager
186 // VariableContextManager.getDefault();
192 // * @see org.eclipse.core.runtime.Plugin#shutdown()
194 // public void shutdown() throws CoreException {
195 // // super.shutdown();
196 // ColorManager.getDefault().dispose();
200 * Returns the preference color, identified by the given preference.
202 public static Color getPreferenceColor(String pref) {
203 return ColorManager.getDefault().getColor(PreferenceConverter.getColor(PHPeclipsePlugin.getDefault().getPreferenceStore(), pref));