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.IPluginDescriptor;
29 import org.eclipse.core.runtime.IStatus;
30 import org.eclipse.core.runtime.Path;
31 import org.eclipse.core.runtime.Platform;
32 import org.eclipse.core.runtime.Status;
33 import org.eclipse.jface.preference.IPreferenceStore;
34 import org.eclipse.jface.preference.PreferenceConverter;
35 import org.eclipse.jface.resource.ImageDescriptor;
36 import org.eclipse.jface.resource.ImageRegistry;
37 import org.eclipse.swt.graphics.Color;
38 import org.eclipse.swt.graphics.RGB;
39 import org.eclipse.swt.widgets.Display;
40 import org.eclipse.ui.IWorkbenchWindow;
41 import org.eclipse.ui.plugin.AbstractUIPlugin;
42 import org.osgi.framework.Bundle;
45 * External tools plug-in class
47 public final class ExternalToolsPlugin extends AbstractUIPlugin {
48 public static final String XAMPP_START_PREF = "_xampp_start_pref";
50 public static final String XAMPP_STOP_PREF = "_xampp_stop_pref";
52 public static final String MYSQL_RUN_PREF = "_mysql_run_pref";
54 public static final String MYSQL_START_BACKGROUND = "_mysql_start_background";
56 public static final String MYSQL_PREF = "__mysql_start";
58 public static final String APACHE_RUN_PREF = "_apache_run_pref";
60 public static final String APACHE_START_BACKGROUND = "_apache_start_background";
62 public static final String APACHE_START_PREF = "__apache_start";
64 public static final String APACHE_STOP_BACKGROUND = "_apache_stop_background";
66 public static final String APACHE_STOP_PREF = "__apache_stop";
68 public static final String APACHE_RESTART_BACKGROUND = "_apache_restart_background";
70 public static final String APACHE_RESTART_PREF = "__apache_restart";
72 // public static final String SHOW_OUTPUT_IN_CONSOLE = "_show_output_in_console";
74 public static final String PHP_RUN_PREF = "_php_run_pref";
76 public static final String EXTERNAL_PARSER_PREF = "_external_parser";
79 * Status representing no problems encountered during operation.
81 public static final IStatus OK_STATUS = new Status(IStatus.OK, IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
83 private static ExternalToolsPlugin plugin;
85 private RefreshScopeVariableRegistry refreshVarRegistry;
87 private PathLocationVariableRegistry fileLocVarRegistry;
89 private PathLocationVariableRegistry dirLocVarRegistry;
91 private ArgumentVariableRegistry argumentVarRegistry;
95 * This version is recommended for eclipse3.0 and above
97 public ExternalToolsPlugin() {
103 * Returns the default instance of the receiver. This represents the runtime plugin.
105 public static ExternalToolsPlugin getDefault() {
110 * Returns a new <code>IStatus</code> for this plug-in
112 public static IStatus newErrorStatus(String message, Throwable exception) {
113 return new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception);
117 * Returns a new <code>CoreException</code> for this plug-in
119 public static CoreException newError(String message, Throwable exception) {
120 return new CoreException(new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception));
124 * Returns the registry of refresh scope variables.
126 public ArgumentVariableRegistry getArgumentVariableRegistry() {
127 if (argumentVarRegistry == null)
128 argumentVarRegistry = new ArgumentVariableRegistry();
129 return argumentVarRegistry;
133 * Returns the registry of directory location variables.
135 public PathLocationVariableRegistry getDirectoryLocationVariableRegistry() {
136 if (dirLocVarRegistry == null)
137 dirLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_DIRECTORY_VARIABLES);
138 return dirLocVarRegistry;
142 * Returns the registry of file location variables.
144 public PathLocationVariableRegistry getFileLocationVariableRegistry() {
145 if (fileLocVarRegistry == null)
146 fileLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_FILE_VARIABLES);
147 return fileLocVarRegistry;
151 * Returns the registry of refresh scope variables.
153 public RefreshScopeVariableRegistry getRefreshVariableRegistry() {
154 if (refreshVarRegistry == null)
155 refreshVarRegistry = new RefreshScopeVariableRegistry();
156 return refreshVarRegistry;
160 * Writes the message to the plug-in's log
163 * the text to write to the log
165 public void log(String message, Throwable exception) {
166 IStatus status = newErrorStatus(message, exception);
167 // getLog().log(status);
168 ExternalToolsPlugin.log(status);
171 public static void log(IStatus status) {
172 getDefault().getLog().log(status);
176 * Returns the ImageDescriptor for the icon with the given path
178 * @return the ImageDescriptor object
180 public ImageDescriptor getImageDescriptor(String path) {
182 Bundle bundle = ExternalToolsPlugin.getDefault().getBundle();
183 URL installURL = bundle.getEntry("/"); //$NON-NLS-1$
184 URL url = new URL(installURL, path);
185 return ImageDescriptor.createFromURL(url);
186 } catch (MalformedURLException e) {
192 * (non-Javadoc) Method declared in AbstractUIPlugin.
195 protected void initializeDefaultPreferences(IPreferenceStore store) {
196 String operatingSystem = Platform.getOS();
197 // maxosx, linux, solaris, win32,...
199 InputStream is = getDefault().openStream(new Path("prefs/default_" + operatingSystem + ".properties"));
200 PropertyResourceBundle resourceBundle = new PropertyResourceBundle(is);
201 Enumeration enum = resourceBundle.getKeys();
203 while (enum.hasMoreElements()) {
204 key = (String) enum.nextElement();
205 store.setDefault(key, resourceBundle.getString(key));
207 } catch (Exception e) {
208 // no default properties found
209 if (operatingSystem.equals(Platform.OS_WIN32)) {
210 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
211 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
212 store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
213 store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
214 store.setDefault(XAMPP_START_PREF, "c:\\xampp\\xampp_start.exe");
215 store.setDefault(XAMPP_STOP_PREF, "c:\\xampp\\xampp_stop.exe");
217 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
218 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
219 store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
220 store.setDefault(APACHE_RUN_PREF, "/apache/apache");
221 store.setDefault(XAMPP_START_PREF, "xamp/xampp_start");
222 store.setDefault(XAMPP_STOP_PREF, "xampp/xampp_stop");
224 store.setDefault(MYSQL_PREF, "--standalone");
225 store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
226 store.setDefault(APACHE_STOP_PREF, "-k shutdown");
227 store.setDefault(APACHE_RESTART_PREF, "-k restart");
228 store.setDefault(MYSQL_START_BACKGROUND, "true");
229 store.setDefault(APACHE_START_BACKGROUND, "true");
230 store.setDefault(APACHE_STOP_BACKGROUND, "true");
231 store.setDefault(APACHE_RESTART_BACKGROUND, "true");
234 // store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
236 store.setDefault(IPreferenceConstants.PROMPT_FOR_MIGRATION, true);
238 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_ERROR_RGB, new RGB(255, 0, 0)); // red - exactly the same as
240 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_WARNING_RGB, new RGB(255, 100, 0)); // orange
241 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_INFO_RGB, new RGB(0, 0, 255)); // blue
242 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_VERBOSE_RGB, new RGB(0, 200, 125)); // green
243 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_DEBUG_RGB, new RGB(0, 0, 0)); // black
246 public static IWorkbenchWindow getActiveWorkbenchWindow() {
247 return ExternalToolsPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
251 * Returns the standard display to be used. The method first checks, if the thread calling this method has an associated display.
252 * If so, this display is returned. Otherwise the method returns the default display.
254 public static Display getStandardDisplay() {
255 Display display = Display.getCurrent();
256 if (display == null) {
257 display = Display.getDefault();
263 * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
265 protected ImageRegistry createImageRegistry() {
266 return ExternalToolsImages.initializeImageRegistry();
270 * @see org.eclipse.core.runtime.Plugin#startup()
272 public void startup() throws CoreException {
274 getStandardDisplay().asyncExec(new Runnable() {
276 //initialize the variable context manager
277 VariableContextManager.getDefault();
283 * @see org.eclipse.core.runtime.Plugin#shutdown()
285 public void shutdown() throws CoreException {
287 ColorManager.getDefault().dispose();
291 * Returns the preference color, identified by the given preference.
293 public static Color getPreferenceColor(String pref) {
294 return ColorManager.getDefault().getColor(
295 PreferenceConverter.getColor(ExternalToolsPlugin.getDefault().getPreferenceStore(), pref));