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.swt.widgets.Display;
31 import org.eclipse.ui.IWorkbenchWindow;
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 URL installURL = PHPeclipsePlugin.getDefault().getDescriptor().getInstallURL();
134 URL url = new URL(installURL, path);
135 return ImageDescriptor.createFromURL(url);
136 } catch (MalformedURLException e) {
142 * Method declared in AbstractUIPlugin.
144 public void initializeDefaultPreferences(IPreferenceStore prefs) {
145 prefs.setDefault(IPreferenceConstants.PROMPT_FOR_MIGRATION, true);
147 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_ERROR_RGB, new RGB(255, 0, 0)); // red - exactly the same as debug Consol
148 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_WARNING_RGB, new RGB(255, 100, 0)); // orange
149 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_INFO_RGB, new RGB(0, 0, 255)); // blue
150 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_VERBOSE_RGB, new RGB(0, 200, 125)); // green
151 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_DEBUG_RGB, new RGB(0, 0, 0)); // black
154 public static IWorkbenchWindow getActiveWorkbenchWindow() {
155 return PHPeclipsePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
159 * Returns the standard display to be used. The method first checks, if
160 * the thread calling this method has an associated display. If so, this
161 * display is returned. Otherwise the method returns the default display.
163 // public static Display getStandardDisplay() {
164 // Display display = Display.getCurrent();
165 // if (display == null) {
166 // display = Display.getDefault();
172 * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
174 protected ImageRegistry createImageRegistry() {
175 return ExternalToolsImages.initializeImageRegistry();
179 * @see org.eclipse.core.runtime.Plugin#startup()
181 // public void startup() throws CoreException {
182 //// super.startup();
183 // getStandardDisplay().asyncExec(
185 // public void run() {
186 // //initialize the variable context manager
187 // VariableContextManager.getDefault();
193 // * @see org.eclipse.core.runtime.Plugin#shutdown()
195 // public void shutdown() throws CoreException {
196 // // super.shutdown();
197 // ColorManager.getDefault().dispose();
201 * Returns the preference color, identified by the given preference.
203 public static Color getPreferenceColor(String pref) {
204 return ColorManager.getDefault().getColor(PreferenceConverter.getColor(PHPeclipsePlugin.getDefault().getPreferenceStore(), pref));