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;
24 import org.eclipse.core.runtime.CoreException;
25 import org.eclipse.core.runtime.IStatus;
26 import org.eclipse.core.runtime.Status;
27 import org.eclipse.jface.preference.IPreferenceStore;
28 import org.eclipse.jface.preference.PreferenceConverter;
29 import org.eclipse.jface.resource.ImageDescriptor;
30 import org.eclipse.jface.resource.ImageRegistry;
31 import org.eclipse.swt.graphics.Color;
32 import org.eclipse.swt.graphics.RGB;
33 import org.eclipse.swt.widgets.Display;
34 import org.eclipse.ui.IWorkbenchWindow;
35 import org.eclipse.ui.plugin.AbstractUIPlugin;
36 import org.osgi.framework.Bundle;
39 * External tools plug-in class
41 public final class ExternalToolsPlugin extends AbstractUIPlugin {
42 public static final String XAMPP_START_PREF = "_xampp_start_pref";
44 public static final String XAMPP_STOP_PREF = "_xampp_stop_pref";
46 public static final String MYSQL_RUN_PREF = "_mysql_run_pref";
48 public static final String MYSQL_START_BACKGROUND = "_mysql_start_background";
50 public static final String MYSQL_PREF = "__mysql_start";
52 public static final String APACHE_RUN_PREF = "_apache_run_pref";
54 public static final String APACHE_START_BACKGROUND = "_apache_start_background";
56 public static final String APACHE_START_PREF = "__apache_start";
58 public static final String APACHE_STOP_BACKGROUND = "_apache_stop_background";
60 public static final String APACHE_STOP_PREF = "__apache_stop";
62 public static final String APACHE_RESTART_BACKGROUND = "_apache_restart_background";
64 public static final String APACHE_RESTART_PREF = "__apache_restart";
66 public static final String SHOW_OUTPUT_IN_CONSOLE = "_show_output_in_console";
68 public static final String PHP_RUN_PREF = "_php_run_pref";
71 * Status representing no problems encountered during operation.
73 public static final IStatus OK_STATUS = new Status(IStatus.OK, IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
75 private static ExternalToolsPlugin plugin;
77 private RefreshScopeVariableRegistry refreshVarRegistry;
79 private PathLocationVariableRegistry fileLocVarRegistry;
81 private PathLocationVariableRegistry dirLocVarRegistry;
83 private ArgumentVariableRegistry argumentVarRegistry;
86 * Create an instance of the External Tools plug-in.
88 public ExternalToolsPlugin() { // IPluginDescriptor descriptor) {
94 * Returns the default instance of the receiver. This represents the runtime plugin.
96 public static ExternalToolsPlugin getDefault() {
101 * Returns a new <code>IStatus</code> for this plug-in
103 public static IStatus newErrorStatus(String message, Throwable exception) {
104 return new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception);
108 * Returns a new <code>CoreException</code> for this plug-in
110 public static CoreException newError(String message, Throwable exception) {
111 return new CoreException(new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception));
115 * Returns the registry of refresh scope variables.
117 public ArgumentVariableRegistry getArgumentVariableRegistry() {
118 if (argumentVarRegistry == null)
119 argumentVarRegistry = new ArgumentVariableRegistry();
120 return argumentVarRegistry;
124 * Returns the registry of directory location variables.
126 public PathLocationVariableRegistry getDirectoryLocationVariableRegistry() {
127 if (dirLocVarRegistry == null)
128 dirLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_DIRECTORY_VARIABLES);
129 return dirLocVarRegistry;
133 * Returns the registry of file location variables.
135 public PathLocationVariableRegistry getFileLocationVariableRegistry() {
136 if (fileLocVarRegistry == null)
137 fileLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_FILE_VARIABLES);
138 return fileLocVarRegistry;
142 * Returns the registry of refresh scope variables.
144 public RefreshScopeVariableRegistry getRefreshVariableRegistry() {
145 if (refreshVarRegistry == null)
146 refreshVarRegistry = new RefreshScopeVariableRegistry();
147 return refreshVarRegistry;
151 * Writes the message to the plug-in's log
154 * the text to write to the log
156 public void log(String message, Throwable exception) {
157 IStatus status = newErrorStatus(message, exception);
158 // getLog().log(status);
159 ExternalToolsPlugin.log(status);
162 public static void log(IStatus status) {
163 getDefault().getLog().log(status);
167 * Returns the ImageDescriptor for the icon with the given path
169 * @return the ImageDescriptor object
171 public ImageDescriptor getImageDescriptor(String path) {
173 Bundle bundle = ExternalToolsPlugin.getDefault().getBundle();
174 URL installURL = bundle.getEntry("/"); //$NON-NLS-1$
175 URL url = new URL(installURL, path);
176 return ImageDescriptor.createFromURL(url);
177 } catch (MalformedURLException e) {
183 * (non-Javadoc) Method declared in AbstractUIPlugin.
185 public void initializeDefaultPreferences(IPreferenceStore prefs) {
186 prefs.setDefault(IPreferenceConstants.PROMPT_FOR_MIGRATION, true);
188 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_ERROR_RGB, new RGB(255, 0, 0)); // red - exactly the same as
190 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_WARNING_RGB, new RGB(255, 100, 0)); // orange
191 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_INFO_RGB, new RGB(0, 0, 255)); // blue
192 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_VERBOSE_RGB, new RGB(0, 200, 125)); // green
193 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_DEBUG_RGB, new RGB(0, 0, 0)); // black
196 public static IWorkbenchWindow getActiveWorkbenchWindow() {
197 return ExternalToolsPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
201 * Returns the standard display to be used. The method first checks, if the thread calling this method has an associated display.
202 * If so, this display is returned. Otherwise the method returns the default display.
204 public static Display getStandardDisplay() {
205 Display display = Display.getCurrent();
206 if (display == null) {
207 display = Display.getDefault();
213 * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
215 protected ImageRegistry createImageRegistry() {
216 return ExternalToolsImages.initializeImageRegistry();
220 * @see org.eclipse.core.runtime.Plugin#startup()
222 public void startup() throws CoreException {
224 getStandardDisplay().asyncExec(new Runnable() {
226 //initialize the variable context manager
227 VariableContextManager.getDefault();
233 * @see org.eclipse.core.runtime.Plugin#shutdown()
235 public void shutdown() throws CoreException {
237 ColorManager.getDefault().dispose();
241 * Returns the preference color, identified by the given preference.
243 public static Color getPreferenceColor(String pref) {
244 return ColorManager.getDefault().getColor(
245 PreferenceConverter.getColor(ExternalToolsPlugin.getDefault().getPreferenceStore(), pref));