Organized imports
[phpeclipse.git] / net.sourceforge.phpeclipse.phphelp / src / net / sourceforge / phpdt / phphelp / PHPHelpPlugin.java
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
7
8 Contributors:
9     IBM Corporation - Initial implementation
10     www.phpeclipse.de
11 **********************************************************************/
12 package net.sourceforge.phpdt.phphelp;
13
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;
28
29 /**
30  * The main plugin class to be used in the desktop.
31  */
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";
36
37   /**
38    * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse.phphelp"</code>).
39    */
40   public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.phphelp"; //$NON-NLS-1$
41
42   //The shared instance.
43   private static PHPHelpPlugin plugin;
44   /**
45    * The constructor.
46    */
47   public PHPHelpPlugin(IPluginDescriptor descriptor) {
48     super();
49     plugin = this;
50   }
51
52   /**
53    * Returns the shared instance.
54    */
55   public static PHPHelpPlugin getDefault() {
56     return plugin;
57   }
58   /**
59    * Returns the workspace instance.
60    */
61   public static IWorkspace getWorkspace() {
62     return ResourcesPlugin.getWorkspace();
63   }
64
65   public static IWorkbenchPage getActivePage() {
66     return getDefault().internalGetActivePage();
67   }
68
69   private IWorkbenchPage internalGetActivePage() {
70     IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
71     if (window != null)
72       return window.getActivePage();
73     return null;
74   }
75
76   public static IWorkbenchWindow getActiveWorkbenchWindow() {
77     return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
78   }
79
80   public static Shell getActiveWorkbenchShell() {
81     return getActiveWorkbenchWindow().getShell();
82   }
83
84 //  public static String getPluginId() {
85 //    return getDefault().getDescriptor().getUniqueIdentifier();
86 //  }
87
88   public static void log(IStatus status) {
89     getDefault().getLog().log(status);
90   }
91
92   public static void log(int severity, String message) {
93     Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
94     log(status);
95   }
96   public static void log(Throwable e) {
97     log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
98   }
99
100   public static boolean isDebug() {
101     return getDefault().isDebugging();
102   }
103
104 //  static IPath getInstallLocation() {
105 //    return new Path(getDefault().getDescriptor().getInstallURL().getFile());
106 //  }
107
108   protected void initializeDefaultPreferences(IPreferenceStore store) {
109     // windows preferences:
110     String windowsSystem = Platform.getWS();
111
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\"");
116     } else {
117       store.setDefault(PHP_CHM_ENABLED, "false");
118       store.setDefault(PHP_CHM_FILE, "");
119       store.setDefault(PHP_CHM_COMMAND, "");
120     }
121
122   }
123
124   /**
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.
128    */
129   public static Display getStandardDisplay() {
130     Display display = Display.getCurrent();
131     if (display == null) {
132       display = Display.getDefault();
133     }
134     return display;
135   }
136
137 //  public void startup() throws CoreException {
138 //    super.startup();
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();
147 //      }
148 //    });
149 //  }
150
151 //  /**
152 //   * @see org.eclipse.core.runtime.Plugin#shutdown()
153 //   */
154 //  public void shutdown() throws CoreException {
155 //    //  externalTools.shutDown();
156 //    ColorManager.getDefault().dispose();
157 //  }
158
159         /* (non-Javadoc)
160          * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
161          */
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();
172 //            }
173 //          });
174         }
175         /* (non-Javadoc)
176          * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
177          */
178         public void stop(BundleContext context) throws Exception {
179 //              ColorManager.getDefault().dispose();
180                 super.stop(context);
181         }
182 }