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
11 **********************************************************************/
12 package net.sourceforge.phpdt.phphelp;
14 import org.eclipse.core.resources.IWorkspace;
15 import org.eclipse.core.resources.ResourcesPlugin;
16 import org.eclipse.core.runtime.IPluginDescriptor;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Platform;
19 import org.eclipse.core.runtime.Status;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 import org.eclipse.swt.widgets.Display;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.ui.IWorkbenchPage;
24 import org.eclipse.ui.IWorkbenchWindow;
25 import org.eclipse.ui.PlatformUI;
26 import org.eclipse.ui.plugin.AbstractUIPlugin;
27 import org.osgi.framework.BundleContext;
30 * The main plugin class to be used in the desktop.
32 public class PHPHelpPlugin extends AbstractUIPlugin {
33 public static final String PHP_CHM_ENABLED = "_php_chm_enabled";
34 public static final String PHP_CHM_FILE = "_php_chm_file";
35 public static final String PHP_CHM_COMMAND = "_php_chm_command";
38 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse.phphelp"</code>).
40 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.phphelp"; //$NON-NLS-1$
42 //The shared instance.
43 private static PHPHelpPlugin plugin;
47 public PHPHelpPlugin(IPluginDescriptor descriptor) {
53 * Returns the shared instance.
55 public static PHPHelpPlugin getDefault() {
59 * Returns the workspace instance.
61 public static IWorkspace getWorkspace() {
62 return ResourcesPlugin.getWorkspace();
65 public static IWorkbenchPage getActivePage() {
66 return getDefault().internalGetActivePage();
69 private IWorkbenchPage internalGetActivePage() {
70 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
72 return window.getActivePage();
76 public static IWorkbenchWindow getActiveWorkbenchWindow() {
77 return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
80 public static Shell getActiveWorkbenchShell() {
81 return getActiveWorkbenchWindow().getShell();
84 // public static String getPluginId() {
85 // return getDefault().getDescriptor().getUniqueIdentifier();
88 public static void log(IStatus status) {
89 getDefault().getLog().log(status);
92 public static void log(int severity, String message) {
93 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
96 public static void log(Throwable e) {
97 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
100 public static boolean isDebug() {
101 return getDefault().isDebugging();
104 // static IPath getInstallLocation() {
105 // return new Path(getDefault().getDescriptor().getInstallURL().getFile());
108 protected void initializeDefaultPreferences(IPreferenceStore store) {
109 // windows preferences:
110 String windowsSystem = Platform.getWS();
112 if (windowsSystem.equals(Platform.WS_WIN32)) {
113 store.setDefault(PHP_CHM_ENABLED, "false");
114 store.setDefault(PHP_CHM_FILE, "c:\\wampp2\\php\\php_manual_en.chm");
115 store.setDefault(PHP_CHM_COMMAND, "hh.exe \"mk:@MSITStore:{0}::/en/function.{1}.html\"");
117 store.setDefault(PHP_CHM_ENABLED, "false");
118 store.setDefault(PHP_CHM_FILE, "");
119 store.setDefault(PHP_CHM_COMMAND, "");
125 * Returns the standard display to be used. The method first checks, if
126 * the thread calling this method has an associated display. If so, this
127 * display is returned. Otherwise the method returns the default display.
129 public static Display getStandardDisplay() {
130 Display display = Display.getCurrent();
131 if (display == null) {
132 display = Display.getDefault();
137 // public void startup() throws CoreException {
139 // IAdapterManager manager = Platform.getAdapterManager();
140 // manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
141 // manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
142 // // externalTools.startUp();
143 // getStandardDisplay().asyncExec(new Runnable() {
144 // public void run() {
145 // //initialize the variable context manager
146 // VariableContextManager.getDefault();
152 // * @see org.eclipse.core.runtime.Plugin#shutdown()
154 // public void shutdown() throws CoreException {
155 // // externalTools.shutDown();
156 // ColorManager.getDefault().dispose();
160 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
162 public void start(BundleContext context) throws Exception {
163 super.start(context);
164 // IAdapterManager manager = Platform.getAdapterManager();
165 // manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
166 // manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
167 // // externalTools.startUp();
168 // getStandardDisplay().asyncExec(new Runnable() {
169 // public void run() {
170 // //initialize the variable context manager
171 // VariableContextManager.getDefault();
176 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
178 public void stop(BundleContext context) throws Exception {
179 // ColorManager.getDefault().dispose();