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 net.sourceforge.phpeclipse.resourcesview.*;
21 import org.eclipse.core.resources.IResource;
22 import org.eclipse.core.resources.IWorkspace;
23 import org.eclipse.core.resources.ResourcesPlugin;
24 import org.eclipse.core.runtime.CoreException;
25 import org.eclipse.core.runtime.IAdapterManager;
26 import org.eclipse.core.runtime.IPath;
27 import org.eclipse.core.runtime.IPluginDescriptor;
28 import org.eclipse.core.runtime.IStatus;
29 import org.eclipse.core.runtime.Path;
30 import org.eclipse.core.runtime.Platform;
31 import org.eclipse.core.runtime.Status;
32 import org.eclipse.jface.preference.IPreferenceStore;
33 import org.eclipse.jface.preference.PreferenceConverter;
34 import org.eclipse.swt.widgets.Shell;
35 import org.eclipse.ui.IWorkbenchPage;
36 import org.eclipse.ui.IWorkbenchWindow;
37 import org.eclipse.ui.plugin.AbstractUIPlugin;
40 * The main plugin class to be used in the desktop.
42 public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceConstants {
43 // public static final String LOCALHOST_PREF = "_localhost";
44 // public static final String DOCUMENTROOT_PREF = "_documentroot";
45 // public static final String USE_EXTERNAL_BROWSER_PREF = "_use_external_browser";
46 // public static final String EXTERNAL_BROWSER_PREF = "_external_browser";
47 // public static final String MYSQL_PREF = "_my_sql";
48 // public static final String APACHE_START_PREF = "_apache_start";
49 // public static final String APACHE_STOP_PREF = "_apache_stop";
50 // public static final String APACHE_RESTART_PREF = "_apache_restart";
51 // public static final String SHOW_OUTPUT_IN_CONSOLE = "_sho_output_in_console";
52 // public static final String EXTERNAL_PARSER_PREF = "_external_parser";
55 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
57 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
58 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
59 public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID + ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
61 //The shared instance.
62 private static PHPeclipsePlugin plugin;
64 private ResourceBundle resourceBundle;
66 private PHPDocumentProvider fCompilationUnitDocumentProvider;
68 * The Java virtual machine that we are running on.
70 private static int jvm;
73 private static final int MRJ_2_0 = 0;
75 /** MRJ 2.1 or later */
76 private static final int MRJ_2_1 = 1;
78 /** Java on Mac OS X 10.0 (MRJ 3.0) */
79 private static final int MRJ_3_0 = 3;
82 private static final int MRJ_3_1 = 4;
85 private static final int WINDOWS_NT = 5;
88 private static final int WINDOWS_9x = 6;
90 /** JVM constant for any other platform */
91 private static final int OTHER = -1;
95 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
100 resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
101 } catch (MissingResourceException x) {
102 resourceBundle = null;
106 // @TODO: refactor this into a better method name !
107 public PHPDocumentProvider getCompilationUnitDocumentProvider() {
108 if (fCompilationUnitDocumentProvider == null)
109 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
110 return fCompilationUnitDocumentProvider;
113 public static void setJVM() {
114 String osName = System.getProperty("os.name");
116 if (osName.startsWith("Mac OS")) {
117 String mrjVersion = System.getProperty("mrj.version");
118 String majorMRJVersion = mrjVersion.substring(0, 3);
122 double version = Double.valueOf(majorMRJVersion).doubleValue();
126 } else if (version >= 2.1 && version < 3) {
128 } else if (version == 3.0) {
130 } else if (version >= 3.1) {
134 } catch (NumberFormatException nfe) {
138 } else if (osName.startsWith("Windows")) {
139 if (osName.indexOf("9") != -1) {
146 public static int getJVM() {
150 * Returns the shared instance.
152 public static PHPeclipsePlugin getDefault() {
157 * Returns the workspace instance.
159 public static IWorkspace getWorkspace() {
160 return ResourcesPlugin.getWorkspace();
163 public static IWorkbenchPage getActivePage() {
164 return getDefault().getActivePage();
167 public static IWorkbenchWindow getActiveWorkbenchWindow() {
168 return getDefault().getWorkbench().getActiveWorkbenchWindow();
171 public static Shell getActiveWorkbenchShell() {
172 return getActiveWorkbenchWindow().getShell();
175 public static String getPluginId() {
176 return getDefault().getDescriptor().getUniqueIdentifier();
179 public static void log(IStatus status) {
180 getDefault().getLog().log(status);
183 // public static void logErrorMessage(String message) {
184 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
187 // public static void logErrorStatus(String message, IStatus status) {
188 // if (status == null) {
189 // logErrorMessage(message);
192 // MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
193 // multi.add(status);
197 // public static void log(Throwable e) {
198 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
201 public static void log(Throwable e) {
202 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
204 public static boolean isDebug() {
205 return getDefault().isDebugging();
208 static IPath getInstallLocation() {
209 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
213 * Returns the string from the plugin's resource bundle,
214 * or 'key' if not found.
216 public static String getResourceString(String key) {
217 ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
219 return bundle.getString(key);
220 } catch (MissingResourceException e) {
226 * Returns the plugin's resource bundle,
228 public ResourceBundle getResourceBundle() {
229 return resourceBundle;
232 protected void initializeDefaultPreferences(IPreferenceStore store) {
233 // windows preferences:
234 store.setDefault(LOCALHOST_PREF, "http://localhost");
236 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
237 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
238 if (jvm == WINDOWS_9x) {
239 store.setDefault(EXTERNAL_BROWSER_PREF, "command.com /c start iexplore {0}");
240 } else if (jvm == WINDOWS_NT) {
241 store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
243 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
245 if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
246 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
247 store.setDefault(DOCUMENTROOT_PREF, "c:\\eclipse\\workspace");
248 store.setDefault(MYSQL_PREF, "c:\\apache\\mysql\\bin\\mysqld.exe --standalone");
249 store.setDefault(APACHE_START_PREF, "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\"");
250 store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
251 store.setDefault(APACHE_RESTART_PREF, "c:\\apache\\apache.exe -k restart");
253 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
254 store.setDefault(DOCUMENTROOT_PREF, "/eclipse/workspace");
255 store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
256 store.setDefault(APACHE_START_PREF, "/apache/apache -c \"DocumentRoot \"{0}\"\"");
257 store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
258 store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");
262 store.setDefault(PHP_PARSER_DEFAULT, PHP_INTERNAL_PARSER);
263 store.setDefault(PHP_INTERNAL_PARSER, "true");
264 store.setDefault(PHP_EXTERNAL_PARSER, "false");
266 store.setDefault(PHP_PARSE_ON_SAVE, "true");
267 // php syntax highlighting
268 PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT, PHPColorProvider.MULTI_LINE_COMMENT);
269 PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT, PHPColorProvider.SINGLE_LINE_COMMENT);
270 PreferenceConverter.setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
271 PreferenceConverter.setDefault(store, PHP_VARIABLE, PHPColorProvider.VARIABLE);
272 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME, PHPColorProvider.FUNCTION_NAME);
273 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
274 PreferenceConverter.setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
275 PreferenceConverter.setDefault(store, LINKED_POSITION_COLOR, PHPColorProvider.LINKED_POSITION_COLOR);
279 public void startup() throws CoreException {
281 IAdapterManager manager= Platform.getAdapterManager();
282 manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
283 manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);