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.externaltools.internal.model.ColorManager;
15 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsPlugin;
16 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
17 import net.sourceforge.phpdt.internal.ui.preferences.TemplatePreferencePage;
18 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
19 import net.sourceforge.phpdt.ui.PreferenceConstants;
20 import net.sourceforge.phpdt.ui.text.JavaTextTools;
21 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
22 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
23 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
24 import net.sourceforge.phpeclipse.resourcesview.PHPElement;
25 import net.sourceforge.phpeclipse.resourcesview.PHPElementAdapterFactory;
26 import net.sourceforge.phpeclipse.resourcesview.ResourceAdapterFactory;
28 import org.eclipse.core.boot.BootLoader;
29 import org.eclipse.core.resources.IFile;
30 import org.eclipse.core.resources.IResource;
31 import org.eclipse.core.resources.IWorkspace;
32 import org.eclipse.core.resources.ResourcesPlugin;
33 import org.eclipse.core.runtime.CoreException;
34 import org.eclipse.core.runtime.IAdapterManager;
35 import org.eclipse.core.runtime.IPath;
36 import org.eclipse.core.runtime.IPluginDescriptor;
37 import org.eclipse.core.runtime.IStatus;
38 import org.eclipse.core.runtime.Path;
39 import org.eclipse.core.runtime.Platform;
40 import org.eclipse.core.runtime.Status;
41 import org.eclipse.jface.preference.IPreferenceStore;
42 import org.eclipse.jface.preference.PreferenceConverter;
43 import org.eclipse.swt.widgets.Display;
44 import org.eclipse.swt.widgets.Shell;
45 import org.eclipse.ui.IWorkbenchPage;
46 import org.eclipse.ui.IWorkbenchWindow;
47 import org.eclipse.ui.plugin.AbstractUIPlugin;
50 * The main plugin class to be used in the desktop.
52 public class PHPeclipsePlugin
53 extends AbstractUIPlugin
54 implements IPreferenceConstants {
55 // public static final String LOCALHOST_PREF = "_localhost";
56 // public static final String DOCUMENTROOT_PREF = "_documentroot";
57 // public static final String USE_EXTERNAL_BROWSER_PREF = "_use_external_browser";
58 // public static final String EXTERNAL_BROWSER_PREF = "_external_browser";
59 // public static final String MYSQL_PREF = "_my_sql";
60 // public static final String APACHE_START_PREF = "_apache_start";
61 // public static final String APACHE_STOP_PREF = "_apache_stop";
62 // public static final String APACHE_RESTART_PREF = "_apache_restart";
63 // public static final String SHOW_OUTPUT_IN_CONSOLE = "_sho_output_in_console";
64 // public static final String EXTERNAL_PARSER_PREF = "_external_parser";
67 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
69 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
70 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
71 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID + ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
72 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID + ".ui.CodingActionSet"; //$NON-NLS-1$
74 public static final String PHPPARSER_NEW = "test.PHPParser";
75 public static final String PHPPARSER_ORIGINAL =
76 "net.sourceforge.phpdt.internal.compiler.parser.Parser";
78 /** Change this if you want to switch PHP Parser. */
79 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
81 //The shared instance.
82 private static PHPeclipsePlugin plugin;
84 private static ExternalToolsPlugin externalTools;
86 //private ResourceBundle resourceBundle;
88 private ImageDescriptorRegistry fImageDescriptorRegistry;
89 private PHPDocumentProvider fCompilationUnitDocumentProvider;
90 private IFile fLastEditorFile = null;
92 private JavaTextTools fJavaTextTools;
95 * The Java virtual machine that we are running on.
97 private static int jvm;
100 private static final int MRJ_2_0 = 0;
102 /** MRJ 2.1 or later */
103 private static final int MRJ_2_1 = 1;
105 /** Java on Mac OS X 10.0 (MRJ 3.0) */
106 private static final int MRJ_3_0 = 3;
109 private static final int MRJ_3_1 = 4;
112 private static final int WINDOWS_NT = 5;
115 private static final int WINDOWS_9x = 6;
117 /** JVM constant for any other platform */
118 private static final int OTHER = -1;
120 /** General debug flag*/
121 public static final boolean DEBUG = false;
125 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
129 externalTools = new ExternalToolsPlugin();
131 // resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
132 // } catch (MissingResourceException x) {
133 // resourceBundle = null;
137 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
138 return getDefault().internalGetImageDescriptorRegistry();
141 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
142 if (fImageDescriptorRegistry == null)
143 fImageDescriptorRegistry = new ImageDescriptorRegistry();
144 return fImageDescriptorRegistry;
146 // @TODO: refactor this into a better method name !
147 public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
148 if (fCompilationUnitDocumentProvider == null)
149 fCompilationUnitDocumentProvider= new PHPDocumentProvider();
150 return fCompilationUnitDocumentProvider;
153 private static void setJVM() {
154 String osName = System.getProperty("os.name");
156 if (osName.startsWith("Mac OS")) {
157 String mrjVersion = System.getProperty("mrj.version");
158 String majorMRJVersion = mrjVersion.substring(0, 3);
162 double version = Double.valueOf(majorMRJVersion).doubleValue();
166 } else if (version >= 2.1 && version < 3) {
168 } else if (version == 3.0) {
170 } else if (version >= 3.1) {
174 } catch (NumberFormatException nfe) {
178 } else if (osName.startsWith("Windows")) {
179 if (osName.indexOf("9") != -1) {
186 public static int getJVM() {
190 * Returns the shared instance.
192 public static PHPeclipsePlugin getDefault() {
196 // public static ExternalToolsPlugin getExternalTools() {
197 // return externalTools;
200 * Returns the workspace instance.
202 public static IWorkspace getWorkspace() {
203 return ResourcesPlugin.getWorkspace();
206 public static IWorkbenchPage getActivePage() {
207 return getDefault().internalGetActivePage();
210 private IWorkbenchPage internalGetActivePage() {
211 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
212 if (window!=null) return window.getActivePage();
216 public static IWorkbenchWindow getActiveWorkbenchWindow() {
217 return getDefault().getWorkbench().getActiveWorkbenchWindow();
220 public static Shell getActiveWorkbenchShell() {
221 return getActiveWorkbenchWindow().getShell();
224 public static String getPluginId() {
225 return getDefault().getDescriptor().getUniqueIdentifier();
228 public static void log(IStatus status) {
229 getDefault().getLog().log(status);
232 // public static void logErrorMessage(String message) {
233 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
236 // public static void logErrorStatus(String message, IStatus status) {
237 // if (status == null) {
238 // logErrorMessage(message);
241 // MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
242 // multi.add(status);
246 // public static void log(Throwable e) {
247 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
250 public static void log(int severity, String message) {
251 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
254 public static void log(Throwable e) {
255 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
258 public static boolean isDebug() {
259 return getDefault().isDebugging();
262 static IPath getInstallLocation() {
263 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
266 public synchronized JavaTextTools getJavaTextTools() {
267 if (fJavaTextTools == null)
268 fJavaTextTools= new JavaTextTools(getPreferenceStore());
269 return fJavaTextTools;
273 * Returns the string from the plugin's resource bundle,
274 * or 'key' if not found.
276 // public static String getResourceString(String key) {
277 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
279 // return bundle.getString(key);
280 // } catch (MissingResourceException e) {
286 * Returns the plugin's resource bundle,
288 // public ResourceBundle getResourceBundle() {
289 // return resourceBundle;
292 protected void initializeDefaultPreferences(IPreferenceStore store) {
293 // windows preferences:
294 store.setDefault(LOCALHOST_PREF, "http://localhost");
296 store.setDefault(SHOW_EXTERNAL_PREVIEW_PREF, "true");
297 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
298 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
300 String windowsSystem = BootLoader.getWS();
302 if (jvm == WINDOWS_9x) {
304 EXTERNAL_BROWSER_PREF,
305 "command.com /c start iexplore {0}");
306 } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
308 EXTERNAL_BROWSER_PREF,
309 "rundll32 url.dll,FileProtocolHandler {0}");
311 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
315 getWorkspace().getRoot().getLocation().toString());
317 // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
318 if (windowsSystem.equals(BootLoader.WS_WIN32)) {
319 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
320 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
323 "c:\\apache\\mysql\\bin\\mysqld-nt.exe --standalone");
326 "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\"");
327 store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
330 "c:\\apache\\apache.exe -k restart");
332 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
333 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
334 store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
337 "/apache/apache -c \"DocumentRoot \"{0}\"\"");
338 store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
339 store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");
343 store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
344 store.setDefault(PHP_INTERNAL_PARSER, "false");
345 store.setDefault(PHP_EXTERNAL_PARSER, "true");
347 store.setDefault(PHP_PARSE_ON_SAVE, "true");
349 // show line numbers:
350 // store.setDefault(LINE_NUMBER_RULER, "false");
351 // store.setDefault(FORMATTER_TAB_SIZE, "4");
353 // php syntax highlighting
354 store.setDefault(PHP_USERDEF_XMLFILE, ""); //assume there is none chooA
356 PreferenceConverter.setDefault(
358 PHP_MULTILINE_COMMENT,
359 PHPColorProvider.MULTI_LINE_COMMENT);
360 PreferenceConverter.setDefault(
362 PHP_SINGLELINE_COMMENT,
363 PHPColorProvider.SINGLE_LINE_COMMENT);
364 PreferenceConverter.setDefault(
367 PHPColorProvider.KEYWORD);
368 PreferenceConverter.setDefault(
371 PHPColorProvider.VARIABLE);
372 PreferenceConverter.setDefault(
375 PHPColorProvider.FUNCTION_NAME);
376 PreferenceConverter.setDefault(
379 PHPColorProvider.CONSTANT);
380 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
381 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
382 PreferenceConverter.setDefault(
385 PHPColorProvider.DEFAULT);
386 // PreferenceConverter.setDefault(
388 // PHP_EDITOR_BACKGROUND,
389 // PHPColorProvider.BACKGROUND);
390 // PreferenceConverter.setDefault(
392 // LINKED_POSITION_COLOR,
393 // PHPColorProvider.LINKED_POSITION_COLOR);
394 // PreferenceConverter.setDefault(
396 // LINE_NUMBER_COLOR,
397 // PHPColorProvider.LINE_NUMBER_COLOR);
399 // // set default PHPDoc colors:
400 // PreferenceConverter.setDefault(
403 // PHPColorProvider.PHPDOC_KEYWORD);
404 // PreferenceConverter.setDefault(
407 // PHPColorProvider.PHPDOC_LINK);
408 // PreferenceConverter.setDefault(
411 // PHPColorProvider.PHPDOC_DEFAULT);
412 // PreferenceConverter.setDefault(
415 // PHPColorProvider.PHPDOC_TAG);
417 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
418 // PreferenceConverter.setDefault(
420 // PREFERENCE_COLOR_BACKGROUND,
421 // PHPColorProvider.BACKGROUND_COLOR);
424 store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
425 store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
426 store.setDefault(RESOURCE_BUNDLE_DE, "false");
427 store.setDefault(RESOURCE_BUNDLE_FR, "false");
428 store.setDefault(RESOURCE_BUNDLE_ES, "false");
430 store.setDefault(PHP_OUTLINE_CLASS, "true"); //$NON-NLS-1$
431 store.setDefault(PHP_OUTLINE_FUNC, "true"); //$NON-NLS-1$
432 store.setDefault(PHP_OUTLINE_VAR, "true"); //$NON-NLS-1$
434 TemplatePreferencePage.initDefaults(store);
435 //this will initialize the static fields in the syntaxrdr class
438 PHPCore.initializeDefaultPluginPreferences();
439 PreferenceConstants.initializeDefaultValues(store);
441 externalTools.initializeDefaultPreferences(store);
445 * Returns the standard display to be used. The method first checks, if
446 * the thread calling this method has an associated display. If so, this
447 * display is returned. Otherwise the method returns the default display.
449 public static Display getStandardDisplay() {
450 Display display = Display.getCurrent();
451 if (display == null) {
452 display = Display.getDefault();
457 public void startup() throws CoreException {
459 IAdapterManager manager = Platform.getAdapterManager();
460 manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
461 manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
462 // externalTools.startUp();
463 getStandardDisplay().asyncExec(
466 //initialize the variable context manager
467 VariableContextManager.getDefault();
473 * @see org.eclipse.core.runtime.Plugin#shutdown()
475 public void shutdown() throws CoreException {
476 // externalTools.shutDown();
477 ColorManager.getDefault().dispose();
480 public void setLastEditorFile(IFile textEditor) {
481 this.fLastEditorFile = textEditor;
484 public IFile getLastEditorFile() {
485 return fLastEditorFile;