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 net.sourceforge.phpdt.internal.ui.preferences.TemplatePreferencePage;
15 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
16 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
17 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
18 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
19 import net.sourceforge.phpeclipse.resourcesview.PHPElement;
20 import net.sourceforge.phpeclipse.resourcesview.PHPElementAdapterFactory;
21 import net.sourceforge.phpeclipse.resourcesview.ResourceAdapterFactory;
23 import org.eclipse.core.boot.BootLoader;
24 import org.eclipse.core.resources.IResource;
25 import org.eclipse.core.resources.IWorkspace;
26 import org.eclipse.core.resources.ResourcesPlugin;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.core.runtime.IAdapterManager;
29 import org.eclipse.core.runtime.IPath;
30 import org.eclipse.core.runtime.IPluginDescriptor;
31 import org.eclipse.core.runtime.IStatus;
32 import org.eclipse.core.runtime.Path;
33 import org.eclipse.core.runtime.Platform;
34 import org.eclipse.core.runtime.Status;
35 import org.eclipse.jface.preference.IPreferenceStore;
36 import org.eclipse.jface.preference.PreferenceConverter;
37 import org.eclipse.swt.widgets.Shell;
38 import org.eclipse.ui.IWorkbenchPage;
39 import org.eclipse.ui.IWorkbenchWindow;
40 import org.eclipse.ui.plugin.AbstractUIPlugin;
43 * The main plugin class to be used in the desktop.
45 public class PHPeclipsePlugin
46 extends AbstractUIPlugin
47 implements IPreferenceConstants {
48 // public static final String LOCALHOST_PREF = "_localhost";
49 // public static final String DOCUMENTROOT_PREF = "_documentroot";
50 // public static final String USE_EXTERNAL_BROWSER_PREF = "_use_external_browser";
51 // public static final String EXTERNAL_BROWSER_PREF = "_external_browser";
52 // public static final String MYSQL_PREF = "_my_sql";
53 // public static final String APACHE_START_PREF = "_apache_start";
54 // public static final String APACHE_STOP_PREF = "_apache_stop";
55 // public static final String APACHE_RESTART_PREF = "_apache_restart";
56 // public static final String SHOW_OUTPUT_IN_CONSOLE = "_sho_output_in_console";
57 // public static final String EXTERNAL_PARSER_PREF = "_external_parser";
60 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
62 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
63 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
64 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID + ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
65 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID + ".ui.CodingActionSet"; //$NON-NLS-1$
67 public static final String PHPPARSER_NEW = "test.PHPParser";
68 public static final String PHPPARSER_ORIGINAL =
69 "net.sourceforge.phpdt.internal.compiler.parser.Parser";
71 /** Change this if you want to switch PHP Parser) */
72 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
74 //The shared instance.
75 private static PHPeclipsePlugin plugin;
77 //private ResourceBundle resourceBundle;
79 private ImageDescriptorRegistry fImageDescriptorRegistry;
80 private PHPDocumentProvider fCompilationUnitDocumentProvider;
82 * The Java virtual machine that we are running on.
84 private static int jvm;
87 private static final int MRJ_2_0 = 0;
89 /** MRJ 2.1 or later */
90 private static final int MRJ_2_1 = 1;
92 /** Java on Mac OS X 10.0 (MRJ 3.0) */
93 private static final int MRJ_3_0 = 3;
96 private static final int MRJ_3_1 = 4;
99 private static final int WINDOWS_NT = 5;
102 private static final int WINDOWS_9x = 6;
104 /** JVM constant for any other platform */
105 private static final int OTHER = -1;
107 /** General debug flag*/
108 public static final boolean DEBUG = false;
112 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
117 // resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
118 // } catch (MissingResourceException x) {
119 // resourceBundle = null;
123 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
124 return getDefault().internalGetImageDescriptorRegistry();
127 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
128 if (fImageDescriptorRegistry == null)
129 fImageDescriptorRegistry = new ImageDescriptorRegistry();
130 return fImageDescriptorRegistry;
132 // @TODO: refactor this into a better method name !
133 public PHPDocumentProvider getCompilationUnitDocumentProvider() {
134 if (fCompilationUnitDocumentProvider == null)
135 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
136 return fCompilationUnitDocumentProvider;
139 private static void setJVM() {
140 String osName = System.getProperty("os.name");
142 if (osName.startsWith("Mac OS")) {
143 String mrjVersion = System.getProperty("mrj.version");
144 String majorMRJVersion = mrjVersion.substring(0, 3);
148 double version = Double.valueOf(majorMRJVersion).doubleValue();
152 } else if (version >= 2.1 && version < 3) {
154 } else if (version == 3.0) {
156 } else if (version >= 3.1) {
160 } catch (NumberFormatException nfe) {
164 } else if (osName.startsWith("Windows")) {
165 if (osName.indexOf("9") != -1) {
172 public static int getJVM() {
176 * Returns the shared instance.
178 public static PHPeclipsePlugin getDefault() {
183 * Returns the workspace instance.
185 public static IWorkspace getWorkspace() {
186 return ResourcesPlugin.getWorkspace();
189 public static IWorkbenchPage getActivePage() {
190 return PHPeclipsePlugin.getActivePage();
193 public static IWorkbenchWindow getActiveWorkbenchWindow() {
194 return getDefault().getWorkbench().getActiveWorkbenchWindow();
197 public static Shell getActiveWorkbenchShell() {
198 return getActiveWorkbenchWindow().getShell();
201 public static String getPluginId() {
202 return getDefault().getDescriptor().getUniqueIdentifier();
205 public static void log(IStatus status) {
206 getDefault().getLog().log(status);
209 // public static void logErrorMessage(String message) {
210 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
213 // public static void logErrorStatus(String message, IStatus status) {
214 // if (status == null) {
215 // logErrorMessage(message);
218 // MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
219 // multi.add(status);
223 // public static void log(Throwable e) {
224 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
227 public static void log(int severity, String message) {
228 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
231 public static void log(Throwable e) {
232 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
235 public static boolean isDebug() {
236 return getDefault().isDebugging();
239 static IPath getInstallLocation() {
240 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
244 * Returns the string from the plugin's resource bundle,
245 * or 'key' if not found.
247 // public static String getResourceString(String key) {
248 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
250 // return bundle.getString(key);
251 // } catch (MissingResourceException e) {
257 * Returns the plugin's resource bundle,
259 // public ResourceBundle getResourceBundle() {
260 // return resourceBundle;
263 protected void initializeDefaultPreferences(IPreferenceStore store) {
264 // windows preferences:
265 store.setDefault(LOCALHOST_PREF, "http://localhost");
267 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
268 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
270 String windowsSystem = BootLoader.getWS();
272 if (jvm == WINDOWS_9x) {
274 EXTERNAL_BROWSER_PREF,
275 "command.com /c start iexplore {0}");
276 } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
278 EXTERNAL_BROWSER_PREF,
279 "rundll32 url.dll,FileProtocolHandler {0}");
281 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
285 getWorkspace().getRoot().getLocation().toString());
286 // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
287 if (windowsSystem.equals(BootLoader.WS_WIN32)) {
288 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
291 "c:\\apache\\mysql\\bin\\mysqld.exe --standalone");
294 "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\"");
295 store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
298 "c:\\apache\\apache.exe -k restart");
300 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
301 store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
304 "/apache/apache -c \"DocumentRoot \"{0}\"\"");
305 store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
306 store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");
310 store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
311 store.setDefault(PHP_INTERNAL_PARSER, "false");
312 store.setDefault(PHP_EXTERNAL_PARSER, "true");
314 store.setDefault(PHP_PARSE_ON_SAVE, "true");
316 // show line numbers:
317 store.setDefault(LINE_NUMBER_RULER, "false");
318 store.setDefault(FORMATTER_TAB_SIZE, "4");
320 // php syntax highlighting
321 store.setDefault(PHP_USERDEF_XMLFILE, ""); //assume there is none chooA
323 PreferenceConverter.setDefault(
325 PHP_MULTILINE_COMMENT,
326 PHPColorProvider.MULTI_LINE_COMMENT);
327 PreferenceConverter.setDefault(
329 PHP_SINGLELINE_COMMENT,
330 PHPColorProvider.SINGLE_LINE_COMMENT);
331 PreferenceConverter.setDefault(
334 PHPColorProvider.KEYWORD);
335 PreferenceConverter.setDefault(
338 PHPColorProvider.VARIABLE);
339 PreferenceConverter.setDefault(
342 PHPColorProvider.FUNCTION_NAME);
343 PreferenceConverter.setDefault(
346 PHPColorProvider.CONSTANT);
347 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
348 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
349 PreferenceConverter.setDefault(
352 PHPColorProvider.DEFAULT);
353 PreferenceConverter.setDefault(
355 PHP_EDITOR_BACKGROUND,
356 PHPColorProvider.BACKGROUND);
357 PreferenceConverter.setDefault(
359 LINKED_POSITION_COLOR,
360 PHPColorProvider.LINKED_POSITION_COLOR);
361 PreferenceConverter.setDefault(
364 PHPColorProvider.LINE_NUMBER_COLOR);
366 store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
367 PreferenceConverter.setDefault(
369 PREFERENCE_COLOR_BACKGROUND,
370 PHPColorProvider.BACKGROUND_COLOR);
373 store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
374 store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
375 store.setDefault(RESOURCE_BUNDLE_DE, "false");
376 store.setDefault(RESOURCE_BUNDLE_FR, "false");
377 store.setDefault(RESOURCE_BUNDLE_ES, "false");
379 store.setDefault(PHP_OUTLINE_CLASS, "true"); //$NON-NLS-1$
380 store.setDefault(PHP_OUTLINE_FUNC, "true"); //$NON-NLS-1$
381 store.setDefault(PHP_OUTLINE_VAR, "true"); //$NON-NLS-1$
383 TemplatePreferencePage.initDefaults(store);
385 //this will initialize the static fields in the syntaxrdr class
388 public void startup() throws CoreException {
390 IAdapterManager manager = Platform.getAdapterManager();
391 manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
392 manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);