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 = "__configurations1";
48 public final static String CONFIG_MEMENTO = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
50 + "<config name=\"PHP Manual\" type-id=\"HTTP Query\" url=\"http://www.php.net/manual/en/function.$php.selection.php\"/>"
51 + "<config name=\"Google.com\" type-id=\"HTTP Query\" url=\"http://www.google.com/search?q=$text.selection\"/>"
52 + "<config name=\"Koders.com\" type-id=\"HTTP Query\" url=\"http://koders.com/?s=$text.selection\"/>"
53 + "<config name=\"Leo.org Deutsch/English\" type-id=\"HTTP Query\" url=\"http://dict.leo.org/?search=$text.selection\"/>"
54 + "<config name=\"Localhost\" type-id=\"HTTP Query\" url=\"http://localhost\"/>"
55 + "</configurations>";
57 public static final ArrayList CONFIGURATION_TYPES = new ArrayList();
60 * The id of the PHP plugin (value
61 * <code>"net.sourceforge.phpeclipse.phphelp"</code>).
63 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.phphelp"; //$NON-NLS-1$
65 // The shared instance.
66 private static PHPHelpPlugin plugin;
68 private static ConfigurationManager manager;
72 public PHPHelpPlugin() {
78 * Returns the shared instance.
80 public static PHPHelpPlugin getDefault() {
85 * Returns the workspace instance.
87 public static IWorkspace getWorkspace() {
88 return ResourcesPlugin.getWorkspace();
91 public static IWorkbenchPage getActivePage() {
92 return getDefault().internalGetActivePage();
95 private IWorkbenchPage internalGetActivePage() {
96 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
98 return window.getActivePage();
102 public static IWorkbenchWindow getActiveWorkbenchWindow() {
103 return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
106 public static Shell getActiveWorkbenchShell() {
107 return getActiveWorkbenchWindow().getShell();
110 public static void log(IStatus status) {
111 getDefault().getLog().log(status);
114 public static void log(int severity, String message) {
115 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
119 public static void log(Throwable e) {
120 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
123 public static boolean isDebug() {
124 return getDefault().isDebugging();
127 protected void initializeDefaultPreferences(IPreferenceStore store) {
128 store.setDefault(PREF_STRING_CONFIGURATIONS, CONFIG_MEMENTO);
130 // windows preferences:
131 String windowsSystem = Platform.getWS();
133 if (windowsSystem.equals(Platform.WS_WIN32)) {
134 store.setDefault(PHP_CHM_ENABLED, "false");
135 store.setDefault(PHP_CHM_FILE, "c:\\wampp2\\php\\php_manual_en.chm");
136 store.setDefault(PHP_CHM_COMMAND, "hh.exe \"mk:@MSITStore:{0}::/en/function.{1}.html\"");
138 store.setDefault(PHP_CHM_ENABLED, "false");
139 store.setDefault(PHP_CHM_FILE, "");
140 store.setDefault(PHP_CHM_COMMAND, "");
146 * Returns the standard display to be used. The method first checks, if the
147 * thread calling this method has an associated display. If so, this display
148 * is returned. Otherwise the method returns the default display.
150 public static Display getStandardDisplay() {
151 Display display = Display.getCurrent();
152 if (display == null) {
153 display = Display.getDefault();
158 // public void startup() throws CoreException {
160 // IAdapterManager manager = Platform.getAdapterManager();
161 // manager.registerAdapters(new PHPElementAdapterFactory(),
162 // PHPElement.class);
163 // manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
164 // // externalTools.startUp();
165 // getStandardDisplay().asyncExec(new Runnable() {
166 // public void run() {
167 // //initialize the variable context manager
168 // VariableContextManager.getDefault();
174 // * @see org.eclipse.core.runtime.Plugin#shutdown()
176 // public void shutdown() throws CoreException {
177 // // externalTools.shutDown();
178 // ColorManager.getDefault().dispose();
181 public void start(BundleContext context) throws Exception {
182 super.start(context);
184 manager = ConfigurationManager.getInstance();
185 // IAdapterManager manager = Platform.getAdapterManager();
186 // manager.registerAdapters(new PHPElementAdapterFactory(),
187 // PHPElement.class);
188 // manager.registerAdapters(new ResourceAdapterFactory(),
190 // // externalTools.startUp();
191 // getStandardDisplay().asyncExec(new Runnable() {
192 // public void run() {
193 // //initialize the variable context manager
194 // VariableContextManager.getDefault();
199 public void stop(BundleContext context) throws Exception {
200 // ColorManager.getDefault().dispose();
205 * Returns the translated String found with the given key.
207 * @return java.lang.String
211 public static String getResource(String key) {
213 return Platform.getResourceString(getDefault().getBundle(), key);
214 } catch (Exception e) {
220 * Return a list of all the existing configurations.
222 * @return java.util.List
224 public static List getConfigurations() {
225 return manager.getConfigurations();
229 * Create a new monitor.
231 * @return working copy
233 public static IConfigurationWorkingCopy createConfiguration() {
234 return manager.createConfiguration();
237 public static ArrayList getTypes() {
238 return CONFIGURATION_TYPES;
241 public static void addType(String type) {
242 CONFIGURATION_TYPES.add(type);