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";
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 if (jvm == WINDOWS_9x) {
226 store.setDefault(EXTERNAL_BROWSER_PREF, "command.com /c start iexplore {0}");
227 } else if (jvm == WINDOWS_NT) {
228 store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
230 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
232 if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
233 store.setDefault(DOCUMENTROOT_PREF, "c:\\eclipse\\workspace");
234 store.setDefault(MYSQL_PREF, "c:\\apache\\mysql\\bin\\mysqld.exe --standalone");
235 store.setDefault(APACHE_START_PREF, "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\"");
236 store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
237 store.setDefault(APACHE_RESTART_PREF, "c:\\apache\\apache.exe -k restart");
239 store.setDefault(DOCUMENTROOT_PREF, "/eclipse/workspace");
240 store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
241 store.setDefault(APACHE_START_PREF, "/apache/apache -c \"DocumentRoot \"{0}\"\"");
242 store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
243 store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");