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;
73 public PHPHelpPlugin() {
79 * Returns the shared instance.
81 public static PHPHelpPlugin getDefault() {
86 * Returns the workspace instance.
88 public static IWorkspace getWorkspace() {
89 return ResourcesPlugin.getWorkspace();
92 public static IWorkbenchPage getActivePage() {
93 return getDefault().internalGetActivePage();
96 private IWorkbenchPage internalGetActivePage() {
97 IWorkbenchWindow window = PlatformUI.getWorkbench()
98 .getActiveWorkbenchWindow();
100 return window.getActivePage();
104 public static IWorkbenchWindow getActiveWorkbenchWindow() {
105 return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
108 public static Shell getActiveWorkbenchShell() {
109 return getActiveWorkbenchWindow().getShell();
112 public static void log(IStatus status) {
113 getDefault().getLog().log(status);
116 public static void log(int severity, String message) {
117 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message,
122 public static void log(Throwable e) {
123 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
124 "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
127 public static boolean isDebug() {
128 return getDefault().isDebugging();
131 protected void initializeDefaultPreferences(IPreferenceStore store) {
132 store.setDefault(PREF_STRING_CONFIGURATIONS, CONFIG_MEMENTO);
134 // windows preferences:
135 String windowsSystem = Platform.getWS();
137 if (windowsSystem.equals(Platform.WS_WIN32)) {
138 store.setDefault(PHP_CHM_ENABLED, "false");
140 .setDefault(PHP_CHM_FILE,
141 "c:\\wampp2\\php\\php_manual_en.chm");
142 store.setDefault(PHP_CHM_COMMAND,
143 "hh.exe \"mk:@MSITStore:{0}::/en/function.{1}.html\"");
145 store.setDefault(PHP_CHM_ENABLED, "false");
146 store.setDefault(PHP_CHM_FILE, "");
147 store.setDefault(PHP_CHM_COMMAND, "");
153 * Returns the standard display to be used. The method first checks, if the
154 * thread calling this method has an associated display. If so, this display
155 * is returned. Otherwise the method returns the default display.
157 public static Display getStandardDisplay() {
158 Display display = Display.getCurrent();
159 if (display == null) {
160 display = Display.getDefault();
165 // public void startup() throws CoreException {
167 // IAdapterManager manager = Platform.getAdapterManager();
168 // manager.registerAdapters(new PHPElementAdapterFactory(),
169 // PHPElement.class);
170 // manager.registerAdapters(new ResourceAdapterFactory(), IResource.class);
171 // // externalTools.startUp();
172 // getStandardDisplay().asyncExec(new Runnable() {
173 // public void run() {
174 // //initialize the variable context manager
175 // VariableContextManager.getDefault();
181 // * @see org.eclipse.core.runtime.Plugin#shutdown()
183 // public void shutdown() throws CoreException {
184 // // externalTools.shutDown();
185 // ColorManager.getDefault().dispose();
188 public void start(BundleContext context) throws Exception {
189 super.start(context);
191 manager = ConfigurationManager.getInstance();
192 // IAdapterManager manager = Platform.getAdapterManager();
193 // manager.registerAdapters(new PHPElementAdapterFactory(),
194 // PHPElement.class);
195 // manager.registerAdapters(new ResourceAdapterFactory(),
197 // // externalTools.startUp();
198 // getStandardDisplay().asyncExec(new Runnable() {
199 // public void run() {
200 // //initialize the variable context manager
201 // VariableContextManager.getDefault();
206 public void stop(BundleContext context) throws Exception {
207 // ColorManager.getDefault().dispose();
212 * Returns the translated String found with the given key.
214 * @return java.lang.String
218 public static String getResource(String key) {
220 return Platform.getResourceString(getDefault().getBundle(), key);
221 } catch (Exception e) {
227 * Return a list of all the existing configurations.
229 * @return java.util.List
231 public static List getConfigurations() {
232 return manager.getConfigurations();
236 * Create a new monitor.
238 * @return working copy
240 public static IConfigurationWorkingCopy createConfiguration() {
241 return manager.createConfiguration();
244 public static ArrayList getTypes() {
245 return CONFIGURATION_TYPES;
248 public static void addType(String type) {
249 CONFIGURATION_TYPES.add(type);