1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 IBM Corporation - Initial implementation
10 Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse;
14 import java.util.MissingResourceException;
15 import java.util.ResourceBundle;
17 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
18 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
19 import org.eclipse.core.resources.IWorkspace;
20 import org.eclipse.core.resources.ResourcesPlugin;
21 import org.eclipse.core.runtime.IPath;
22 import org.eclipse.core.runtime.IPluginDescriptor;
23 import org.eclipse.core.runtime.IStatus;
24 import org.eclipse.core.runtime.Path;
25 import org.eclipse.jface.preference.IPreferenceStore;
26 import org.eclipse.jface.preference.PreferenceConverter;
27 import org.eclipse.swt.widgets.Shell;
28 import org.eclipse.ui.IWorkbenchPage;
29 import org.eclipse.ui.IWorkbenchWindow;
30 import org.eclipse.ui.plugin.AbstractUIPlugin;
33 * The main plugin class to be used in the desktop.
35 public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceConstants {
36 // public static final String LOCALHOST_PREF = "_localhost";
37 // public static final String DOCUMENTROOT_PREF = "_documentroot";
38 // public static final String USE_EXTERNAL_BROWSER_PREF = "_use_external_browser";
39 // public static final String EXTERNAL_BROWSER_PREF = "_external_browser";
40 // public static final String MYSQL_PREF = "_my_sql";
41 // public static final String APACHE_START_PREF = "_apache_start";
42 // public static final String APACHE_STOP_PREF = "_apache_stop";
43 // public static final String APACHE_RESTART_PREF = "_apache_restart";
44 // public static final String SHOW_OUTPUT_IN_CONSOLE = "_sho_output_in_console";
45 // public static final String EXTERNAL_PARSER_PREF = "_external_parser";
48 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
50 public static final String ID_PLUGIN = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
52 //The shared instance.
53 private static PHPeclipsePlugin plugin;
55 private ResourceBundle resourceBundle;
57 private PHPDocumentProvider fCompilationUnitDocumentProvider;
59 * The Java virtual machine that we are running on.
61 private static int jvm;
64 private static final int MRJ_2_0 = 0;
66 /** MRJ 2.1 or later */
67 private static final int MRJ_2_1 = 1;
69 /** Java on Mac OS X 10.0 (MRJ 3.0) */
70 private static final int MRJ_3_0 = 3;
73 private static final int MRJ_3_1 = 4;
76 private static final int WINDOWS_NT = 5;
79 private static final int WINDOWS_9x = 6;
81 /** JVM constant for any other platform */
82 private static final int OTHER = -1;
86 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
91 resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
92 } catch (MissingResourceException x) {
93 resourceBundle = null;
97 // @TODO: refactor this into a better method name !
98 public PHPDocumentProvider getCompilationUnitDocumentProvider() {
99 if (fCompilationUnitDocumentProvider == null)
100 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
101 return fCompilationUnitDocumentProvider;
104 public static void setJVM() {
105 String osName = System.getProperty("os.name");
107 if (osName.startsWith("Mac OS")) {
108 String mrjVersion = System.getProperty("mrj.version");
109 String majorMRJVersion = mrjVersion.substring(0, 3);
113 double version = Double.valueOf(majorMRJVersion).doubleValue();
117 } else if (version >= 2.1 && version < 3) {
119 } else if (version == 3.0) {
121 } else if (version >= 3.1) {
125 } catch (NumberFormatException nfe) {
129 } else if (osName.startsWith("Windows")) {
130 if (osName.indexOf("9") != -1) {
137 public static int getJVM() {
141 * Returns the shared instance.
143 public static PHPeclipsePlugin getDefault() {
148 * Returns the workspace instance.
150 public static IWorkspace getWorkspace() {
151 return ResourcesPlugin.getWorkspace();
154 public static IWorkbenchPage getActivePage() {
155 return getDefault().getActivePage();
158 public static IWorkbenchWindow getActiveWorkbenchWindow() {
159 return getDefault().getWorkbench().getActiveWorkbenchWindow();
162 public static Shell getActiveWorkbenchShell() {
163 return getActiveWorkbenchWindow().getShell();
166 public static String getPluginId() {
167 return getDefault().getDescriptor().getUniqueIdentifier();
170 public static void log(IStatus status) {
171 getDefault().getLog().log(status);
174 // public static void logErrorMessage(String message) {
175 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
178 // public static void logErrorStatus(String message, IStatus status) {
179 // if (status == null) {
180 // logErrorMessage(message);
183 // MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
184 // multi.add(status);
188 // public static void log(Throwable e) {
189 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
192 public static boolean isDebug() {
193 return getDefault().isDebugging();
196 static IPath getInstallLocation() {
197 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
201 * Returns the string from the plugin's resource bundle,
202 * or 'key' if not found.
204 public static String getResourceString(String key) {
205 ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
207 return bundle.getString(key);
208 } catch (MissingResourceException e) {
214 * Returns the plugin's resource bundle,
216 public ResourceBundle getResourceBundle() {
217 return resourceBundle;
220 protected void initializeDefaultPreferences(IPreferenceStore store) {
221 // windows preferences:
222 store.setDefault(LOCALHOST_PREF, "http://localhost");
224 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
225 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
226 if (jvm == WINDOWS_9x) {
227 store.setDefault(EXTERNAL_BROWSER_PREF, "command.com /c start iexplore {0}");
228 } else if (jvm == WINDOWS_NT) {
229 store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
231 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
233 if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
234 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
235 store.setDefault(DOCUMENTROOT_PREF, "c:\\eclipse\\workspace");
236 store.setDefault(MYSQL_PREF, "c:\\apache\\mysql\\bin\\mysqld.exe --standalone");
237 store.setDefault(APACHE_START_PREF, "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\"");
238 store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
239 store.setDefault(APACHE_RESTART_PREF, "c:\\apache\\apache.exe -k restart");
241 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
242 store.setDefault(DOCUMENTROOT_PREF, "/eclipse/workspace");
243 store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
244 store.setDefault(APACHE_START_PREF, "/apache/apache -c \"DocumentRoot \"{0}\"\"");
245 store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
246 store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");
250 store.setDefault(PHP_PARSER_DEFAULT, PHP_INTERNAL_PARSER);
251 store.setDefault(PHP_INTERNAL_PARSER, "true");
252 store.setDefault(PHP_EXTERNAL_PARSER, "false");
254 store.setDefault(PHP_PARSE_ON_SAVE, "true");
255 // php syntax highlighting
256 PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT, PHPColorProvider.MULTI_LINE_COMMENT);
257 PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT, PHPColorProvider.SINGLE_LINE_COMMENT);
258 PreferenceConverter.setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
259 PreferenceConverter.setDefault(store, PHP_VARIABLE, PHPColorProvider.VARIABLE);
260 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME, PHPColorProvider.FUNCTION_NAME);
261 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
262 PreferenceConverter.setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);