911ccebbbc55a7157b10a340517aa8eded6b3435
[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                                         jvm = MRJ_3_1;
97                                 }
98
99                         } catch (NumberFormatException nfe) {
100
101                         }
102
103                 } else if (osName.startsWith("Windows")) {
104                         if (osName.indexOf("9") != -1) {
105                                 jvm = WINDOWS_9x;
106                         } else {
107                                 jvm = WINDOWS_NT;
108                         }
109                 }
110         }
111         public static int getJVM() {
112                 return jvm;
113         }
114         /**
115          * Returns the shared instance.
116          */
117         public static PHPeclipsePlugin getDefault() {
118                 return plugin;
119         }
120
121         /**
122          * Returns the workspace instance.
123          */
124         public static IWorkspace getWorkspace() {
125                 return ResourcesPlugin.getWorkspace();
126         }
127
128         /**
129          * Returns the string from the plugin's resource bundle,
130          * or 'key' if not found.
131          */
132         public static String getResourceString(String key) {
133                 ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
134                 try {
135                         return bundle.getString(key);
136                 } catch (MissingResourceException e) {
137                         return key;
138                 }
139         }
140
141         /**
142          * Returns the plugin's resource bundle,
143          */
144         public ResourceBundle getResourceBundle() {
145                 return resourceBundle;
146         }
147
148         protected void initializeDefaultPreferences(IPreferenceStore store) {
149                 // windows preferences:
150                 store.setDefault(LOCALHOST_PREF, "http://localhost");
151                 
152                 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
153                 if (jvm == WINDOWS_9x) {
154                         store.setDefault(EXTERNAL_BROWSER_PREF, "command.com /c start iexplore {0}");
155                 } else if (jvm == WINDOWS_NT) {
156                         store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
157                 } else {
158                         store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
159                 }
160                 if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
161       store.setDefault(DOCUMENTROOT_PREF, "c:\\eclipse\\workspace");
162                         store.setDefault(MYSQL_PREF, "c:\\apache\\mysql\\bin\\mysqld.exe --standalone");
163                         store.setDefault(APACHE_START_PREF, "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\"");
164                         store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown");
165                         store.setDefault(APACHE_RESTART_PREF, "c:\\apache\\apache.exe -k restart");
166                 } else {
167       store.setDefault(DOCUMENTROOT_PREF, "/eclipse/workspace");
168                         store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone");
169                         store.setDefault(APACHE_START_PREF, "/apache/apache -c \"DocumentRoot \"{0}\"\"");
170                         store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown");
171                         store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart");
172                 }
173         }
174 }