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.update.internal.ui.UpdateUIPlugin;
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;
85 private JavaTextTools fJavaTextTools;
88 * The Java virtual machine that we are running on.
90 private static int jvm;
93 private static final int MRJ_2_0 = 0;
95 /** MRJ 2.1 or later */
96 private static final int MRJ_2_1 = 1;
98 /** Java on Mac OS X 10.0 (MRJ 3.0) */
99 private static final int MRJ_3_0 = 3;
102 private static final int MRJ_3_1 = 4;
105 private static final int WINDOWS_NT = 5;
108 private static final int WINDOWS_9x = 6;
110 /** JVM constant for any other platform */
111 private static final int OTHER = -1;
113 /** General debug flag*/
114 public static final boolean DEBUG = false;
118 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
123 // resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
124 // } catch (MissingResourceException x) {
125 // resourceBundle = null;
129 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
130 return getDefault().internalGetImageDescriptorRegistry();
133 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
134 if (fImageDescriptorRegistry == null)
135 fImageDescriptorRegistry = new ImageDescriptorRegistry();
136 return fImageDescriptorRegistry;
138 // @TODO: refactor this into a better method name !
139 public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
140 if (fCompilationUnitDocumentProvider == null)
141 fCompilationUnitDocumentProvider= new PHPDocumentProvider();
142 return fCompilationUnitDocumentProvider;
145 private static void setJVM() {
146 String osName = System.getProperty("os.name");
148 if (osName.startsWith("Mac OS")) {
149 String mrjVersion = System.getProperty("mrj.version");
150 String majorMRJVersion = mrjVersion.substring(0, 3);
154 double version = Double.valueOf(majorMRJVersion).doubleValue();
158 } else if (version >= 2.1 && version < 3) {
160 } else if (version == 3.0) {
162 } else if (version >= 3.1) {
166 } catch (NumberFormatException nfe) {
170 } else if (osName.startsWith("Windows")) {
171 if (osName.indexOf("9") != -1) {
178 public static int getJVM() {
182 * Returns the shared instance.
184 public static PHPeclipsePlugin getDefault() {
189 * Returns the workspace instance.
191 public static IWorkspace getWorkspace() {
192 return ResourcesPlugin.getWorkspace();
195 public static IWorkbenchPage getActivePage() {
196 return getDefault().internalGetActivePage();
199 private IWorkbenchPage internalGetActivePage() {
200 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
201 if (window!=null) return window.getActivePage();
205 public static IWorkbenchWindow getActiveWorkbenchWindow() {
206 return getDefault().getWorkbench().getActiveWorkbenchWindow();
209 public static Shell getActiveWorkbenchShell() {
210 return getActiveWorkbenchWindow().getShell();
213 public static String getPluginId() {
214 return getDefault().getDescriptor().getUniqueIdentifier();
217 public static void log(IStatus status) {
218 getDefault().getLog().log(status);
221 // public static void logErrorMessage(String message) {
222 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
225 // public static void logErrorStatus(String message, IStatus status) {
226 // if (status == null) {
227 // logErrorMessage(message);
230 // MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
231 // multi.add(status);
235 // public static void log(Throwable e) {
236 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
239 public static void log(int severity, String message) {
240 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
243 public static void log(Throwable e) {
244 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
247 public static boolean isDebug() {
248 return getDefault().isDebugging();
251 static IPath getInstallLocation() {
252 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
255 public synchronized JavaTextTools getJavaTextTools() {
256 if (fJavaTextTools == null)
257 fJavaTextTools= new JavaTextTools(getPreferenceStore());
258 return fJavaTextTools;
262 * Returns the string from the plugin's resource bundle,
263 * or 'key' if not found.
265 // public static String getResourceString(String key) {
266 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
268 // return bundle.getString(key);
269 // } catch (MissingResourceException e) {
275 * Returns the plugin's resource bundle,
277 // public ResourceBundle getResourceBundle() {
278 // return resourceBundle;
281 protected void initializeDefaultPreferences(IPreferenceStore store) {
282 // windows preferences:
283 store.setDefault(LOCALHOST_PREF, "http://localhost");
285 store.setDefault(SHOW_EXTERNAL_PREVIEW_PREF, "true");
286 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
287 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
289 String windowsSystem = BootLoader.getWS();
291 if (jvm == WINDOWS_9x) {
293 EXTERNAL_BROWSER_PREF,
294 "command.com /c start iexplore {0}");
295 } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
297 EXTERNAL_BROWSER_PREF,
298 "rundll32 url.dll,FileProtocolHandler {0}");
300 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
304 getWorkspace().getRoot().getLocation().toString());
305 // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
306 if (windowsSystem.equals(BootLoader.WS_WIN32)) {
307 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
310 "c:\\apache\\mysql\\bin\\mysqld-nt.exe --standalone");
313 "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\"");
314 store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
317 "c:\\apache\\apache.exe -k restart");
319 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
320 store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
323 "/apache/apache -c \"DocumentRoot \"{0}\"\"");
324 store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
325 store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");
329 store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
330 store.setDefault(PHP_INTERNAL_PARSER, "false");
331 store.setDefault(PHP_EXTERNAL_PARSER, "true");
333 store.setDefault(PHP_PARSE_ON_SAVE, "true");
335 // show line numbers:
336 // store.setDefault(LINE_NUMBER_RULER, "false");
337 // store.setDefault(FORMATTER_TAB_SIZE, "4");
339 // php syntax highlighting
340 store.setDefault(PHP_USERDEF_XMLFILE, ""); //assume there is none chooA
342 PreferenceConverter.setDefault(
344 PHP_MULTILINE_COMMENT,
345 PHPColorProvider.MULTI_LINE_COMMENT);
346 PreferenceConverter.setDefault(
348 PHP_SINGLELINE_COMMENT,
349 PHPColorProvider.SINGLE_LINE_COMMENT);
350 PreferenceConverter.setDefault(
353 PHPColorProvider.KEYWORD);
354 PreferenceConverter.setDefault(
357 PHPColorProvider.VARIABLE);
358 PreferenceConverter.setDefault(
361 PHPColorProvider.FUNCTION_NAME);
362 PreferenceConverter.setDefault(
365 PHPColorProvider.CONSTANT);
366 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
367 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
368 PreferenceConverter.setDefault(
371 PHPColorProvider.DEFAULT);
372 // PreferenceConverter.setDefault(
374 // PHP_EDITOR_BACKGROUND,
375 // PHPColorProvider.BACKGROUND);
376 // PreferenceConverter.setDefault(
378 // LINKED_POSITION_COLOR,
379 // PHPColorProvider.LINKED_POSITION_COLOR);
380 // PreferenceConverter.setDefault(
382 // LINE_NUMBER_COLOR,
383 // PHPColorProvider.LINE_NUMBER_COLOR);
385 // // set default PHPDoc colors:
386 // PreferenceConverter.setDefault(
389 // PHPColorProvider.PHPDOC_KEYWORD);
390 // PreferenceConverter.setDefault(
393 // PHPColorProvider.PHPDOC_LINK);
394 // PreferenceConverter.setDefault(
397 // PHPColorProvider.PHPDOC_DEFAULT);
398 // PreferenceConverter.setDefault(
401 // PHPColorProvider.PHPDOC_TAG);
403 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
404 // PreferenceConverter.setDefault(
406 // PREFERENCE_COLOR_BACKGROUND,
407 // PHPColorProvider.BACKGROUND_COLOR);
410 store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
411 store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
412 store.setDefault(RESOURCE_BUNDLE_DE, "false");
413 store.setDefault(RESOURCE_BUNDLE_FR, "false");
414 store.setDefault(RESOURCE_BUNDLE_ES, "false");
416 store.setDefault(PHP_OUTLINE_CLASS, "true"); //$NON-NLS-1$
417 store.setDefault(PHP_OUTLINE_FUNC, "true"); //$NON-NLS-1$
418 store.setDefault(PHP_OUTLINE_VAR, "true"); //$NON-NLS-1$
420 TemplatePreferencePage.initDefaults(store);
421 //this will initialize the static fields in the syntaxrdr class
424 PHPCore.initializeDefaultPluginPreferences();
425 PreferenceConstants.initializeDefaultValues(store);
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);