Fixed bug #1404228: Crash on <?php // comment ?>
[phpeclipse.git] / net.sourceforge.phpeclipse.phphelp / src / net / sourceforge / phpdt / phphelp / PHPHelpPlugin.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  www.phpeclipse.de
11  **********************************************************************/
12 package net.sourceforge.phpdt.phphelp;
13
14 import org.eclipse.core.resources.IWorkspace;
15 import org.eclipse.core.resources.ResourcesPlugin;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Platform;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.jface.preference.IPreferenceStore;
20 import org.eclipse.swt.widgets.Display;
21 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.ui.IWorkbenchPage;
23 import org.eclipse.ui.IWorkbenchWindow;
24 import org.eclipse.ui.PlatformUI;
25 import org.eclipse.ui.plugin.AbstractUIPlugin;
26 import org.osgi.framework.BundleContext;
27
28 /**
29  * The main plugin class to be used in the desktop.
30  */
31 public class PHPHelpPlugin extends AbstractUIPlugin {
32         public static final String PHP_CHM_ENABLED = "_php_chm_enabled";
33
34         public static final String PHP_CHM_FILE = "_php_chm_file";
35
36         public static final String PHP_CHM_COMMAND = "_php_chm_command";
37
38         /**
39          * The id of the PHP plugin (value
40          * <code>"net.sourceforge.phpeclipse.phphelp"</code>).
41          */
42         public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.phphelp"; //$NON-NLS-1$
43
44         // The shared instance.
45         private static PHPHelpPlugin plugin;
46
47         /**
48          * The constructor.
49          */
50         public PHPHelpPlugin() {
51                 super();
52                 plugin = this;
53         }
54
55         /**
56          * Returns the shared instance.
57          */
58         public static PHPHelpPlugin getDefault() {
59                 return plugin;
60         }
61
62         /**
63          * Returns the workspace instance.
64          */
65         public static IWorkspace getWorkspace() {
66                 return ResourcesPlugin.getWorkspace();
67         }
68
69         public static IWorkbenchPage getActivePage() {
70                 return getDefault().internalGetActivePage();
71         }
72
73         private IWorkbenchPage internalGetActivePage() {
74                 IWorkbenchWindow window = PlatformUI.getWorkbench()
75                                 .getActiveWorkbenchWindow();
76                 if (window != null)
77                         return window.getActivePage();
78                 return null;
79         }
80
81         public static IWorkbenchWindow getActiveWorkbenchWindow() {
82                 return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
83         }
84
85         public static Shell getActiveWorkbenchShell() {
86                 return getActiveWorkbenchWindow().getShell();
87         }
88
89         public static void log(IStatus status) {
90                 getDefault().getLog().log(status);
91         }
92
93         public static void log(int severity, String message) {
94                 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message,
95                                 null);
96                 log(status);
97         }
98
99         public static void log(Throwable e) {
100                 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
101                                 "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
102         }
103
104         public static boolean isDebug() {
105                 return getDefault().isDebugging();
106         }
107
108         protected void initializeDefaultPreferences(IPreferenceStore store) {
109                 // windows preferences:
110                 String windowsSystem = Platform.getWS();
111
112                 if (windowsSystem.equals(Platform.WS_WIN32)) {
113                         store.setDefault(PHP_CHM_ENABLED, "false");
114                         store
115                                         .setDefault(PHP_CHM_FILE,
116                                                         "c:\\wampp2\\php\\php_manual_en.chm");
117                         store.setDefault(PHP_CHM_COMMAND,
118                                         "hh.exe \"mk:@MSITStore:{0}::/en/function.{1}.html\"");
119                 } else {
120                         store.setDefault(PHP_CHM_ENABLED, "false");
121                         store.setDefault(PHP_CHM_FILE, "");
122                         store.setDefault(PHP_CHM_COMMAND, "");
123                 }
124
125         }
126
127         /**
128          * Returns the standard display to be used. The method first checks, if the
129          * thread calling this method has an associated display. If so, this display
130          * is returned. Otherwise the method returns the default display.
131          */
132         public static Display getStandardDisplay() {
133                 Display display = Display.getCurrent();
134                 if (display == null) {
135                         display = Display.getDefault();
136                 }
137                 return display;
138         }
139
140         // public void startup() throws CoreException {
141         // super.startup();
142         // IAdapterManager manager = Platform.getAdapterManager();
143         // manager.registerAdapters(new PHPElementAdapterFactory(),
144         // PHPElement.class);
145         // manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
146         // // externalTools.startUp();
147         // getStandardDisplay().asyncExec(new Runnable() {
148         // public void run() {
149         // //initialize the variable context manager
150         // VariableContextManager.getDefault();
151         // }
152         // });
153         // }
154
155         // /**
156         // * @see org.eclipse.core.runtime.Plugin#shutdown()
157         // */
158         // public void shutdown() throws CoreException {
159         // // externalTools.shutDown();
160         // ColorManager.getDefault().dispose();
161         // }
162
163         /*
164          * (non-Javadoc)
165          *
166          * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
167          */
168         public void start(BundleContext context) throws Exception {
169                 super.start(context);
170                 // IAdapterManager manager = Platform.getAdapterManager();
171                 // manager.registerAdapters(new PHPElementAdapterFactory(),
172                 // PHPElement.class);
173                 // manager.registerAdapters(new ResourceAdapterFactory(),
174                 // IResource.class);
175                 // // externalTools.startUp();
176                 // getStandardDisplay().asyncExec(new Runnable() {
177                 // public void run() {
178                 // //initialize the variable context manager
179                 // VariableContextManager.getDefault();
180                 // }
181                 // });
182         }
183
184         /*
185          * (non-Javadoc)
186          *
187          * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
188          */
189         public void stop(BundleContext context) throws Exception {
190                 // ColorManager.getDefault().dispose();
191                 super.stop(context);
192         }
193 }