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.io.InputStream;
13 import java.net.MalformedURLException;
15 import java.util.Enumeration;
16 import java.util.PropertyResourceBundle;
18 import net.sourceforge.phpdt.externaltools.internal.model.ColorManager;
19 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsImages;
20 import net.sourceforge.phpdt.externaltools.internal.model.IPreferenceConstants;
21 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
22 import net.sourceforge.phpdt.externaltools.internal.registry.ArgumentVariableRegistry;
23 import net.sourceforge.phpdt.externaltools.internal.registry.PathLocationVariableRegistry;
24 import net.sourceforge.phpdt.externaltools.internal.registry.RefreshScopeVariableRegistry;
25 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.core.runtime.IStatus;
29 import org.eclipse.core.runtime.Path;
30 import org.eclipse.core.runtime.Platform;
31 import org.eclipse.core.runtime.Status;
32 import org.eclipse.jface.preference.IPreferenceStore;
33 import org.eclipse.jface.preference.PreferenceConverter;
34 import org.eclipse.jface.resource.ImageDescriptor;
35 import org.eclipse.jface.resource.ImageRegistry;
36 import org.eclipse.swt.graphics.Color;
37 import org.eclipse.swt.graphics.RGB;
38 import org.eclipse.swt.widgets.Display;
39 import org.eclipse.ui.IWorkbenchWindow;
40 import org.eclipse.ui.plugin.AbstractUIPlugin;
41 import org.osgi.framework.Bundle;
44 * External tools plug-in class
46 public final class ExternalToolsPlugin extends AbstractUIPlugin {
47 public static final String XAMPP_START_PREF = "_xampp_start_pref";
49 public static final String XAMPP_STOP_PREF = "_xampp_stop_pref";
51 public static final String MYSQL_RUN_PREF = "_mysql_run_pref";
53 public static final String MYSQL_START_BACKGROUND = "_mysql_start_background";
55 public static final String MYSQL_PREF = "__mysql_start";
57 public static final String APACHE_RUN_PREF = "_apache_run_pref";
59 public static final String APACHE_START_BACKGROUND = "_apache_start_background";
61 public static final String APACHE_START_PREF = "__apache_start";
63 public static final String APACHE_STOP_BACKGROUND = "_apache_stop_background";
65 public static final String APACHE_STOP_PREF = "__apache_stop";
67 public static final String APACHE_RESTART_BACKGROUND = "_apache_restart_background";
69 public static final String APACHE_RESTART_PREF = "__apache_restart";
71 public static final String HTTPD_CONF_PATH_PREF = "__httpd_conf_path";
73 public static final String ETC_HOSTS_PATH_PREF = "__etc_hosts_path";
74 // public static final String SHOW_OUTPUT_IN_CONSOLE = "_show_output_in_console";
76 public static final String PHP_RUN_PREF = "_php_run_pref";
78 public static final String EXTERNAL_PARSER_PREF = "_external_parser";
81 * Status representing no problems encountered during operation.
83 public static final IStatus OK_STATUS = new Status(IStatus.OK, IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
85 private static ExternalToolsPlugin plugin;
87 private RefreshScopeVariableRegistry refreshVarRegistry;
89 private PathLocationVariableRegistry fileLocVarRegistry;
91 private PathLocationVariableRegistry dirLocVarRegistry;
93 private ArgumentVariableRegistry argumentVarRegistry;
97 * This version is recommended for eclipse3.0 and above
99 public ExternalToolsPlugin() {
105 * Returns the default instance of the receiver. This represents the runtime plugin.
107 public static ExternalToolsPlugin getDefault() {
112 * Returns a new <code>IStatus</code> for this plug-in
114 public static IStatus newErrorStatus(String message, Throwable exception) {
115 return new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception);
119 * Returns a new <code>CoreException</code> for this plug-in
121 public static CoreException newError(String message, Throwable exception) {
122 return new CoreException(new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception));
126 * Returns the registry of refresh scope variables.
128 public ArgumentVariableRegistry getArgumentVariableRegistry() {
129 if (argumentVarRegistry == null)
130 argumentVarRegistry = new ArgumentVariableRegistry();
131 return argumentVarRegistry;
135 * Returns the registry of directory location variables.
137 public PathLocationVariableRegistry getDirectoryLocationVariableRegistry() {
138 if (dirLocVarRegistry == null)
139 dirLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_DIRECTORY_VARIABLES);
140 return dirLocVarRegistry;
144 * Returns the registry of file location variables.
146 public PathLocationVariableRegistry getFileLocationVariableRegistry() {
147 if (fileLocVarRegistry == null)
148 fileLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_FILE_VARIABLES);
149 return fileLocVarRegistry;
153 * Returns the registry of refresh scope variables.
155 public RefreshScopeVariableRegistry getRefreshVariableRegistry() {
156 if (refreshVarRegistry == null)
157 refreshVarRegistry = new RefreshScopeVariableRegistry();
158 return refreshVarRegistry;
162 * Writes the message to the plug-in's log
165 * the text to write to the log
167 public void log(String message, Throwable exception) {
168 IStatus status = newErrorStatus(message, exception);
169 // getLog().log(status);
170 ExternalToolsPlugin.log(status);
173 public static void log(IStatus status) {
174 getDefault().getLog().log(status);
178 * Returns the ImageDescriptor for the icon with the given path
180 * @return the ImageDescriptor object
182 public ImageDescriptor getImageDescriptor(String path) {
184 Bundle bundle = ExternalToolsPlugin.getDefault().getBundle();
185 URL installURL = bundle.getEntry("/"); //$NON-NLS-1$
186 URL url = new URL(installURL, path);
187 return ImageDescriptor.createFromURL(url);
188 } catch (MalformedURLException e) {
194 * (non-Javadoc) Method declared in AbstractUIPlugin.
197 protected void initializeDefaultPreferences(IPreferenceStore store) {
198 String operatingSystem = Platform.getOS();
199 // maxosx, linux, solaris, win32,...
201 InputStream is = getDefault().openStream(new Path("prefs/default_" + operatingSystem + ".properties"));
202 PropertyResourceBundle resourceBundle = new PropertyResourceBundle(is);
203 Enumeration e = resourceBundle.getKeys();
205 while (e.hasMoreElements()) {
206 key = (String) e.nextElement();
207 store.setDefault(key, resourceBundle.getString(key));
209 } catch (Exception e) {
210 // no default properties found
211 if (operatingSystem.equals(Platform.OS_WIN32)) {
212 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
213 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
214 store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
215 store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
216 store.setDefault(XAMPP_START_PREF, "c:\\xampp\\xampp_start.exe");
217 store.setDefault(XAMPP_STOP_PREF, "c:\\xampp\\xampp_stop.exe");
218 store.setDefault(ETC_HOSTS_PATH_PREF, "c:\\windows\\system32\\drivers\\etc\\hosts");
220 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
221 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
222 store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
223 store.setDefault(APACHE_RUN_PREF, "/apache/apache");
224 store.setDefault(XAMPP_START_PREF, "xamp/xampp_start");
225 store.setDefault(XAMPP_STOP_PREF, "xampp/xampp_stop");
227 store.setDefault(MYSQL_PREF, "--standalone");
228 store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
229 store.setDefault(APACHE_STOP_PREF, "-k shutdown");
230 store.setDefault(APACHE_RESTART_PREF, "-k restart");
231 store.setDefault(MYSQL_START_BACKGROUND, "true");
232 store.setDefault(APACHE_START_BACKGROUND, "true");
233 store.setDefault(APACHE_STOP_BACKGROUND, "true");
234 store.setDefault(APACHE_RESTART_BACKGROUND, "true");
237 // store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
239 store.setDefault(IPreferenceConstants.PROMPT_FOR_MIGRATION, true);
241 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_ERROR_RGB, new RGB(255, 0, 0)); // red - exactly the same as
243 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_WARNING_RGB, new RGB(255, 100, 0)); // orange
244 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_INFO_RGB, new RGB(0, 0, 255)); // blue
245 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_VERBOSE_RGB, new RGB(0, 200, 125)); // green
246 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_DEBUG_RGB, new RGB(0, 0, 0)); // black
249 public static IWorkbenchWindow getActiveWorkbenchWindow() {
250 return ExternalToolsPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
254 * Returns the standard display to be used. The method first checks, if the thread calling this method has an associated display.
255 * If so, this display is returned. Otherwise the method returns the default display.
257 public static Display getStandardDisplay() {
258 Display display = Display.getCurrent();
259 if (display == null) {
260 display = Display.getDefault();
266 * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
268 protected ImageRegistry createImageRegistry() {
269 return ExternalToolsImages.initializeImageRegistry();
273 * @see org.eclipse.core.runtime.Plugin#startup()
275 public void startup() throws CoreException {
277 getStandardDisplay().asyncExec(new Runnable() {
279 //initialize the variable context manager
280 VariableContextManager.getDefault();
286 * @see org.eclipse.core.runtime.Plugin#shutdown()
288 public void shutdown() throws CoreException {
290 ColorManager.getDefault().dispose();
294 * Returns the preference color, identified by the given preference.
296 public static Color getPreferenceColor(String pref) {
297 return ColorManager.getDefault().getColor(
298 PreferenceConverter.getColor(ExternalToolsPlugin.getDefault().getPreferenceStore(), pref));