6dea6cff63a91ced6115ecbbeec082ba77617407
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / PHPeclipsePlugin.java
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
7
8 Contributors:
9     IBM Corporation - Initial implementation
10     Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse;
13
14 import java.util.MissingResourceException;
15 import java.util.ResourceBundle;
16
17 import org.eclipse.core.resources.IWorkspace;
18 import org.eclipse.core.resources.ResourcesPlugin;
19 import org.eclipse.core.runtime.IPluginDescriptor;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 import org.eclipse.ui.plugin.AbstractUIPlugin;
22
23 /**
24  * The main plugin class to be used in the desktop.
25  */
26 public class PHPeclipsePlugin extends AbstractUIPlugin {
27         public static final String LOCALHOST_PREF = "_localhost";
28         public static final String DOCUMENTROOT_PREF = "_documentroot";
29         public static final String USE_EXTERNAL_BROWSER_PREF = "_use_external_browser";
30         public static final String EXTERNAL_BROWSER_PREF = "_external_browser";
31         public static final String MYSQL_PREF = "_my_sql";
32         public static final String APACHE_START_PREF = "_apache_start";
33         public static final String APACHE_STOP_PREF = "_apache_stop";
34         public static final String APACHE_RESTART_PREF = "_apache_restart";
35         //The shared instance.
36         private static PHPeclipsePlugin plugin;
37         //Resource bundle.
38         private ResourceBundle resourceBundle;
39         /**
40         * The Java virtual machine that we are running on.  
41         */
42         private static int jvm;
43
44         /** MRJ 2.0 */
45         private static final int MRJ_2_0 = 0;
46
47         /** MRJ 2.1 or later */
48         private static final int MRJ_2_1 = 1;
49
50         /** Java on Mac OS X 10.0 (MRJ 3.0) */
51         private static final int MRJ_3_0 = 3;
52
53         /** MRJ 3.1 */
54         private static final int MRJ_3_1 = 4;
55
56         /** Windows NT  */
57         private static final int WINDOWS_NT = 5;
58
59         /** Windows 9x  */
60         private static final int WINDOWS_9x = 6;
61
62         /** JVM constant for any other platform */
63         private static final int OTHER = -1;
64         /**
65          * The constructor.
66          */
67         public PHPeclipsePlugin(IPluginDescriptor descriptor) {
68                 super(descriptor);
69                 plugin = this;
70                 setJVM();
71                 try {
72                         resourceBundle = ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
73                 } catch (MissingResourceException x) {
74                         resourceBundle = null;
75                 }
76         }
77
78         public static void setJVM() {
79                 String osName = System.getProperty("os.name");
80
81                 if (osName.startsWith("Mac OS")) {
82                         String mrjVersion = System.getProperty("mrj.version");
83                         String majorMRJVersion = mrjVersion.substring(0, 3);
84                         jvm = OTHER;
85                         try {
86
87                                 double version = Double.valueOf(majorMRJVersion).doubleValue();
88
89                                 if (version == 2) {
90                                         jvm = MRJ_2_0;
91                                 } else if (version >= 2.1 && version < 3) {
92                                         jvm = MRJ_2_1;
93                                 } else if (version == 3.0) {
94                                         jvm = MRJ_3_0;
95                                 } else if (version >= 3.1) {
96                                         // Assume that all 3.1 and later versions of MRJ work the same.
97                                         jvm = MRJ_3_1;
98                                 }
99
100                         } catch (NumberFormatException nfe) {
101
102                         }
103
104                 } else if (osName.startsWith("Windows")) {
105                         if (osName.indexOf("9") != -1) {
106                                 jvm = WINDOWS_9x;
107                         } else {
108                                 jvm = WINDOWS_NT;
109                         }
110                 }
111         }
112         public static int getJVM() {
113                 return jvm;
114         }
115         /**
116          * Returns the shared instance.
117          */
118         public static PHPeclipsePlugin getDefault() {
119                 return plugin;
120         }
121
122         /**
123          * Returns the workspace instance.
124          */
125         public static IWorkspace getWorkspace() {
126                 return ResourcesPlugin.getWorkspace();
127         }
128
129         /**
130          * Returns the string from the plugin's resource bundle,
131          * or 'key' if not found.
132          */
133         public static String getResourceString(String key) {
134                 ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
135                 try {
136                         return bundle.getString(key);
137                 } catch (MissingResourceException e) {
138                         return key;
139                 }
140         }
141
142         /**
143          * Returns the plugin's resource bundle,
144          */
145         public ResourceBundle getResourceBundle() {
146                 return resourceBundle;
147         }
148
149         protected void initializeDefaultPreferences(IPreferenceStore store) {
150                 // windows preferences:
151                 store.setDefault(LOCALHOST_PREF, "http://localhost");
152                 
153                 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
154                 if (jvm == WINDOWS_9x) {
155                         store.setDefault(EXTERNAL_BROWSER_PREF, "command.com /c start iexplore {0}");
156                 } else if (jvm == WINDOWS_NT) {
157                         store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
158                 } else {
159                         store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
160                 }
161                 if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
162       store.setDefault(DOCUMENTROOT_PREF, "c:\\eclipse\\workspace");
163                         store.setDefault(MYSQL_PREF, "c:\\apache\\mysql\\bin\\mysqld.exe --standalone");
164                         store.setDefault(APACHE_START_PREF, "c:\\apache\\apache.exe \"DocumentRoot \"{0}\"\"");
165                         store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
166                         store.setDefault(APACHE_RESTART_PREF, "c:\\apache\\apache.exe -k restart");
167                 } else {
168       store.setDefault(DOCUMENTROOT_PREF, "/eclipse/workspace");
169                         store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
170                         store.setDefault(APACHE_START_PREF, "/apache/apache \"DocumentRoot \"{0}\"\"");
171                         store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
172                         store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");
173                 }
174         }
175 }