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 extends AbstractUIPlugin implements IPreferenceConstants {
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";
61 * id of builder - matches plugin.xml (concatenate pluginid.builderid)
63 public static final String BUILDER_INDEX_ID = PLUGIN_ID + ".indexbuilder";
64 public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
66 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID + ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
67 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID + ".ui.CodingActionSet"; //$NON-NLS-1$
69 public static final String PHPPARSER_NEW = "test.PHPParser";
70 public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
72 /** Change this if you want to switch PHP Parser. */
73 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
75 //The shared instance.
76 private static PHPeclipsePlugin plugin;
78 private static ExternalToolsPlugin externalTools;
80 //private ResourceBundle resourceBundle;
82 private ImageDescriptorRegistry fImageDescriptorRegistry;
83 private PHPDocumentProvider fCompilationUnitDocumentProvider;
84 private IFile fLastEditorFile = 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) {
123 externalTools = new ExternalToolsPlugin();
125 // resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
126 // } catch (MissingResourceException x) {
127 // resourceBundle = null;
131 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
132 return getDefault().internalGetImageDescriptorRegistry();
135 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
136 if (fImageDescriptorRegistry == null)
137 fImageDescriptorRegistry = new ImageDescriptorRegistry();
138 return fImageDescriptorRegistry;
140 // @TODO: refactor this into a better method name !
141 public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
142 if (fCompilationUnitDocumentProvider == null)
143 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
144 return fCompilationUnitDocumentProvider;
147 private static void setJVM() {
148 String osName = System.getProperty("os.name");
150 if (osName.startsWith("Mac OS")) {
151 String mrjVersion = System.getProperty("mrj.version");
152 String majorMRJVersion = mrjVersion.substring(0, 3);
156 double version = Double.valueOf(majorMRJVersion).doubleValue();
160 } else if (version >= 2.1 && version < 3) {
162 } else if (version == 3.0) {
164 } else if (version >= 3.1) {
168 } catch (NumberFormatException nfe) {
172 } else if (osName.startsWith("Windows")) {
173 if (osName.indexOf("9") != -1) {
180 public static int getJVM() {
184 * Returns the shared instance.
186 public static PHPeclipsePlugin getDefault() {
190 // public static ExternalToolsPlugin getExternalTools() {
191 // return externalTools;
194 * Returns the workspace instance.
196 public static IWorkspace getWorkspace() {
197 return ResourcesPlugin.getWorkspace();
200 public static IWorkbenchPage getActivePage() {
201 return getDefault().internalGetActivePage();
204 private IWorkbenchPage internalGetActivePage() {
205 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
207 return window.getActivePage();
211 public static IWorkbenchWindow getActiveWorkbenchWindow() {
212 return getDefault().getWorkbench().getActiveWorkbenchWindow();
215 public static Shell getActiveWorkbenchShell() {
216 return getActiveWorkbenchWindow().getShell();
219 public static String getPluginId() {
220 return getDefault().getDescriptor().getUniqueIdentifier();
223 public static void log(IStatus status) {
224 getDefault().getLog().log(status);
227 // public static void logErrorMessage(String message) {
228 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
231 // public static void logErrorStatus(String message, IStatus status) {
232 // if (status == null) {
233 // logErrorMessage(message);
236 // MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
237 // multi.add(status);
241 // public static void log(Throwable e) {
242 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
245 public static void log(int severity, String message) {
246 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
249 public static void log(Throwable e) {
250 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
253 public static boolean isDebug() {
254 return getDefault().isDebugging();
257 static IPath getInstallLocation() {
258 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
261 public synchronized JavaTextTools getJavaTextTools() {
262 if (fJavaTextTools == null)
263 fJavaTextTools = new JavaTextTools(getPreferenceStore());
264 return fJavaTextTools;
268 * Returns the string from the plugin's resource bundle,
269 * or 'key' if not found.
271 // public static String getResourceString(String key) {
272 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
274 // return bundle.getString(key);
275 // } catch (MissingResourceException e) {
281 * Returns the plugin's resource bundle,
283 // public ResourceBundle getResourceBundle() {
284 // return resourceBundle;
287 protected void initializeDefaultPreferences(IPreferenceStore store) {
288 // windows preferences:
289 store.setDefault(LOCALHOST_PREF, "http://localhost");
291 store.setDefault(SHOW_EXTERNAL_PREVIEW_PREF, "true");
292 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
293 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
295 String windowsSystem = BootLoader.getWS();
297 if (jvm == WINDOWS_9x) {
298 store.setDefault(EXTERNAL_BROWSER_PREF, "command.com /c start iexplore {0}");
299 } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
300 store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
301 } else if (windowsSystem.equals(BootLoader.WS_CARBON)) {
302 // TODO How do we start Safari on Mac OS X ?
303 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
305 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
307 store.setDefault(DOCUMENTROOT_PREF, getWorkspace().getRoot().getLocation().toString());
309 // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
311 if (windowsSystem.equals(BootLoader.WS_WIN32)) {
312 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
313 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
314 store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
315 store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
318 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
319 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
320 store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
321 store.setDefault(APACHE_RUN_PREF, "/apache/apache");
324 store.setDefault(MYSQL_PREF, "--standalone");
325 store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
326 store.setDefault(APACHE_STOP_PREF, "-k shutdown");
327 store.setDefault(APACHE_RESTART_PREF, "-k restart");
329 store.setDefault(MYSQL_START_BACKGROUND, "true");
330 store.setDefault(APACHE_START_BACKGROUND, "true");
331 store.setDefault(APACHE_STOP_BACKGROUND, "true");
332 store.setDefault(APACHE_RESTART_BACKGROUND, "true");
334 store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
335 store.setDefault(PHP_INTERNAL_PARSER, "false");
336 store.setDefault(PHP_EXTERNAL_PARSER, "true");
338 // store.setDefault(PHP_PARSE_ON_SAVE, "true");
340 // show line numbers:
341 // store.setDefault(LINE_NUMBER_RULER, "false");
342 // store.setDefault(FORMATTER_TAB_SIZE, "4");
344 // php syntax highlighting
345 store.setDefault(PHP_USERDEF_XMLFILE, "");
346 //assume there is none chooA
348 PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT, PHPColorProvider.MULTI_LINE_COMMENT);
349 PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT, PHPColorProvider.SINGLE_LINE_COMMENT);
350 PreferenceConverter.setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
351 PreferenceConverter.setDefault(store, PHP_VARIABLE, PHPColorProvider.VARIABLE);
352 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME, PHPColorProvider.FUNCTION_NAME);
353 PreferenceConverter.setDefault(store, PHP_CONSTANT, PHPColorProvider.CONSTANT);
354 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
355 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
356 PreferenceConverter.setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
357 // PreferenceConverter.setDefault(
359 // PHP_EDITOR_BACKGROUND,
360 // PHPColorProvider.BACKGROUND);
361 // PreferenceConverter.setDefault(
363 // LINKED_POSITION_COLOR,
364 // PHPColorProvider.LINKED_POSITION_COLOR);
365 // PreferenceConverter.setDefault(
367 // LINE_NUMBER_COLOR,
368 // PHPColorProvider.LINE_NUMBER_COLOR);
370 // // set default PHPDoc colors:
371 // PreferenceConverter.setDefault(
374 // PHPColorProvider.PHPDOC_KEYWORD);
375 // PreferenceConverter.setDefault(
378 // PHPColorProvider.PHPDOC_LINK);
379 // PreferenceConverter.setDefault(
382 // PHPColorProvider.PHPDOC_DEFAULT);
383 // PreferenceConverter.setDefault(
386 // PHPColorProvider.PHPDOC_TAG);
388 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
389 // PreferenceConverter.setDefault(
391 // PREFERENCE_COLOR_BACKGROUND,
392 // PHPColorProvider.BACKGROUND_COLOR);
395 store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
396 store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
397 store.setDefault(RESOURCE_BUNDLE_DE, "false");
398 store.setDefault(RESOURCE_BUNDLE_FR, "false");
399 store.setDefault(RESOURCE_BUNDLE_ES, "false");
401 store.setDefault(PHP_OUTLINE_CLASS, "true"); //$NON-NLS-1$
402 store.setDefault(PHP_OUTLINE_FUNC, "true"); //$NON-NLS-1$
403 store.setDefault(PHP_OUTLINE_VAR, "true"); //$NON-NLS-1$
405 TemplatePreferencePage.initDefaults(store);
406 //this will initialize the static fields in the syntaxrdr class
409 PHPCore.initializeDefaultPluginPreferences();
410 PreferenceConstants.initializeDefaultValues(store);
412 externalTools.initializeDefaultPreferences(store);
416 * Returns the standard display to be used. The method first checks, if
417 * the thread calling this method has an associated display. If so, this
418 * display is returned. Otherwise the method returns the default display.
420 public static Display getStandardDisplay() {
421 Display display = Display.getCurrent();
422 if (display == null) {
423 display = Display.getDefault();
428 public void startup() throws CoreException {
430 IAdapterManager manager = Platform.getAdapterManager();
431 manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
432 manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
433 // externalTools.startUp();
434 getStandardDisplay().asyncExec(new Runnable() {
436 //initialize the variable context manager
437 VariableContextManager.getDefault();
443 * @see org.eclipse.core.runtime.Plugin#shutdown()
445 public void shutdown() throws CoreException {
446 // externalTools.shutDown();
447 ColorManager.getDefault().dispose();
450 public void setLastEditorFile(IFile textEditor) {
451 this.fLastEditorFile = textEditor;
454 public IFile getLastEditorFile() {
455 return fLastEditorFile;