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;
109 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
114 // resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
115 // } catch (MissingResourceException x) {
116 // resourceBundle = null;
120 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
121 return getDefault().internalGetImageDescriptorRegistry();
124 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
125 if (fImageDescriptorRegistry == null)
126 fImageDescriptorRegistry = new ImageDescriptorRegistry();
127 return fImageDescriptorRegistry;
129 // @TODO: refactor this into a better method name !
130 public PHPDocumentProvider getCompilationUnitDocumentProvider() {
131 if (fCompilationUnitDocumentProvider == null)
132 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
133 return fCompilationUnitDocumentProvider;
136 private static void setJVM() {
137 String osName = System.getProperty("os.name");
139 if (osName.startsWith("Mac OS")) {
140 String mrjVersion = System.getProperty("mrj.version");
141 String majorMRJVersion = mrjVersion.substring(0, 3);
145 double version = Double.valueOf(majorMRJVersion).doubleValue();
149 } else if (version >= 2.1 && version < 3) {
151 } else if (version == 3.0) {
153 } else if (version >= 3.1) {
157 } catch (NumberFormatException nfe) {
161 } else if (osName.startsWith("Windows")) {
162 if (osName.indexOf("9") != -1) {
169 public static int getJVM() {
173 * Returns the shared instance.
175 public static PHPeclipsePlugin getDefault() {
180 * Returns the workspace instance.
182 public static IWorkspace getWorkspace() {
183 return ResourcesPlugin.getWorkspace();
186 public static IWorkbenchPage getActivePage() {
187 return PHPeclipsePlugin.getActivePage();
190 public static IWorkbenchWindow getActiveWorkbenchWindow() {
191 return getDefault().getWorkbench().getActiveWorkbenchWindow();
194 public static Shell getActiveWorkbenchShell() {
195 return getActiveWorkbenchWindow().getShell();
198 public static String getPluginId() {
199 return getDefault().getDescriptor().getUniqueIdentifier();
202 public static void log(IStatus status) {
203 getDefault().getLog().log(status);
206 // public static void logErrorMessage(String message) {
207 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
210 // public static void logErrorStatus(String message, IStatus status) {
211 // if (status == null) {
212 // logErrorMessage(message);
215 // MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
216 // multi.add(status);
220 // public static void log(Throwable e) {
221 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
224 public static void log(int severity, String message) {
225 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
228 public static void log(Throwable e) {
229 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
231 public static boolean isDebug() {
232 return getDefault().isDebugging();
235 static IPath getInstallLocation() {
236 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
240 * Returns the string from the plugin's resource bundle,
241 * or 'key' if not found.
243 // public static String getResourceString(String key) {
244 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
246 // return bundle.getString(key);
247 // } catch (MissingResourceException e) {
253 * Returns the plugin's resource bundle,
255 // public ResourceBundle getResourceBundle() {
256 // return resourceBundle;
259 protected void initializeDefaultPreferences(IPreferenceStore store) {
260 // windows preferences:
261 store.setDefault(LOCALHOST_PREF, "http://localhost");
263 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
264 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
266 String windowsSystem = BootLoader.getWS();
268 if (jvm == WINDOWS_9x) {
270 EXTERNAL_BROWSER_PREF,
271 "command.com /c start iexplore {0}");
272 } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
274 EXTERNAL_BROWSER_PREF,
275 "rundll32 url.dll,FileProtocolHandler {0}");
277 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
281 getWorkspace().getRoot().getLocation().toString());
282 // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
283 if (windowsSystem.equals(BootLoader.WS_WIN32)) {
284 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
287 "c:\\apache\\mysql\\bin\\mysqld.exe --standalone");
290 "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\"");
291 store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
294 "c:\\apache\\apache.exe -k restart");
296 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
297 store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
300 "/apache/apache -c \"DocumentRoot \"{0}\"\"");
301 store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
302 store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");
306 store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
307 store.setDefault(PHP_INTERNAL_PARSER, "false");
308 store.setDefault(PHP_EXTERNAL_PARSER, "true");
310 store.setDefault(PHP_PARSE_ON_SAVE, "true");
312 // show line numbers:
313 store.setDefault(LINE_NUMBER_RULER, "false");
314 store.setDefault(FORMATTER_TAB_SIZE, "4");
316 // php syntax highlighting
317 store.setDefault(PHP_USERDEF_XMLFILE, ""); //assume there is none chooA
319 PreferenceConverter.setDefault(
321 PHP_MULTILINE_COMMENT,
322 PHPColorProvider.MULTI_LINE_COMMENT);
323 PreferenceConverter.setDefault(
325 PHP_SINGLELINE_COMMENT,
326 PHPColorProvider.SINGLE_LINE_COMMENT);
327 PreferenceConverter.setDefault(
330 PHPColorProvider.KEYWORD);
331 PreferenceConverter.setDefault(
334 PHPColorProvider.VARIABLE);
335 PreferenceConverter.setDefault(
338 PHPColorProvider.FUNCTION_NAME);
339 PreferenceConverter.setDefault(
342 PHPColorProvider.CONSTANT);
343 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
344 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
345 PreferenceConverter.setDefault(
348 PHPColorProvider.DEFAULT);
349 PreferenceConverter.setDefault(
351 PHP_EDITOR_BACKGROUND,
352 PHPColorProvider.BACKGROUND);
353 PreferenceConverter.setDefault(
355 LINKED_POSITION_COLOR,
356 PHPColorProvider.LINKED_POSITION_COLOR);
357 PreferenceConverter.setDefault(
360 PHPColorProvider.LINE_NUMBER_COLOR);
362 store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
363 PreferenceConverter.setDefault(
365 PREFERENCE_COLOR_BACKGROUND,
366 PHPColorProvider.BACKGROUND_COLOR);
369 store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
370 store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
371 store.setDefault(RESOURCE_BUNDLE_DE, "false");
372 store.setDefault(RESOURCE_BUNDLE_FR, "false");
373 store.setDefault(RESOURCE_BUNDLE_ES, "false");
375 store.setDefault(PHP_OUTLINE_CLASS, "true"); //$NON-NLS-1$
376 store.setDefault(PHP_OUTLINE_FUNC, "true"); //$NON-NLS-1$
377 store.setDefault(PHP_OUTLINE_VAR, "true"); //$NON-NLS-1$
379 TemplatePreferencePage.initDefaults(store);
381 //this will initialize the static fields in the syntaxrdr class
384 public void startup() throws CoreException {
386 IAdapterManager manager = Platform.getAdapterManager();
387 manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
388 manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);