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.ExternalToolsImages;
19 import net.sourceforge.phpdt.externaltools.internal.model.IPreferenceConstants;
20 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
21 import net.sourceforge.phpdt.externaltools.internal.registry.ArgumentVariableRegistry;
22 import net.sourceforge.phpdt.externaltools.internal.registry.PathLocationVariableRegistry;
23 import net.sourceforge.phpdt.externaltools.internal.registry.RefreshScopeVariableRegistry;
24 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
26 //import org.eclipse.core.runtime.CoreException;
27 import org.eclipse.core.runtime.IStatus;
28 import org.eclipse.core.runtime.Path;
29 import org.eclipse.core.runtime.Platform;
30 import org.eclipse.core.runtime.Status;
31 import org.eclipse.jface.preference.IPreferenceStore;
32 import org.eclipse.jface.preference.PreferenceConverter;
33 import org.eclipse.jface.resource.ImageDescriptor;
34 import org.eclipse.jface.resource.ImageRegistry;
35 import org.eclipse.swt.graphics.RGB;
36 import org.eclipse.swt.widgets.Display;
37 //import org.eclipse.ui.IWorkbenchWindow;
38 import org.eclipse.ui.plugin.AbstractUIPlugin;
39 import org.osgi.framework.Bundle;
40 import org.osgi.framework.BundleContext;
43 * External tools plug-in class
45 public final class ExternalToolsPlugin extends AbstractUIPlugin {
46 public static final String XAMPP_START_PREF = "_xampp_start_pref";
48 public static final String XAMPP_STOP_PREF = "_xampp_stop_pref";
50 public static final String MYSQL_RUN_PREF = "_mysql_run_pref";
52 public static final String MYSQL_START_BACKGROUND = "_mysql_start_background";
54 public static final String MYSQL_PREF = "__mysql_start";
56 public static final String APACHE_RUN_PREF = "_apache_run_pref";
58 public static final String APACHE_START_BACKGROUND = "_apache_start_background";
60 public static final String APACHE_START_PREF = "__apache_start";
62 public static final String APACHE_STOP_BACKGROUND = "_apache_stop_background";
64 public static final String APACHE_STOP_PREF = "__apache_stop";
66 public static final String APACHE_RESTART_BACKGROUND = "_apache_restart_background";
68 public static final String APACHE_RESTART_PREF = "__apache_restart";
70 public static final String HTTPD_CONF_PATH_PREF = "__httpd_conf_path";
72 public static final String ETC_HOSTS_PATH_PREF = "__etc_hosts_path";
74 // public static final String SHOW_OUTPUT_IN_CONSOLE =
75 // "_show_output_in_console";
77 public static final String PHP_RUN_PREF = "_php_run_pref";
79 public static final String EXTERNAL_PARSER_PREF = "_external_parser";
82 * Status representing no problems encountered during operation.
84 public static final IStatus OK_STATUS = new Status(IStatus.OK,
85 IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
87 private static ExternalToolsPlugin plugin;
89 private RefreshScopeVariableRegistry refreshVarRegistry;
91 private PathLocationVariableRegistry fileLocVarRegistry;
93 private PathLocationVariableRegistry dirLocVarRegistry;
95 private ArgumentVariableRegistry argumentVarRegistry;
98 * This version is recommended for eclipse3.0 and above
100 public ExternalToolsPlugin() {
106 * Returns the default instance of the receiver. This represents the runtime
109 public static ExternalToolsPlugin getDefault() {
114 * Returns a new <code>IStatus</code> for this plug-in
116 public static IStatus newErrorStatus(String message, Throwable exception) {
117 return new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0,
122 * Returns a new <code>CoreException</code> for this plug-in
124 // public static CoreException newError(String message, Throwable exception) {
125 // return new CoreException(new Status(Status.ERROR,
126 // IExternalToolConstants.PLUGIN_ID, 0, message, exception));
130 * Returns the registry of refresh scope variables.
132 public ArgumentVariableRegistry getArgumentVariableRegistry() {
133 if (argumentVarRegistry == null)
134 argumentVarRegistry = new ArgumentVariableRegistry();
135 return argumentVarRegistry;
139 * Returns the registry of directory location variables.
141 public PathLocationVariableRegistry getDirectoryLocationVariableRegistry() {
142 if (dirLocVarRegistry == null)
143 dirLocVarRegistry = new PathLocationVariableRegistry(
144 IExternalToolConstants.EXTENSION_POINT_DIRECTORY_VARIABLES);
145 return dirLocVarRegistry;
149 * Returns the registry of file location variables.
151 public PathLocationVariableRegistry getFileLocationVariableRegistry() {
152 if (fileLocVarRegistry == null)
153 fileLocVarRegistry = new PathLocationVariableRegistry(
154 IExternalToolConstants.EXTENSION_POINT_FILE_VARIABLES);
155 return fileLocVarRegistry;
159 * Returns the registry of refresh scope variables.
161 public RefreshScopeVariableRegistry getRefreshVariableRegistry() {
162 if (refreshVarRegistry == null)
163 refreshVarRegistry = new RefreshScopeVariableRegistry();
164 return refreshVarRegistry;
168 * Writes the message to the plug-in's log
171 * the text to write to the log
173 public void log(String message, Throwable exception) {
174 IStatus status = newErrorStatus(message, exception);
175 // getLog().log(status);
176 ExternalToolsPlugin.log(status);
179 public static void log(IStatus status) {
180 getDefault().getLog().log(status);
184 * Returns the ImageDescriptor for the icon with the given path
186 * @return the ImageDescriptor object
188 public ImageDescriptor getImageDescriptor(String path) {
190 Bundle bundle = ExternalToolsPlugin.getDefault().getBundle();
191 URL installURL = bundle.getEntry("/"); //$NON-NLS-1$
192 URL url = new URL(installURL, path);
193 return ImageDescriptor.createFromURL(url);
194 } catch (MalformedURLException e) {
200 * (non-Javadoc) Method declared in AbstractUIPlugin.
203 protected void initializeDefaultPreferences(IPreferenceStore store) {
204 String operatingSystem = Platform.getOS();
205 // maxosx, linux, solaris, win32,...
207 InputStream is = getDefault()
209 new Path("prefs/default_" + operatingSystem
211 PropertyResourceBundle resourceBundle = new PropertyResourceBundle(
213 Enumeration e = resourceBundle.getKeys();
215 while (e.hasMoreElements()) {
216 key = (String) e.nextElement();
217 store.setDefault(key, resourceBundle.getString(key));
219 } catch (Exception e) {
220 // no default properties found
221 if (operatingSystem.equals(Platform.OS_WIN32)) {
222 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
223 store.setDefault(EXTERNAL_PARSER_PREF,
224 "c:\\apache\\php\\php -l -f {0}");
225 store.setDefault(MYSQL_RUN_PREF,
226 "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
227 store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
229 .setDefault(XAMPP_START_PREF,
230 "c:\\xampp\\xampp_start.exe");
231 store.setDefault(XAMPP_STOP_PREF, "c:\\xampp\\xampp_stop.exe");
232 store.setDefault(ETC_HOSTS_PATH_PREF,
233 "c:\\windows\\system32\\drivers\\etc\\hosts");
235 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
236 store.setDefault(EXTERNAL_PARSER_PREF,
237 "/apache/php/php -l -f {0}");
238 store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
239 store.setDefault(APACHE_RUN_PREF, "/apache/apache");
240 store.setDefault(XAMPP_START_PREF, "xamp/xampp_start");
241 store.setDefault(XAMPP_STOP_PREF, "xampp/xampp_stop");
243 store.setDefault(MYSQL_PREF, "--standalone");
244 store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
245 store.setDefault(APACHE_STOP_PREF, "-k shutdown");
246 store.setDefault(APACHE_RESTART_PREF, "-k restart");
247 store.setDefault(MYSQL_START_BACKGROUND, "true");
248 store.setDefault(APACHE_START_BACKGROUND, "true");
249 store.setDefault(APACHE_STOP_BACKGROUND, "true");
250 store.setDefault(APACHE_RESTART_BACKGROUND, "true");
253 // store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
255 store.setDefault(IPreferenceConstants.PROMPT_FOR_MIGRATION, true);
257 PreferenceConverter.setDefault(store,
258 IPreferenceConstants.CONSOLE_ERROR_RGB, new RGB(255, 0, 0)); // red
265 PreferenceConverter.setDefault(store,
266 IPreferenceConstants.CONSOLE_WARNING_RGB, new RGB(255, 100, 0)); // orange
267 PreferenceConverter.setDefault(store,
268 IPreferenceConstants.CONSOLE_INFO_RGB, new RGB(0, 0, 255)); // blue
269 PreferenceConverter.setDefault(store,
270 IPreferenceConstants.CONSOLE_VERBOSE_RGB, new RGB(0, 200, 125)); // green
271 PreferenceConverter.setDefault(store,
272 IPreferenceConstants.CONSOLE_DEBUG_RGB, new RGB(0, 0, 0)); // black
275 // public static IWorkbenchWindow getActiveWorkbenchWindow() {
276 // return ExternalToolsPlugin.getDefault().getWorkbench()
277 // .getActiveWorkbenchWindow();
281 * Returns the standard display to be used. The method first checks, if the
282 * thread calling this method has an associated display. If so, this display
283 * is returned. Otherwise the method returns the default display.
285 public static Display getStandardDisplay() {
286 Display display = Display.getCurrent();
287 if (display == null) {
288 display = Display.getDefault();
294 * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
296 protected ImageRegistry createImageRegistry() {
297 return ExternalToolsImages.initializeImageRegistry();
302 * @see org.eclipse.core.runtime.Plugin#start(BundleContext context)
304 public void start(BundleContext context) throws Exception {
305 super.start(context);
306 getStandardDisplay().asyncExec(new Runnable() {
308 // initialize the variable context manager
309 VariableContextManager.getDefault();