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 org.eclipse.core.resources.IWorkspace;
19 import org.eclipse.core.resources.ResourcesPlugin;
20 import org.eclipse.core.runtime.IPath;
21 import org.eclipse.core.runtime.IPluginDescriptor;
22 import org.eclipse.core.runtime.IStatus;
23 import org.eclipse.core.runtime.MultiStatus;
24 import org.eclipse.core.runtime.Path;
25 import org.eclipse.core.runtime.Status;
26 //import org.eclipse.jdt.internal.ui.JavaStatusConstants;
27 //import org.eclipse.jdt.internal.ui.JavaUIMessages;
28 import org.eclipse.jface.preference.IPreferenceStore;
29 import org.eclipse.swt.widgets.Shell;
30 import org.eclipse.ui.IWorkbenchPage;
31 import org.eclipse.ui.IWorkbenchWindow;
32 import org.eclipse.ui.plugin.AbstractUIPlugin;
35 * The main plugin class to be used in the desktop.
37 public class PHPeclipsePlugin extends AbstractUIPlugin {
38 public static final String LOCALHOST_PREF = "_localhost";
39 public static final String DOCUMENTROOT_PREF = "_documentroot";
40 public static final String USE_EXTERNAL_BROWSER_PREF = "_use_external_browser";
41 public static final String EXTERNAL_BROWSER_PREF = "_external_browser";
42 public static final String MYSQL_PREF = "_my_sql";
43 public static final String APACHE_START_PREF = "_apache_start";
44 public static final String APACHE_STOP_PREF = "_apache_stop";
45 public static final String APACHE_RESTART_PREF = "_apache_restart";
46 public static final String SHOW_OUTPUT_IN_CONSOLE = "_sho_output_in_console";
47 public static final String EXTERNAL_PARSER_PREF = "_external_parser";
50 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
52 public static final String ID_PLUGIN= "net.sourceforge.phpeclipse"; //$NON-NLS-1$
54 //The shared instance.
55 private static PHPeclipsePlugin plugin;
57 private ResourceBundle resourceBundle;
59 private PHPDocumentProvider fCompilationUnitDocumentProvider;
61 * The Java virtual machine that we are running on.
63 private static int jvm;
66 private static final int MRJ_2_0 = 0;
68 /** MRJ 2.1 or later */
69 private static final int MRJ_2_1 = 1;
71 /** Java on Mac OS X 10.0 (MRJ 3.0) */
72 private static final int MRJ_3_0 = 3;
75 private static final int MRJ_3_1 = 4;
78 private static final int WINDOWS_NT = 5;
81 private static final int WINDOWS_9x = 6;
83 /** JVM constant for any other platform */
84 private static final int OTHER = -1;
88 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
93 resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
94 } catch (MissingResourceException x) {
95 resourceBundle = null;
99 // @TODO: refactor this into a better method name !
100 public PHPDocumentProvider getCompilationUnitDocumentProvider() {
101 if (fCompilationUnitDocumentProvider == null)
102 fCompilationUnitDocumentProvider= new PHPDocumentProvider();
103 return fCompilationUnitDocumentProvider;
106 public static void setJVM() {
107 String osName = System.getProperty("os.name");
109 if (osName.startsWith("Mac OS")) {
110 String mrjVersion = System.getProperty("mrj.version");
111 String majorMRJVersion = mrjVersion.substring(0, 3);
115 double version = Double.valueOf(majorMRJVersion).doubleValue();
119 } else if (version >= 2.1 && version < 3) {
121 } else if (version == 3.0) {
123 } else if (version >= 3.1) {
127 } catch (NumberFormatException nfe) {
131 } else if (osName.startsWith("Windows")) {
132 if (osName.indexOf("9") != -1) {
139 public static int getJVM() {
143 * Returns the shared instance.
145 public static PHPeclipsePlugin getDefault() {
150 * Returns the workspace instance.
152 public static IWorkspace getWorkspace() {
153 return ResourcesPlugin.getWorkspace();
156 public static IWorkbenchPage getActivePage() {
157 return getDefault().getActivePage();
160 public static IWorkbenchWindow getActiveWorkbenchWindow() {
161 return getDefault().getWorkbench().getActiveWorkbenchWindow();
164 public static Shell getActiveWorkbenchShell() {
165 return getActiveWorkbenchWindow().getShell();
168 public static String getPluginId() {
169 return getDefault().getDescriptor().getUniqueIdentifier();
172 public static void log(IStatus status) {
173 getDefault().getLog().log(status);
176 // public static void logErrorMessage(String message) {
177 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
180 // public static void logErrorStatus(String message, IStatus status) {
181 // if (status == null) {
182 // logErrorMessage(message);
185 // MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
186 // multi.add(status);
190 // public static void log(Throwable e) {
191 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
194 public static boolean isDebug() {
195 return getDefault().isDebugging();
198 static IPath getInstallLocation() {
199 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
203 * Returns the string from the plugin's resource bundle,
204 * or 'key' if not found.
206 public static String getResourceString(String key) {
207 ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
209 return bundle.getString(key);
210 } catch (MissingResourceException e) {
216 * Returns the plugin's resource bundle,
218 public ResourceBundle getResourceBundle() {
219 return resourceBundle;
222 protected void initializeDefaultPreferences(IPreferenceStore store) {
223 // windows preferences:
224 store.setDefault(LOCALHOST_PREF, "http://localhost");
226 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
227 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
228 if (jvm == WINDOWS_9x) {
229 store.setDefault(EXTERNAL_BROWSER_PREF, "command.com /c start iexplore {0}");
230 } else if (jvm == WINDOWS_NT) {
231 store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
233 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
235 if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
236 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
237 store.setDefault(DOCUMENTROOT_PREF, "c:\\eclipse\\workspace");
238 store.setDefault(MYSQL_PREF, "c:\\apache\\mysql\\bin\\mysqld.exe --standalone");
239 store.setDefault(APACHE_START_PREF, "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\"");
240 store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
241 store.setDefault(APACHE_RESTART_PREF, "c:\\apache\\apache.exe -k restart");
243 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
244 store.setDefault(DOCUMENTROOT_PREF, "/eclipse/workspace");
245 store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
246 store.setDefault(APACHE_START_PREF, "/apache/apache -c \"DocumentRoot \"{0}\"\"");
247 store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
248 store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");