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.phpdt.ui.PreferenceConstants;
17 import net.sourceforge.phpdt.ui.text.JavaTextTools;
18 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
19 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
20 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
21 import net.sourceforge.phpeclipse.resourcesview.PHPElement;
22 import net.sourceforge.phpeclipse.resourcesview.PHPElementAdapterFactory;
23 import net.sourceforge.phpeclipse.resourcesview.ResourceAdapterFactory;
25 import org.eclipse.core.boot.BootLoader;
26 import org.eclipse.core.resources.IResource;
27 import org.eclipse.core.resources.IWorkspace;
28 import org.eclipse.core.resources.ResourcesPlugin;
29 import org.eclipse.core.runtime.CoreException;
30 import org.eclipse.core.runtime.IAdapterManager;
31 import org.eclipse.core.runtime.IPath;
32 import org.eclipse.core.runtime.IPluginDescriptor;
33 import org.eclipse.core.runtime.IStatus;
34 import org.eclipse.core.runtime.Path;
35 import org.eclipse.core.runtime.Platform;
36 import org.eclipse.core.runtime.Status;
37 import org.eclipse.jface.preference.IPreferenceStore;
38 import org.eclipse.jface.preference.PreferenceConverter;
39 import org.eclipse.swt.widgets.Shell;
40 import org.eclipse.ui.IWorkbenchPage;
41 import org.eclipse.ui.IWorkbenchWindow;
42 import org.eclipse.ui.plugin.AbstractUIPlugin;
43 import org.eclipse.ui.texteditor.ITextEditor;
46 * The main plugin class to be used in the desktop.
48 public class PHPeclipsePlugin
49 extends AbstractUIPlugin
50 implements IPreferenceConstants {
51 // public static final String LOCALHOST_PREF = "_localhost";
52 // public static final String DOCUMENTROOT_PREF = "_documentroot";
53 // public static final String USE_EXTERNAL_BROWSER_PREF = "_use_external_browser";
54 // public static final String EXTERNAL_BROWSER_PREF = "_external_browser";
55 // public static final String MYSQL_PREF = "_my_sql";
56 // public static final String APACHE_START_PREF = "_apache_start";
57 // public static final String APACHE_STOP_PREF = "_apache_stop";
58 // public static final String APACHE_RESTART_PREF = "_apache_restart";
59 // public static final String SHOW_OUTPUT_IN_CONSOLE = "_sho_output_in_console";
60 // public static final String EXTERNAL_PARSER_PREF = "_external_parser";
63 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
65 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
66 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
67 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID + ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
68 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID + ".ui.CodingActionSet"; //$NON-NLS-1$
70 public static final String PHPPARSER_NEW = "test.PHPParser";
71 public static final String PHPPARSER_ORIGINAL =
72 "net.sourceforge.phpdt.internal.compiler.parser.Parser";
74 /** Change this if you want to switch PHP Parser. */
75 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
77 //The shared instance.
78 private static PHPeclipsePlugin plugin;
80 //private ResourceBundle resourceBundle;
82 private ImageDescriptorRegistry fImageDescriptorRegistry;
83 private PHPDocumentProvider fCompilationUnitDocumentProvider;
84 private ITextEditor fTextEditor = null;
86 private JavaTextTools fJavaTextTools;
89 * The Java virtual machine that we are running on.
91 private static int jvm;
94 private static final int MRJ_2_0 = 0;
96 /** MRJ 2.1 or later */
97 private static final int MRJ_2_1 = 1;
99 /** Java on Mac OS X 10.0 (MRJ 3.0) */
100 private static final int MRJ_3_0 = 3;
103 private static final int MRJ_3_1 = 4;
106 private static final int WINDOWS_NT = 5;
109 private static final int WINDOWS_9x = 6;
111 /** JVM constant for any other platform */
112 private static final int OTHER = -1;
114 /** General debug flag*/
115 public static final boolean DEBUG = false;
119 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
124 // resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
125 // } catch (MissingResourceException x) {
126 // resourceBundle = null;
130 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
131 return getDefault().internalGetImageDescriptorRegistry();
134 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
135 if (fImageDescriptorRegistry == null)
136 fImageDescriptorRegistry = new ImageDescriptorRegistry();
137 return fImageDescriptorRegistry;
139 // @TODO: refactor this into a better method name !
140 public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
141 if (fCompilationUnitDocumentProvider == null)
142 fCompilationUnitDocumentProvider= new PHPDocumentProvider();
143 return fCompilationUnitDocumentProvider;
146 private static void setJVM() {
147 String osName = System.getProperty("os.name");
149 if (osName.startsWith("Mac OS")) {
150 String mrjVersion = System.getProperty("mrj.version");
151 String majorMRJVersion = mrjVersion.substring(0, 3);
155 double version = Double.valueOf(majorMRJVersion).doubleValue();
159 } else if (version >= 2.1 && version < 3) {
161 } else if (version == 3.0) {
163 } else if (version >= 3.1) {
167 } catch (NumberFormatException nfe) {
171 } else if (osName.startsWith("Windows")) {
172 if (osName.indexOf("9") != -1) {
179 public static int getJVM() {
183 * Returns the shared instance.
185 public static PHPeclipsePlugin getDefault() {
190 * Returns the workspace instance.
192 public static IWorkspace getWorkspace() {
193 return ResourcesPlugin.getWorkspace();
196 public static IWorkbenchPage getActivePage() {
197 return getDefault().internalGetActivePage();
200 private IWorkbenchPage internalGetActivePage() {
201 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
202 if (window!=null) return window.getActivePage();
206 public static IWorkbenchWindow getActiveWorkbenchWindow() {
207 return getDefault().getWorkbench().getActiveWorkbenchWindow();
210 public static Shell getActiveWorkbenchShell() {
211 return getActiveWorkbenchWindow().getShell();
214 public static String getPluginId() {
215 return getDefault().getDescriptor().getUniqueIdentifier();
218 public static void log(IStatus status) {
219 getDefault().getLog().log(status);
222 // public static void logErrorMessage(String message) {
223 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
226 // public static void logErrorStatus(String message, IStatus status) {
227 // if (status == null) {
228 // logErrorMessage(message);
231 // MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
232 // multi.add(status);
236 // public static void log(Throwable e) {
237 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
240 public static void log(int severity, String message) {
241 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
244 public static void log(Throwable e) {
245 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
248 public static boolean isDebug() {
249 return getDefault().isDebugging();
252 static IPath getInstallLocation() {
253 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
256 public synchronized JavaTextTools getJavaTextTools() {
257 if (fJavaTextTools == null)
258 fJavaTextTools= new JavaTextTools(getPreferenceStore());
259 return fJavaTextTools;
263 * Returns the string from the plugin's resource bundle,
264 * or 'key' if not found.
266 // public static String getResourceString(String key) {
267 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
269 // return bundle.getString(key);
270 // } catch (MissingResourceException e) {
276 * Returns the plugin's resource bundle,
278 // public ResourceBundle getResourceBundle() {
279 // return resourceBundle;
282 protected void initializeDefaultPreferences(IPreferenceStore store) {
283 // windows preferences:
284 store.setDefault(LOCALHOST_PREF, "http://localhost");
286 store.setDefault(SHOW_EXTERNAL_PREVIEW_PREF, "true");
287 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
288 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
290 String windowsSystem = BootLoader.getWS();
292 if (jvm == WINDOWS_9x) {
294 EXTERNAL_BROWSER_PREF,
295 "command.com /c start iexplore {0}");
296 } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
298 EXTERNAL_BROWSER_PREF,
299 "rundll32 url.dll,FileProtocolHandler {0}");
301 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
305 getWorkspace().getRoot().getLocation().toString());
307 // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
308 if (windowsSystem.equals(BootLoader.WS_WIN32)) {
309 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
310 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
313 "c:\\apache\\mysql\\bin\\mysqld-nt.exe --standalone");
316 "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\"");
317 store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
320 "c:\\apache\\apache.exe -k restart");
322 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
323 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
324 store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
327 "/apache/apache -c \"DocumentRoot \"{0}\"\"");
328 store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
329 store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");
333 store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
334 store.setDefault(PHP_INTERNAL_PARSER, "false");
335 store.setDefault(PHP_EXTERNAL_PARSER, "true");
337 store.setDefault(PHP_PARSE_ON_SAVE, "true");
339 // show line numbers:
340 // store.setDefault(LINE_NUMBER_RULER, "false");
341 // store.setDefault(FORMATTER_TAB_SIZE, "4");
343 // php syntax highlighting
344 store.setDefault(PHP_USERDEF_XMLFILE, ""); //assume there is none chooA
346 PreferenceConverter.setDefault(
348 PHP_MULTILINE_COMMENT,
349 PHPColorProvider.MULTI_LINE_COMMENT);
350 PreferenceConverter.setDefault(
352 PHP_SINGLELINE_COMMENT,
353 PHPColorProvider.SINGLE_LINE_COMMENT);
354 PreferenceConverter.setDefault(
357 PHPColorProvider.KEYWORD);
358 PreferenceConverter.setDefault(
361 PHPColorProvider.VARIABLE);
362 PreferenceConverter.setDefault(
365 PHPColorProvider.FUNCTION_NAME);
366 PreferenceConverter.setDefault(
369 PHPColorProvider.CONSTANT);
370 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
371 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
372 PreferenceConverter.setDefault(
375 PHPColorProvider.DEFAULT);
376 // PreferenceConverter.setDefault(
378 // PHP_EDITOR_BACKGROUND,
379 // PHPColorProvider.BACKGROUND);
380 // PreferenceConverter.setDefault(
382 // LINKED_POSITION_COLOR,
383 // PHPColorProvider.LINKED_POSITION_COLOR);
384 // PreferenceConverter.setDefault(
386 // LINE_NUMBER_COLOR,
387 // PHPColorProvider.LINE_NUMBER_COLOR);
389 // // set default PHPDoc colors:
390 // PreferenceConverter.setDefault(
393 // PHPColorProvider.PHPDOC_KEYWORD);
394 // PreferenceConverter.setDefault(
397 // PHPColorProvider.PHPDOC_LINK);
398 // PreferenceConverter.setDefault(
401 // PHPColorProvider.PHPDOC_DEFAULT);
402 // PreferenceConverter.setDefault(
405 // PHPColorProvider.PHPDOC_TAG);
407 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
408 // PreferenceConverter.setDefault(
410 // PREFERENCE_COLOR_BACKGROUND,
411 // PHPColorProvider.BACKGROUND_COLOR);
414 store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
415 store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
416 store.setDefault(RESOURCE_BUNDLE_DE, "false");
417 store.setDefault(RESOURCE_BUNDLE_FR, "false");
418 store.setDefault(RESOURCE_BUNDLE_ES, "false");
420 store.setDefault(PHP_OUTLINE_CLASS, "true"); //$NON-NLS-1$
421 store.setDefault(PHP_OUTLINE_FUNC, "true"); //$NON-NLS-1$
422 store.setDefault(PHP_OUTLINE_VAR, "true"); //$NON-NLS-1$
424 TemplatePreferencePage.initDefaults(store);
425 //this will initialize the static fields in the syntaxrdr class
428 PHPCore.initializeDefaultPluginPreferences();
429 PreferenceConstants.initializeDefaultValues(store);
432 public void startup() throws CoreException {
434 IAdapterManager manager = Platform.getAdapterManager();
435 manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
436 manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
439 public void setTextEditor(ITextEditor textEditor) {
440 this.fTextEditor = textEditor;
443 public ITextEditor getTextEditor() {