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.phpdt.phphelp;
14 import net.sourceforge.phpdt.externaltools.internal.model.ColorManager;
15 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
16 import net.sourceforge.phpeclipse.resourcesview.PHPElement;
17 import net.sourceforge.phpeclipse.resourcesview.PHPElementAdapterFactory;
18 import net.sourceforge.phpeclipse.resourcesview.ResourceAdapterFactory;
20 import org.eclipse.core.boot.BootLoader;
21 import org.eclipse.core.resources.IResource;
22 import org.eclipse.core.resources.IWorkspace;
23 import org.eclipse.core.resources.ResourcesPlugin;
24 import org.eclipse.core.runtime.CoreException;
25 import org.eclipse.core.runtime.IAdapterManager;
26 import org.eclipse.core.runtime.IPath;
27 import org.eclipse.core.runtime.IPluginDescriptor;
28 import org.eclipse.core.runtime.IStatus;
29 import org.eclipse.core.runtime.Path;
30 import org.eclipse.core.runtime.Platform;
31 import org.eclipse.core.runtime.Status;
32 import org.eclipse.jface.preference.IPreferenceStore;
33 import org.eclipse.swt.widgets.Display;
34 import org.eclipse.swt.widgets.Shell;
35 import org.eclipse.ui.IWorkbenchPage;
36 import org.eclipse.ui.IWorkbenchWindow;
37 import org.eclipse.ui.plugin.AbstractUIPlugin;
40 * The main plugin class to be used in the desktop.
42 public class PHPHelpPlugin extends AbstractUIPlugin {
43 public static final String PHP_CHM_ENABLED = "_php_chm_enabled";
44 public static final String PHP_CHM_FILE = "_php_chm_file";
45 public static final String PHP_CHM_COMMAND = "_php_chm_command";
48 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse.phphelp"</code>).
50 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.phphelp"; //$NON-NLS-1$
52 //The shared instance.
53 private static PHPHelpPlugin plugin;
57 public PHPHelpPlugin(IPluginDescriptor descriptor) {
63 * Returns the shared instance.
65 public static PHPHelpPlugin getDefault() {
69 * Returns the workspace instance.
71 public static IWorkspace getWorkspace() {
72 return ResourcesPlugin.getWorkspace();
75 public static IWorkbenchPage getActivePage() {
76 return getDefault().internalGetActivePage();
79 private IWorkbenchPage internalGetActivePage() {
80 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
82 return window.getActivePage();
86 public static IWorkbenchWindow getActiveWorkbenchWindow() {
87 return getDefault().getWorkbench().getActiveWorkbenchWindow();
90 public static Shell getActiveWorkbenchShell() {
91 return getActiveWorkbenchWindow().getShell();
94 public static String getPluginId() {
95 return getDefault().getDescriptor().getUniqueIdentifier();
98 public static void log(IStatus status) {
99 getDefault().getLog().log(status);
102 public static void log(int severity, String message) {
103 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
106 public static void log(Throwable e) {
107 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
110 public static boolean isDebug() {
111 return getDefault().isDebugging();
114 static IPath getInstallLocation() {
115 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
118 protected void initializeDefaultPreferences(IPreferenceStore store) {
119 // windows preferences:
120 String windowsSystem = BootLoader.getWS();
122 if (windowsSystem.equals(BootLoader.WS_WIN32)) {
123 store.setDefault(PHP_CHM_ENABLED, "false");
124 store.setDefault(PHP_CHM_FILE, "");
125 store.setDefault(PHP_CHM_COMMAND, "hh.exe \"mk:@MSITStore:{0}::/en/function.{1}.html\"");
127 store.setDefault(PHP_CHM_ENABLED, "false");
128 store.setDefault(PHP_CHM_FILE, "");
129 store.setDefault(PHP_CHM_COMMAND, "");
135 * Returns the standard display to be used. The method first checks, if
136 * the thread calling this method has an associated display. If so, this
137 * display is returned. Otherwise the method returns the default display.
139 public static Display getStandardDisplay() {
140 Display display = Display.getCurrent();
141 if (display == null) {
142 display = Display.getDefault();
147 public void startup() throws CoreException {
149 IAdapterManager manager = Platform.getAdapterManager();
150 manager.registerAdapters(new PHPElementAdapterFactory(), PHPElement.class);
151 manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
152 // externalTools.startUp();
153 getStandardDisplay().asyncExec(new Runnable() {
155 //initialize the variable context manager
156 VariableContextManager.getDefault();
162 * @see org.eclipse.core.runtime.Plugin#shutdown()
164 public void shutdown() throws CoreException {
165 // externalTools.shutDown();
166 ColorManager.getDefault().dispose();