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 java.util.ArrayList;
15 import java.util.List;
17 import net.sourceforge.phpdt.httpquery.config.ConfigurationManager;
18 import net.sourceforge.phpdt.httpquery.config.IConfigurationWorkingCopy;
20 import org.eclipse.core.resources.IWorkspace;
21 import org.eclipse.core.resources.ResourcesPlugin;
22 import org.eclipse.core.runtime.IStatus;
23 import org.eclipse.core.runtime.Platform;
24 import org.eclipse.core.runtime.Status;
25 import org.eclipse.jface.preference.IPreferenceStore;
26 import org.eclipse.swt.widgets.Display;
27 import org.eclipse.swt.widgets.Shell;
28 import org.eclipse.ui.IWorkbenchPage;
29 import org.eclipse.ui.IWorkbenchWindow;
30 import org.eclipse.ui.PlatformUI;
31 import org.eclipse.ui.plugin.AbstractUIPlugin;
32 import org.osgi.framework.BundleContext;
35 * The main plugin class to be used in the desktop.
37 public class PHPHelpPlugin extends AbstractUIPlugin {
38 public static final String PHP_CHM_ENABLED = "_php_chm_enabled";
40 public static final String PHP_CHM_FILE = "_php_chm_file";
42 public static final String PHP_CHM_COMMAND = "_php_chm_command";
44 public static final String HTTP_QUERY = "HTTP Query";
46 public final static String PREF_STRING_CONFIGURATIONS = "__configurations";
48 public final static String CONFIG_MEMENTO = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
50 + "<config name=\"PHP Online Manual\" type-id=\"HTTP Query\" url=\"http://www.php.net/manual/en/function.$php.selection.php\"/>"
51 + "<config name=\"Google Search\" type-id=\"HTTP Query\" url=\"http://www.google.com/search?q=$text.selection\"/>"
52 + "<config name=\"Koders.com Search\" type-id=\"HTTP Query\" url=\"http://koders.com/?s=$text.selection\"/>"
53 + "<config name=\"Leo.org Translation\" type-id=\"HTTP Query\" url=\"http://dict.leo.org/?search=$text.selection\"/>"
54 + "</configurations>";
56 public static final ArrayList CONFIGURATION_TYPES = new ArrayList();
59 * The id of the PHP plugin (value
60 * <code>"net.sourceforge.phpeclipse.phphelp"</code>).
62 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.phphelp"; //$NON-NLS-1$
64 // The shared instance.
65 private static PHPHelpPlugin plugin;
67 private static ConfigurationManager manager;
71 public PHPHelpPlugin() {
77 * Returns the shared instance.
79 public static PHPHelpPlugin getDefault() {
84 * Returns the workspace instance.
86 public static IWorkspace getWorkspace() {
87 return ResourcesPlugin.getWorkspace();
90 public static IWorkbenchPage getActivePage() {
91 return getDefault().internalGetActivePage();
94 private IWorkbenchPage internalGetActivePage() {
95 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
97 return window.getActivePage();
101 public static IWorkbenchWindow getActiveWorkbenchWindow() {
102 return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
105 public static Shell getActiveWorkbenchShell() {
106 return getActiveWorkbenchWindow().getShell();
109 public static void log(IStatus status) {
110 getDefault().getLog().log(status);
113 public static void log(int severity, String message) {
114 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
118 public static void log(Throwable e) {
119 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
122 public static boolean isDebug() {
123 return getDefault().isDebugging();
126 protected void initializeDefaultPreferences(IPreferenceStore store) {
127 store.setDefault(PREF_STRING_CONFIGURATIONS, CONFIG_MEMENTO);
128 // windows preferences:
129 String windowsSystem = Platform.getWS();
131 if (windowsSystem.equals(Platform.WS_WIN32)) {
132 store.setDefault(PHP_CHM_ENABLED, "false");
133 store.setDefault(PHP_CHM_FILE, "c:\\wampp2\\php\\php_manual_en.chm");
134 store.setDefault(PHP_CHM_COMMAND, "hh.exe \"mk:@MSITStore:{0}::/en/function.{1}.html\"");
136 store.setDefault(PHP_CHM_ENABLED, "false");
137 store.setDefault(PHP_CHM_FILE, "");
138 store.setDefault(PHP_CHM_COMMAND, "");
144 * Returns the standard display to be used. The method first checks, if the
145 * thread calling this method has an associated display. If so, this display
146 * is returned. Otherwise the method returns the default display.
148 public static Display getStandardDisplay() {
149 Display display = Display.getCurrent();
150 if (display == null) {
151 display = Display.getDefault();
156 // public void startup() throws CoreException {
158 // IAdapterManager manager = Platform.getAdapterManager();
159 // manager.registerAdapters(new PHPElementAdapterFactory(),
160 // PHPElement.class);
161 // manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
162 // // externalTools.startUp();
163 // getStandardDisplay().asyncExec(new Runnable() {
164 // public void run() {
165 // //initialize the variable context manager
166 // VariableContextManager.getDefault();
172 // * @see org.eclipse.core.runtime.Plugin#shutdown()
174 // public void shutdown() throws CoreException {
175 // // externalTools.shutDown();
176 // ColorManager.getDefault().dispose();
179 public void start(BundleContext context) throws Exception {
180 super.start(context);
182 manager = ConfigurationManager.getInstance();
183 // IAdapterManager manager = Platform.getAdapterManager();
184 // manager.registerAdapters(new PHPElementAdapterFactory(),
185 // PHPElement.class);
186 // manager.registerAdapters(new ResourceAdapterFactory(),
188 // // externalTools.startUp();
189 // getStandardDisplay().asyncExec(new Runnable() {
190 // public void run() {
191 // //initialize the variable context manager
192 // VariableContextManager.getDefault();
197 public void stop(BundleContext context) throws Exception {
198 // ColorManager.getDefault().dispose();
203 * Returns the translated String found with the given key.
205 * @return java.lang.String
209 public static String getResource(String key) {
211 return Platform.getResourceString(getDefault().getBundle(), key);
212 } catch (Exception e) {
218 * Return a list of all the existing configurations.
220 * @return java.util.List
222 public static List getConfigurations() {
223 return manager.getConfigurations();
227 * Create a new monitor.
229 * @return working copy
231 public static IConfigurationWorkingCopy createConfiguration() {
232 return manager.createConfiguration();
235 public static ArrayList getTypes() {
236 return CONFIGURATION_TYPES;
239 public static void addType(String type) {
240 CONFIGURATION_TYPES.add(type);