make sure that the VariableHover for the debugPlugin is the first to show
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / PHPeclipsePlugin.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  Klaus Hartlage - www.eclipseproject.de
11  **********************************************************************/
12 package net.sourceforge.phpeclipse;
13 import java.io.File;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.HashMap;
17 import java.util.HashSet;
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.Set;
21 import net.sourceforge.phpdt.core.JavaCore;
22 import net.sourceforge.phpdt.externaltools.internal.model.ColorManager;
23 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsPlugin;
24 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
25 import net.sourceforge.phpdt.internal.core.JavaModelManager;
26 import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache;
27 import net.sourceforge.phpdt.internal.ui.preferences.TemplatePreferencePage;
28 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
29 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
30 import net.sourceforge.phpdt.internal.ui.viewsupport.ProblemMarkerManager;
31 import net.sourceforge.phpdt.ui.IContextMenuConstants;
32 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
33 import net.sourceforge.phpdt.ui.PreferenceConstants;
34 import net.sourceforge.phpdt.ui.text.JavaTextTools;
35 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
36 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
37 import net.sourceforge.phpeclipse.builder.FileStorage;
38 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
39 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
40 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
41 import net.sourceforge.phpeclipse.phpeditor.WorkingCopyManager;
42 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
43 import net.sourceforge.phpeclipse.resourcesview.PHPElement;
44 import net.sourceforge.phpeclipse.resourcesview.PHPElementAdapterFactory;
45 import net.sourceforge.phpeclipse.resourcesview.ResourceAdapterFactory;
46 import org.eclipse.core.boot.BootLoader;
47 import org.eclipse.core.resources.IFile;
48 import org.eclipse.core.resources.IProject;
49 import org.eclipse.core.resources.IResource;
50 import org.eclipse.core.resources.IResourceChangeEvent;
51 import org.eclipse.core.resources.IWorkspace;
52 import org.eclipse.core.resources.ResourcesPlugin;
53 import org.eclipse.core.runtime.CoreException;
54 import org.eclipse.core.runtime.IAdapterManager;
55 import org.eclipse.core.runtime.IPath;
56 import org.eclipse.core.runtime.IPluginDescriptor;
57 import org.eclipse.core.runtime.IConfigurationElement;
58 import org.eclipse.core.runtime.IStatus;
59 import org.eclipse.core.runtime.Path;
60 import org.eclipse.core.runtime.Platform;
61 import org.eclipse.core.runtime.Status;
62 import org.eclipse.jface.action.GroupMarker;
63 import org.eclipse.jface.action.IMenuManager;
64 import org.eclipse.jface.action.Separator;
65 import org.eclipse.jface.preference.IPreferenceStore;
66 import org.eclipse.jface.preference.PreferenceConverter;
67 import org.eclipse.jface.text.BadLocationException;
68 import org.eclipse.jface.text.IDocument;
69 import org.eclipse.swt.widgets.Display;
70 import org.eclipse.swt.widgets.Shell;
71 import org.eclipse.ui.IEditorDescriptor;
72 import org.eclipse.ui.IEditorInput;
73 import org.eclipse.ui.IEditorPart;
74 import org.eclipse.ui.IEditorRegistry;
75 import org.eclipse.ui.IWorkbench;
76 import org.eclipse.ui.IWorkbenchPage;
77 import org.eclipse.ui.IWorkbenchWindow;
78 import org.eclipse.ui.PlatformUI;
79 import org.eclipse.ui.ide.IDE;
80 import org.eclipse.ui.plugin.AbstractUIPlugin;
81 import org.eclipse.ui.texteditor.IDocumentProvider;
82 import org.eclipse.ui.texteditor.ITextEditor;
83 import org.eclipse.ui.texteditor.ConfigurationElementSorter;
84 /**
85  * The main plugin class to be used in the desktop.
86  */
87 public class PHPeclipsePlugin extends AbstractUIPlugin
88     implements
89       IPreferenceConstants {
90   /**
91    * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
92    */
93   public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
94   /**
95    * id of builder - matches plugin.xml (concatenate pluginid.builderid)
96    */
97   public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
98   //public static final String BUILDER_INDEX_ID = PLUGIN_ID + ".indexbuilder";
99   /** General debug flag */
100   public static final boolean DEBUG = false;
101   /**
102    * The maximum number of allowed proposals by category
103    */
104   public final static int MAX_PROPOSALS = 200;
105   private static ExternalToolsPlugin externalTools;
106   /**
107    * The Java virtual machine that we are running on.
108    */
109   private static int jvm;
110   /** MRJ 2.0 */
111   private static final int MRJ_2_0 = 0;
112   /** MRJ 2.1 or later */
113   private static final int MRJ_2_1 = 1;
114   /** Java on Mac OS X 10.0 (MRJ 3.0) */
115   private static final int MRJ_3_0 = 3;
116   /** MRJ 3.1 */
117   private static final int MRJ_3_1 = 4;
118   /** JVM constant for any other platform */
119   private static final int OTHER = -1;
120   // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID +
121   // ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
122   public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID
123       + ".ui.CodingActionSet"; //$NON-NLS-1$
124   public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
125   public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
126   public static final String PHPPARSER_NEW = "test.PHPParser";
127   /** Change this if you want to switch PHP Parser. */
128   public static final String PHPPARSER = PHPPARSER_ORIGINAL;
129   //The shared instance.
130   private static PHPeclipsePlugin plugin;
131   /** Windows 9x */
132   private static final int WINDOWS_9x = 6;
133   /** Windows NT */
134   private static final int WINDOWS_NT = 5;
135   private ImageDescriptorRegistry fImageDescriptorRegistry;
136   private HashMap fIndexManagerMap = new HashMap();
137   private IWorkingCopyManager fWorkingCopyManager;
138   private PHPDocumentProvider fCompilationUnitDocumentProvider;
139   private JavaTextTools fJavaTextTools;
140   private ProblemMarkerManager fProblemMarkerManager;
141   private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
142   private IFile fLastEditorFile = null;
143   private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
144   /**
145    * The constructor.
146    */
147   public PHPeclipsePlugin(IPluginDescriptor descriptor) {
148     super(descriptor);
149     plugin = this;
150     setJVM();
151     externalTools = new ExternalToolsPlugin();
152     //    try {
153     //      resourceBundle =
154     // ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
155     //    } catch (MissingResourceException x) {
156     //      resourceBundle = null;
157     //    }
158   }
159   /**
160    * Returns all Java editor text hovers contributed to the workbench.
161    * 
162    * @return an array of JavaEditorTextHoverDescriptor
163    * @since 2.1
164    */
165   public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
166     if (fJavaEditorTextHoverDescriptors == null)
167       fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor.getContributedHovers();
168                         ConfigurationElementSorter sorter= new ConfigurationElementSorter() {
169                           public IConfigurationElement getConfigurationElement(Object object) {
170                             return ((JavaEditorTextHoverDescriptor)object).getConfigurationElement();
171                           }
172                         };
173                         sorter.sort(fJavaEditorTextHoverDescriptors);    
174     return fJavaEditorTextHoverDescriptors;
175   }
176   /**
177    * Resets the Java editor text hovers contributed to the workbench.
178    * <p>
179    * This will force a rebuild of the descriptors the next time a client asks
180    * for them.
181    * </p>
182    * 
183    * @return an array of JavaEditorTextHoverDescriptor
184    * @since 2.1
185    */
186   public void resetJavaEditorTextHoverDescriptors() {
187     fJavaEditorTextHoverDescriptors = null;
188   }
189   /**
190    * Creates the PHP plugin standard groups in a context menu.
191    */
192   public static void createStandardGroups(IMenuManager menu) {
193     if (!menu.isEmpty())
194       return;
195     menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
196     menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
197     menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
198     menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
199     menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
200     menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
201     menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
202     menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
203     menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
204     menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
205     menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
206   }
207   public static IWorkbenchPage getActivePage() {
208     return getDefault().internalGetActivePage();
209   }
210   public static Shell getActiveWorkbenchShell() {
211     return getActiveWorkbenchWindow().getShell();
212   }
213   /**
214    * Returns an array of all editors that have an unsaved content. If the
215    * identical content is presented in more than one editor, only one of those
216    * editor parts is part of the result.
217    * 
218    * @return an array of all dirty editor parts.
219    */
220   public static IEditorPart[] getDirtyEditors() {
221     Set inputs = new HashSet();
222     List result = new ArrayList(0);
223     IWorkbench workbench = getDefault().getWorkbench();
224     IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
225     for (int i = 0; i < windows.length; i++) {
226       IWorkbenchPage[] pages = windows[i].getPages();
227       for (int x = 0; x < pages.length; x++) {
228         IEditorPart[] editors = pages[x].getDirtyEditors();
229         for (int z = 0; z < editors.length; z++) {
230           IEditorPart ep = editors[z];
231           IEditorInput input = ep.getEditorInput();
232           if (!inputs.contains(input)) {
233             inputs.add(input);
234             result.add(ep);
235           }
236         }
237       }
238     }
239     return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]);
240   }
241   public static IWorkbenchWindow getActiveWorkbenchWindow() {
242     return getDefault().getWorkbench().getActiveWorkbenchWindow();
243   }
244   /**
245    * Returns the shared instance.
246    */
247   public static PHPeclipsePlugin getDefault() {
248     return plugin;
249   }
250   public static ImageDescriptorRegistry getImageDescriptorRegistry() {
251     return getDefault().internalGetImageDescriptorRegistry();
252   }
253   static IPath getInstallLocation() {
254     return new Path(getDefault().getDescriptor().getInstallURL().getFile());
255   }
256   public static int getJVM() {
257     return jvm;
258   }
259   public static String getPluginId() {
260     return getDefault().getDescriptor().getUniqueIdentifier();
261   }
262   /**
263    * Returns the standard display to be used. The method first checks, if the
264    * thread calling this method has an associated display. If so, this display
265    * is returned. Otherwise the method returns the default display.
266    */
267   public static Display getStandardDisplay() {
268     Display display = Display.getCurrent();
269     if (display == null) {
270       display = Display.getDefault();
271     }
272     return display;
273   }
274   //  public static ExternalToolsPlugin getExternalTools() {
275   //    return externalTools;
276   //  }
277   /**
278    * Returns the workspace instance.
279    */
280   public static IWorkspace getWorkspace() {
281     return ResourcesPlugin.getWorkspace();
282   }
283   public static boolean isDebug() {
284     return getDefault().isDebugging();
285   }
286   //  public static void logErrorMessage(String message) {
287   //    log(new Status(IStatus.ERROR, getPluginId(),
288   // JavaStatusConstants.INTERNAL_ERROR, message, null));
289   //  }
290   //
291   //  public static void logErrorStatus(String message, IStatus status) {
292   //    if (status == null) {
293   //      logErrorMessage(message);
294   //      return;
295   //    }
296   //    MultiStatus multi= new MultiStatus(getPluginId(),
297   // JavaStatusConstants.INTERNAL_ERROR, message, null);
298   //    multi.add(status);
299   //    log(multi);
300   //  }
301   //
302   //  public static void log(Throwable e) {
303   //    log(new Status(IStatus.ERROR, getPluginId(),
304   // JavaStatusConstants.INTERNAL_ERROR,
305   // JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
306   //  }
307   public static void log(int severity, String message) {
308     Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
309     log(status);
310   }
311   public static void log(IStatus status) {
312     getDefault().getLog().log(status);
313   }
314   public static void log(Throwable e) {
315     log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
316         "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
317   }
318   private static void setJVM() {
319     String osName = System.getProperty("os.name");
320     if (osName.startsWith("Mac OS")) {
321       String mrjVersion = System.getProperty("mrj.version");
322       String majorMRJVersion = mrjVersion.substring(0, 3);
323       jvm = OTHER;
324       try {
325         double version = Double.valueOf(majorMRJVersion).doubleValue();
326         if (version == 2) {
327           jvm = MRJ_2_0;
328         } else if (version >= 2.1 && version < 3) {
329           jvm = MRJ_2_1;
330         } else if (version == 3.0) {
331           jvm = MRJ_3_0;
332         } else if (version >= 3.1) {
333           jvm = MRJ_3_1;
334         }
335       } catch (NumberFormatException nfe) {
336       }
337     } else if (osName.startsWith("Windows")) {
338       if (osName.indexOf("9") != -1) {
339         jvm = WINDOWS_9x;
340       } else {
341         jvm = WINDOWS_NT;
342       }
343     }
344   }
345   // TODO: refactor this into a better method name !
346   public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
347     if (fCompilationUnitDocumentProvider == null)
348       fCompilationUnitDocumentProvider = new PHPDocumentProvider();
349     return fCompilationUnitDocumentProvider;
350   }
351   /**
352    * Get the identifier index manager for the given project
353    * 
354    * @param iProject
355    *            the current project
356    * @return
357    */
358   public IdentifierIndexManager getIndexManager(IProject iProject) {
359     String indexFilename = iProject.getLocation() + File.separator
360         + "project.index";
361     IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap
362         .get(indexFilename);
363     if (indexManager == null) {
364       indexManager = new IdentifierIndexManager(indexFilename);
365       fIndexManagerMap.put(indexFilename, indexManager);
366     }
367     return indexManager;
368   }
369   public synchronized IWorkingCopyManager getWorkingCopyManager() {
370     if (fWorkingCopyManager == null) {
371       PHPDocumentProvider provider = getCompilationUnitDocumentProvider();
372       fWorkingCopyManager = new WorkingCopyManager(provider);
373     }
374     return fWorkingCopyManager;
375   }
376   public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
377     if (fMembersOrderPreferenceCache == null)
378       fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
379     return fMembersOrderPreferenceCache;
380   }
381   public synchronized ProblemMarkerManager getProblemMarkerManager() {
382     if (fProblemMarkerManager == null)
383       fProblemMarkerManager = new ProblemMarkerManager();
384     return fProblemMarkerManager;
385   }
386   public synchronized JavaTextTools getJavaTextTools() {
387     if (fJavaTextTools == null)
388       fJavaTextTools = new JavaTextTools(getPreferenceStore());
389     return fJavaTextTools;
390   }
391   public IFile getLastEditorFile() {
392     return fLastEditorFile;
393   }
394   /**
395    * Returns the string from the plugin's resource bundle, or 'key' if not
396    * found.
397    */
398   //  public static String getResourceString(String key) {
399   //    ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
400   //    try {
401   //      return bundle.getString(key);
402   //    } catch (MissingResourceException e) {
403   //      return key;
404   //    }
405   //  }
406   /**
407    * Returns the plugin's resource bundle,
408    */
409   //  public ResourceBundle getResourceBundle() {
410   //    return resourceBundle;
411   //  }
412   protected void initializeDefaultPreferences(IPreferenceStore store) {
413     // windows preferences:
414     store.setDefault(LOCALHOST_PREF, "http://localhost");
415     store.setDefault(SHOW_EXTERNAL_PREVIEW_PREF, "true");
416     store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
417     store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
418     String windowsSystem = BootLoader.getWS();
419     if (jvm == WINDOWS_9x) {
420       store.setDefault(EXTERNAL_BROWSER_PREF,
421           "command.com /c start iexplore {0}");
422     } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
423       store.setDefault(EXTERNAL_BROWSER_PREF,
424           "rundll32 url.dll,FileProtocolHandler {0}");
425     } else if (windowsSystem.equals(BootLoader.WS_CARBON)) {
426       // TODO How do we start Safari on Mac OS X ?
427       store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
428     } else {
429       store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
430     }
431     store.setDefault(DOCUMENTROOT_PREF, getWorkspace().getRoot().getLocation()
432         .toString());
433     //  if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
434     //  
435     if (windowsSystem.equals(BootLoader.WS_WIN32)) {
436       store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
437       store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
438       store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
439       store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
440     } else {
441       store.setDefault(PHP_RUN_PREF, "/apache/php/php");
442       store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
443       store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
444       store.setDefault(APACHE_RUN_PREF, "/apache/apache");
445     }
446     store.setDefault(MYSQL_PREF, "--standalone");
447     store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
448     store.setDefault(APACHE_STOP_PREF, "-k shutdown");
449     store.setDefault(APACHE_RESTART_PREF, "-k restart");
450     store.setDefault(MYSQL_START_BACKGROUND, "true");
451     store.setDefault(APACHE_START_BACKGROUND, "true");
452     store.setDefault(APACHE_STOP_BACKGROUND, "true");
453     store.setDefault(APACHE_RESTART_BACKGROUND, "true");
454     store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
455     store.setDefault(PHP_INTERNAL_PARSER, "false");
456     store.setDefault(PHP_EXTERNAL_PARSER, "true");
457     //    store.setDefault(PHP_PARSE_ON_SAVE, "true");
458     // show line numbers:
459     //   store.setDefault(LINE_NUMBER_RULER, "false");
460     //    store.setDefault(FORMATTER_TAB_SIZE, "4");
461     // php syntax highlighting
462     store.setDefault(PHP_USERDEF_XMLFILE, "");
463     //assume there is none chooA
464     PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT,
465         PHPColorProvider.MULTI_LINE_COMMENT);
466     PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT,
467         PHPColorProvider.SINGLE_LINE_COMMENT);
468     PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
469     PreferenceConverter
470         .setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
471     PreferenceConverter.setDefault(store, PHP_VARIABLE,
472         PHPColorProvider.VARIABLE);
473     PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME,
474         PHPColorProvider.FUNCTION_NAME);
475     PreferenceConverter.setDefault(store, PHP_CONSTANT,
476         PHPColorProvider.CONSTANT);
477     PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
478     PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
479     PreferenceConverter
480         .setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
481     PreferenceConverter.setDefault(store, PHPDOC_KEYWORD,
482         PHPColorProvider.PHPDOC_KEYWORD);
483     PreferenceConverter.setDefault(store, PHPDOC_TAG,
484         PHPColorProvider.PHPDOC_TAG);
485     PreferenceConverter.setDefault(store, PHPDOC_LINK,
486         PHPColorProvider.PHPDOC_LINK);
487     PreferenceConverter.setDefault(store, PHPDOC_DEFAULT,
488         PHPColorProvider.PHPDOC_DEFAULT);
489     //    PreferenceConverter.setDefault(
490     //      store,
491     //      PHP_EDITOR_BACKGROUND,
492     //      PHPColorProvider.BACKGROUND);
493     //    PreferenceConverter.setDefault(
494     //      store,
495     //      LINKED_POSITION_COLOR,
496     //      PHPColorProvider.LINKED_POSITION_COLOR);
497     //    PreferenceConverter.setDefault(
498     //      store,
499     //      LINE_NUMBER_COLOR,
500     //      PHPColorProvider.LINE_NUMBER_COLOR);
501     //    // set default PHPDoc colors:
502     //    PreferenceConverter.setDefault(
503     //      store,
504     //      PHPDOC_KEYWORD,
505     //      PHPColorProvider.PHPDOC_KEYWORD);
506     //    PreferenceConverter.setDefault(
507     //      store,
508     //      PHPDOC_LINK,
509     //      PHPColorProvider.PHPDOC_LINK);
510     //    PreferenceConverter.setDefault(
511     //      store,
512     //      PHPDOC_DEFAULT,
513     //      PHPColorProvider.PHPDOC_DEFAULT);
514     //    PreferenceConverter.setDefault(
515     //      store,
516     //      PHPDOC_TAG,
517     //      PHPColorProvider.PHPDOC_TAG);
518     //    store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
519     //    PreferenceConverter.setDefault(
520     //      store,
521     //      PREFERENCE_COLOR_BACKGROUND,
522     //      PHPColorProvider.BACKGROUND_COLOR);
523     //language stuff
524     //    store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
525     //    store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
526     //    store.setDefault(RESOURCE_BUNDLE_DE, "false");
527     //    store.setDefault(RESOURCE_BUNDLE_FR, "false");
528     //    store.setDefault(RESOURCE_BUNDLE_ES, "false");
529     store.setDefault(PHP_OUTLINE_CLASS, "true"); //$NON-NLS-1$
530     store.setDefault(PHP_OUTLINE_FUNC, "true"); //$NON-NLS-1$
531     store.setDefault(PHP_OUTLINE_VAR, "true"); //$NON-NLS-1$
532     TemplatePreferencePage.initDefaults(store);
533     //this will initialize the static fields in the syntaxrdr class
534     new PHPSyntaxRdr();
535     JavaCore.initializeDefaultPluginPreferences();
536     PreferenceConstants.initializeDefaultValues(store);
537     externalTools.initializeDefaultPreferences(store);
538   }
539   private IWorkbenchPage internalGetActivePage() {
540     IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
541     if (window != null)
542       return window.getActivePage();
543     return null;
544   }
545   private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
546     if (fImageDescriptorRegistry == null)
547       fImageDescriptorRegistry = new ImageDescriptorRegistry();
548     return fImageDescriptorRegistry;
549   }
550   /**
551    * Open a file in the Workbench that may or may not exist in the workspace.
552    * Must be run on the UI thread.
553    * 
554    * @param filename
555    * @throws CoreException
556    */
557   public ITextEditor openFileInTextEditor(String filename) throws CoreException {
558     //  reject directories
559     if (new File(filename).isDirectory())
560       return null;
561     IWorkbench workbench = PlatformUI.getWorkbench();
562     IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
563     IWorkbenchPage page = window.getActivePage();
564     IPath path = new Path(filename);
565     // If the file exists in the workspace, open it
566     IFile file = getWorkspace().getRoot().getFileForLocation(path);
567     IEditorPart editor;
568     ITextEditor textEditor;
569     if (file != null && file.exists()) {
570       editor = IDE.openEditor(page, file, true);
571       textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
572     } else {
573       // Otherwise open the stream directly
574       if (page == null)
575         return null;
576       FileStorage storage = new FileStorage(path);
577       IEditorRegistry registry = getWorkbench().getEditorRegistry();
578       IEditorDescriptor desc = registry.getDefaultEditor(filename);
579       if (desc == null) {
580         desc = registry.getDefaultEditor();
581       }
582       IEditorInput input = new ExternalEditorInput(storage);
583       editor = page.openEditor(input, desc.getId());
584       textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
585       // If the storage provider is not ours, we can't guarantee read/write.
586       if (textEditor != null) {
587         IDocumentProvider documentProvider = textEditor.getDocumentProvider();
588         if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
589           storage.setReadOnly();
590         }
591       }
592     }
593     return textEditor;
594   }
595   /**
596    * Open a file in the Workbench that may or may not exist in the workspace.
597    * Must be run on the UI thread.
598    * 
599    * @param filename
600    * @param line
601    * @throws CoreException
602    */
603   public void openFileAndGotoLine(String filename, int line)
604       throws CoreException {
605     ITextEditor textEditor = openFileInTextEditor(filename);
606     if (textEditor != null) {
607       // If a line number was given, go to it
608       if (line > 0) {
609         try {
610           line--; // document is 0 based
611           IDocument document = textEditor.getDocumentProvider().getDocument(
612               textEditor.getEditorInput());
613           textEditor.selectAndReveal(document.getLineOffset(line), document
614               .getLineLength(line));
615         } catch (BadLocationException e) {
616           // invalid text position -> do nothing
617         }
618       }
619     }
620   }
621   /**
622    * Open a file in the Workbench that may or may not exist in the workspace.
623    * Must be run on the UI thread.
624    * 
625    * @param filename
626    * @param offset
627    * @throws CoreException
628    */
629   public void openFileAndGotoOffset(String filename, int offset, int length)
630       throws CoreException {
631     ITextEditor textEditor = openFileInTextEditor(filename);
632     if (textEditor != null) {
633       // If a line number was given, go to it
634       if (offset >= 0) {
635         IDocument document = textEditor.getDocumentProvider().getDocument(
636             textEditor.getEditorInput());
637         textEditor.selectAndReveal(offset, length);
638       }
639     }
640   }
641   public void openFileAndFindString(String filename, String findString)
642       throws CoreException {
643     ITextEditor textEditor = openFileInTextEditor(filename);
644     if (textEditor != null) {
645       //                If a string was given, go to it
646       if (findString != null) {
647         try {
648           IDocument document = textEditor.getDocumentProvider().getDocument(
649               textEditor.getEditorInput());
650           int offset = document.search(0, findString, true, false, true);
651           textEditor.selectAndReveal(offset, findString.length());
652         } catch (BadLocationException e) {
653           // invalid text position -> do nothing
654         }
655       }
656     }
657   }
658   public void setLastEditorFile(IFile textEditor) {
659     this.fLastEditorFile = textEditor;
660   }
661   /**
662    * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
663    */
664   public void shutdown() throws CoreException {
665     // moved down (see below):
666     //    super.shutdown();
667     //  externalTools.shutDown();
668     ColorManager.getDefault().dispose();
669     // save the information from the php index files if necessary
670     Collection collection = fIndexManagerMap.values();
671     Iterator iterator = collection.iterator();
672     IdentifierIndexManager indexManager = null;
673     while (iterator.hasNext()) {
674       indexManager = (IdentifierIndexManager) iterator.next();
675       indexManager.writeFile();
676     }
677     if (fImageDescriptorRegistry != null)
678       fImageDescriptorRegistry.dispose();
679     //                          unregisterAdapters();
680     super.shutdown();
681     if (fWorkingCopyManager != null) {
682       fWorkingCopyManager.shutdown();
683       fWorkingCopyManager = null;
684     }
685     if (fCompilationUnitDocumentProvider != null) {
686       fCompilationUnitDocumentProvider.shutdown();
687       fCompilationUnitDocumentProvider = null;
688     }
689     if (fJavaTextTools != null) {
690       fJavaTextTools.dispose();
691       fJavaTextTools = null;
692     }
693     //                          JavaDocLocations.shutdownJavadocLocations();
694     //          
695     //                          JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
696     // begin JavaCore#shutdown()
697     //savePluginPreferences();
698     savePluginPreferences();
699     IWorkspace workspace = ResourcesPlugin.getWorkspace();
700     workspace.removeResourceChangeListener(JavaModelManager
701         .getJavaModelManager().deltaProcessor);
702     workspace.removeSaveParticipant(PHPeclipsePlugin.getDefault());
703     ((JavaModelManager) JavaModelManager.getJavaModelManager()).shutdown();
704     //   end JavaCore#shutdown()
705   }
706   public void startup() throws CoreException {
707     super.startup();
708     // begin JavaCore.startup();
709     JavaModelManager manager = JavaModelManager.getJavaModelManager();
710     try {
711       manager.configurePluginDebugOptions();
712       // request state folder creation (workaround 19885)
713       //                JavaCore.getPlugin().getStateLocation();
714       getStateLocation();
715       // retrieve variable values
716       //                JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new
717       // JavaModelManager.PluginPreferencesListener());
718       getPluginPreferences().addPropertyChangeListener(
719           new JavaModelManager.PluginPreferencesListener());
720       //        TODO khartlage temp-del
721       //                manager.loadVariablesAndContainers();
722       IWorkspace workspace = ResourcesPlugin.getWorkspace();
723       workspace.addResourceChangeListener(manager.deltaProcessor,
724           IResourceChangeEvent.PRE_AUTO_BUILD
725               | IResourceChangeEvent.POST_AUTO_BUILD
726               | IResourceChangeEvent.POST_CHANGE
727               | IResourceChangeEvent.PRE_DELETE
728               | IResourceChangeEvent.PRE_CLOSE);
729       //                startIndexing();
730       workspace.addSaveParticipant(PHPeclipsePlugin.getDefault(), manager);
731     } catch (CoreException e) {
732     } catch (RuntimeException e) {
733       manager.shutdown();
734       throw e;
735     }
736     //   end JavaCore.startup();
737     IAdapterManager platformManager = Platform.getAdapterManager();
738     platformManager.registerAdapters(new PHPElementAdapterFactory(),
739         PHPElement.class);
740     platformManager.registerAdapters(new ResourceAdapterFactory(),
741         IResource.class);
742     //  externalTools.startUp();
743     getStandardDisplay().asyncExec(new Runnable() {
744       public void run() {
745         //initialize the variable context manager
746         VariableContextManager.getDefault();
747       }
748     });
749   }
750 }