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 java.util.MissingResourceException;
15 import java.util.ResourceBundle;
17 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
18 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
19 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
20 import net.sourceforge.phpeclipse.resourcesview.PHPElement;
21 import net.sourceforge.phpeclipse.resourcesview.PHPElementAdapterFactory;
22 import net.sourceforge.phpeclipse.resourcesview.ResourceAdapterFactory;
23 import org.eclipse.core.resources.IResource;
24 import org.eclipse.core.resources.IWorkspace;
25 import org.eclipse.core.resources.ResourcesPlugin;
26 import org.eclipse.core.runtime.CoreException;
27 import org.eclipse.core.runtime.IAdapterManager;
28 import org.eclipse.core.runtime.IPath;
29 import org.eclipse.core.runtime.IPluginDescriptor;
30 import org.eclipse.core.runtime.IStatus;
31 import org.eclipse.core.runtime.Path;
32 import org.eclipse.core.runtime.Platform;
33 import org.eclipse.core.runtime.Status;
34 import org.eclipse.jface.preference.IPreferenceStore;
35 import org.eclipse.jface.preference.PreferenceConverter;
36 import org.eclipse.swt.widgets.Shell;
37 import org.eclipse.ui.IWorkbenchPage;
38 import org.eclipse.ui.IWorkbenchWindow;
39 import org.eclipse.ui.plugin.AbstractUIPlugin;
42 * The main plugin class to be used in the desktop.
44 public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceConstants {
45 // public static final String LOCALHOST_PREF = "_localhost";
46 // public static final String DOCUMENTROOT_PREF = "_documentroot";
47 // public static final String USE_EXTERNAL_BROWSER_PREF = "_use_external_browser";
48 // public static final String EXTERNAL_BROWSER_PREF = "_external_browser";
49 // public static final String MYSQL_PREF = "_my_sql";
50 // public static final String APACHE_START_PREF = "_apache_start";
51 // public static final String APACHE_STOP_PREF = "_apache_stop";
52 // public static final String APACHE_RESTART_PREF = "_apache_restart";
53 // public static final String SHOW_OUTPUT_IN_CONSOLE = "_sho_output_in_console";
54 // public static final String EXTERNAL_PARSER_PREF = "_external_parser";
57 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
59 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
60 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
61 public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID + ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
63 //The shared instance.
64 private static PHPeclipsePlugin plugin;
66 private ResourceBundle resourceBundle;
68 private ImageDescriptorRegistry fImageDescriptorRegistry;
69 private PHPDocumentProvider fCompilationUnitDocumentProvider;
71 * The Java virtual machine that we are running on.
73 private static int jvm;
76 private static final int MRJ_2_0 = 0;
78 /** MRJ 2.1 or later */
79 private static final int MRJ_2_1 = 1;
81 /** Java on Mac OS X 10.0 (MRJ 3.0) */
82 private static final int MRJ_3_0 = 3;
85 private static final int MRJ_3_1 = 4;
88 private static final int WINDOWS_NT = 5;
91 private static final int WINDOWS_9x = 6;
93 /** JVM constant for any other platform */
94 private static final int OTHER = -1;
98 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
103 resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
104 } catch (MissingResourceException x) {
105 resourceBundle = null;
109 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
110 return getDefault().internalGetImageDescriptorRegistry();
113 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
114 if (fImageDescriptorRegistry == null)
115 fImageDescriptorRegistry= new ImageDescriptorRegistry();
116 return fImageDescriptorRegistry;
118 // @TODO: refactor this into a better method name !
119 public PHPDocumentProvider getCompilationUnitDocumentProvider() {
120 if (fCompilationUnitDocumentProvider == null)
121 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
122 return fCompilationUnitDocumentProvider;
125 public static void setJVM() {
126 String osName = System.getProperty("os.name");
128 if (osName.startsWith("Mac OS")) {
129 String mrjVersion = System.getProperty("mrj.version");
130 String majorMRJVersion = mrjVersion.substring(0, 3);
134 double version = Double.valueOf(majorMRJVersion).doubleValue();
138 } else if (version >= 2.1 && version < 3) {
140 } else if (version == 3.0) {
142 } else if (version >= 3.1) {
146 } catch (NumberFormatException nfe) {
150 } else if (osName.startsWith("Windows")) {
151 if (osName.indexOf("9") != -1) {
158 public static int getJVM() {
162 * Returns the shared instance.
164 public static PHPeclipsePlugin getDefault() {
169 * Returns the workspace instance.
171 public static IWorkspace getWorkspace() {
172 return ResourcesPlugin.getWorkspace();
175 public static IWorkbenchPage getActivePage() {
176 return getDefault().getActivePage();
179 public static IWorkbenchWindow getActiveWorkbenchWindow() {
180 return getDefault().getWorkbench().getActiveWorkbenchWindow();
183 public static Shell getActiveWorkbenchShell() {
184 return getActiveWorkbenchWindow().getShell();
187 public static String getPluginId() {
188 return getDefault().getDescriptor().getUniqueIdentifier();
191 public static void log(IStatus status) {
192 getDefault().getLog().log(status);
195 // public static void logErrorMessage(String message) {
196 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
199 // public static void logErrorStatus(String message, IStatus status) {
200 // if (status == null) {
201 // logErrorMessage(message);
204 // MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
205 // multi.add(status);
209 // public static void log(Throwable e) {
210 // log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
212 public static void log(int severity, String message) {
213 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null) ;
216 public static void log(Throwable e) {
217 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
219 public static boolean isDebug() {
220 return getDefault().isDebugging();
223 static IPath getInstallLocation() {
224 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
228 * Returns the string from the plugin's resource bundle,
229 * or 'key' if not found.
231 public static String getResourceString(String key) {
232 ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
234 return bundle.getString(key);
235 } catch (MissingResourceException e) {
241 * Returns the plugin's resource bundle,
243 public ResourceBundle getResourceBundle() {
244 return resourceBundle;
247 protected void initializeDefaultPreferences(IPreferenceStore store) {
248 // windows preferences:
249 store.setDefault(LOCALHOST_PREF, "http://localhost");
251 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
252 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
253 if (jvm == WINDOWS_9x) {
254 store.setDefault(EXTERNAL_BROWSER_PREF, "command.com /c start iexplore {0}");
255 } else if (jvm == WINDOWS_NT) {
256 store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
258 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
260 store.setDefault(DOCUMENTROOT_PREF, getWorkspace().getRoot().getLocation().toString() );
261 // store.setDefault(DOCUMENTROOT_PREF, "c:\\eclipse\\workspace"); // WIN_32
262 // store.setDefault(DOCUMENTROOT_PREF, "/eclipse/workspace"); // UNIX
263 if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
264 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
265 store.setDefault(MYSQL_PREF, "c:\\apache\\mysql\\bin\\mysqld.exe --standalone");
266 store.setDefault(APACHE_START_PREF, "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\"");
267 store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
268 store.setDefault(APACHE_RESTART_PREF, "c:\\apache\\apache.exe -k restart");
270 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
271 store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
272 store.setDefault(APACHE_START_PREF, "/apache/apache -c \"DocumentRoot \"{0}\"\"");
273 store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
274 store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");
278 store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
279 store.setDefault(PHP_INTERNAL_PARSER, "false");
280 store.setDefault(PHP_EXTERNAL_PARSER, "true");
282 store.setDefault(PHP_PARSE_ON_SAVE, "true");
284 // show line numbers:
285 store.setDefault(LINE_NUMBER_RULER, "false");
287 // php syntax highlighting
288 PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT, PHPColorProvider.MULTI_LINE_COMMENT);
289 PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT, PHPColorProvider.SINGLE_LINE_COMMENT);
290 PreferenceConverter.setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
291 PreferenceConverter.setDefault(store, PHP_VARIABLE, PHPColorProvider.VARIABLE);
292 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME, PHPColorProvider.FUNCTION_NAME);
293 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
294 PreferenceConverter.setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
295 PreferenceConverter.setDefault(store, LINKED_POSITION_COLOR, PHPColorProvider.LINKED_POSITION_COLOR);
296 PreferenceConverter.setDefault(store, LINE_NUMBER_COLOR, PHPColorProvider.LINE_NUMBER_COLOR);
298 store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
299 PreferenceConverter.setDefault(store, PREFERENCE_COLOR_BACKGROUND, PHPColorProvider.BACKGROUND_COLOR);
302 public void startup() throws CoreException {
304 IAdapterManager manager= Platform.getAdapterManager();
305 manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
306 manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);