d04f02774d64b628dac2c41a425796d8445030a2
[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  **********************************************************************/
9 package net.sourceforge.phpeclipse;
10
11 import java.io.File;
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Enumeration;
17 import java.util.HashMap;
18 import java.util.HashSet;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.PropertyResourceBundle;
22 import java.util.Set;
23
24 import net.sourceforge.phpdt.core.IBuffer;
25 import net.sourceforge.phpdt.core.IBufferFactory;
26 import net.sourceforge.phpdt.core.ICompilationUnit;
27 import net.sourceforge.phpdt.core.IJavaElement;
28 import net.sourceforge.phpdt.core.JavaCore;
29 import net.sourceforge.phpdt.core.WorkingCopyOwner;
30 import net.sourceforge.phpdt.internal.core.BatchOperation;
31 import net.sourceforge.phpdt.internal.core.JavaModelManager;
32 import net.sourceforge.phpdt.internal.core.util.Util;
33 /*import net.sourceforge.phpdt.internal.corext.template.php.CodeTemplateContextType;
34 import net.sourceforge.phpdt.internal.corext.template.php.HTMLContextType;
35 import net.sourceforge.phpdt.internal.corext.template.php.JavaContextType;
36 import net.sourceforge.phpdt.internal.corext.template.php.JavaDocContextType;*/
37 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
38 /*import net.sourceforge.phpdt.internal.ui.IJavaStatusConstants;
39 import net.sourceforge.phpdt.internal.ui.JavaElementAdapterFactory;
40 import net.sourceforge.phpdt.internal.ui.ResourceAdapterFactory;
41 import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache;
42 import net.sourceforge.phpdt.internal.ui.preferences.MockupPreferenceStore;
43 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
44 import net.sourceforge.phpdt.internal.ui.text.folding.JavaFoldingStructureProviderRegistry;
45 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
46 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
47 import net.sourceforge.phpdt.internal.ui.viewsupport.ProblemMarkerManager;
48 import net.sourceforge.phpdt.ui.IContextMenuConstants;
49 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
50 import net.sourceforge.phpdt.ui.PreferenceConstants;
51 import net.sourceforge.phpdt.ui.text.JavaTextTools;*/
52 /*import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
53 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
54 import net.sourceforge.phpeclipse.builder.FileStorage;
55 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;*/
56 /*import net.sourceforge.phpeclipse.phpeditor.CustomBufferFactory;
57 import net.sourceforge.phpeclipse.phpeditor.DocumentAdapter;
58 import net.sourceforge.phpeclipse.phpeditor.ICompilationUnitDocumentProvider;
59 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
60 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
61 import net.sourceforge.phpeclipse.phpeditor.WorkingCopyManager;
62 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;*/
63
64 import org.eclipse.core.resources.IFile;
65 import org.eclipse.core.resources.IProject;
66 import org.eclipse.core.resources.IResource;
67 import org.eclipse.core.resources.IResourceChangeEvent;
68 import org.eclipse.core.resources.ISavedState;
69 import org.eclipse.core.resources.IWorkspace;
70 import org.eclipse.core.resources.IWorkspaceRunnable;
71 import org.eclipse.core.resources.ResourcesPlugin;
72 import org.eclipse.core.resources.WorkspaceJob;
73 import org.eclipse.core.runtime.CoreException;
74 import org.eclipse.core.runtime.IAdapterManager;
75 import org.eclipse.core.runtime.IConfigurationElement;
76 import org.eclipse.core.runtime.IPath;
77 import org.eclipse.core.runtime.IProgressMonitor;
78 import org.eclipse.core.runtime.IStatus;
79 import org.eclipse.core.runtime.Path;
80 import org.eclipse.core.runtime.Platform;
81 import org.eclipse.core.runtime.Plugin;
82 import org.eclipse.core.runtime.Status;
83 import org.eclipse.core.runtime.jobs.ISchedulingRule;
84 import org.eclipse.core.runtime.jobs.Job;
85 import org.eclipse.jface.text.templates.ContextTypeRegistry;
86 import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
87 /*import org.eclipse.jface.action.GroupMarker;
88 import org.eclipse.jface.action.IMenuManager;
89 import org.eclipse.jface.action.Separator;
90 import org.eclipse.jface.preference.IPreferenceStore;
91 import org.eclipse.jface.preference.PreferenceConverter;
92 import org.eclipse.jface.resource.JFaceResources;*/
93 /*import org.eclipse.jface.text.BadLocationException;
94 import org.eclipse.jface.text.IDocument;
95 import org.eclipse.jface.text.templates.ContextTypeRegistry;
96 import org.eclipse.jface.text.templates.persistence.TemplateStore;
97 import org.eclipse.jface.util.IPropertyChangeListener;
98 import org.eclipse.jface.util.PropertyChangeEvent;
99 import org.eclipse.swt.graphics.RGB;
100 import org.eclipse.swt.widgets.Display;
101 import org.eclipse.swt.widgets.Shell;
102 import org.eclipse.ui.IEditorDescriptor;
103 import org.eclipse.ui.IEditorInput;
104 import org.eclipse.ui.IEditorPart;
105 import org.eclipse.ui.IEditorRegistry;
106 import org.eclipse.ui.IWorkbench;
107 import org.eclipse.ui.IWorkbenchPage;
108 import org.eclipse.ui.IWorkbenchWindow;
109 import org.eclipse.ui.PlatformUI;
110 import org.eclipse.ui.editors.text.EditorsUI;
111 import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
112 import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
113 import org.eclipse.ui.ide.IDE;
114 import org.eclipse.ui.plugin.AbstractUIPlugin;
115 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
116 import org.eclipse.ui.texteditor.ConfigurationElementSorter;
117 import org.eclipse.ui.texteditor.IDocumentProvider;
118 import org.eclipse.ui.texteditor.ITextEditor;
119 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;*/
120 import org.osgi.framework.BundleContext;
121
122 /**
123  * The main plugin class to be used in the desktop.
124  */
125 public class PHPeclipsePlugin extends /*AbstractUIPlugin*/Plugin implements
126                 IPreferenceConstants {
127         /**
128          * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
129          */
130         public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
131
132         public static final String EDITOR_ID = PHPeclipsePlugin.PLUGIN_ID
133                         + ".PHPUnitEditor";
134
135         //public static final String ID_PERSPECTIVE = "net.sourceforge.phpeclipse.PHPPerspective"; //$NON-NLS-1$
136
137         IWorkspace w;
138
139         /**
140          * id of builder - matches plugin.xml (concatenate pluginid.builderid)
141          */
142         public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
143
144         // public static final String BUILDER_INDEX_ID = PLUGIN_ID +
145         // ".indexbuilder";
146         /** General debug flag */
147
148         public static final boolean DEBUG = false;
149
150         /**
151          * The maximum number of allowed proposals by category
152          */
153         public final static int MAX_PROPOSALS = 200;
154
155         /**
156          * The key to store customized templates.
157          * 
158          * @since 3.0
159          */
160         private static final String TEMPLATES_KEY = "net.sourceforge.phpdt.ui.text.custom_templates"; //$NON-NLS-1$
161
162         /**
163          * The key to store customized code templates.
164          * 
165          * @since 3.0
166          */
167         private static final String CODE_TEMPLATES_KEY = "net.sourceforge.phpdt.ui.text.custom_code_templates"; //$NON-NLS-1$
168
169         public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID
170                         + ".ui.CodingActionSet"; //$NON-NLS-1$
171
172         public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
173
174         public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
175
176         public static final String PHPPARSER_NEW = "test.PHPParser";
177
178         /** Change this if you want to switch PHP Parser. */
179         public static final String PHPPARSER = PHPPARSER_ORIGINAL;
180
181         // The shared instance.
182         private static PHPeclipsePlugin plugin;
183
184         /**
185          * The template context type registry for the java editor.
186          * 
187          * @since 3.0
188          */
189         /*private ContextTypeRegistry fContextTypeRegistry;*/
190
191         /**
192          * The code template context type registry for the java editor.
193          * 
194          * @since 3.0
195          */
196         private ContextTypeRegistry fCodeTemplateContextTypeRegistry;
197
198         /**
199          * The template store for the java editor.
200          * 
201          * @since 3.0
202          */
203         /*private TemplateStore fTemplateStore;*/
204
205         /**
206          * The coded template store for the java editor.
207          * 
208          * @since 3.0
209          */
210         /*private TemplateStore fCodeTemplateStore;*/
211
212         /** Windows 9x */
213         private static final int WINDOWS_9x = 6;
214
215         /** Windows NT */
216         private static final int WINDOWS_NT = 5;
217
218         /*private ImageDescriptorRegistry fImageDescriptorRegistry;*/
219
220         private HashMap fIndexManagerMap = new HashMap();
221
222         /*private IWorkingCopyManager fWorkingCopyManager;*/
223
224         private IBufferFactory fBufferFactory;
225
226         /*private ICompilationUnitDocumentProvider fCompilationUnitDocumentProvider;*/
227
228         /*private JavaTextTools fJavaTextTools;*/
229
230         /*private ProblemMarkerManager fProblemMarkerManager;*/
231
232         /*private MembersOrderPreferenceCache fMembersOrderPreferenceCache;*/
233
234         private IFile fLastEditorFile = null;
235
236 /*      private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;*/
237
238         /*private JavaElementAdapterFactory fJavaElementAdapterFactory;*/
239
240         // private MarkerAdapterFactory fMarkerAdapterFactory;
241         // private EditorInputAdapterFactory fEditorInputAdapterFactory;
242         /*private ResourceAdapterFactory fResourceAdapterFactory;*/
243
244         // private LogicalPackageAdapterFactory fLogicalPackageAdapterFactory;
245         /*private IPropertyChangeListener fFontPropertyChangeListener;*/
246
247         /**
248          * Property change listener on this plugin's preference store.
249          * 
250          * @since 3.0
251          */
252         // private IPropertyChangeListener fPropertyChangeListener;
253         /**
254          * The combined preference store.
255          * 
256          * @since 3.0
257          */
258         /*private IPreferenceStore fCombinedPreferenceStore;*/
259
260         /**
261          * The extension point registry for the
262          * <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code>
263          * extension point.
264          * 
265          * @since 3.0
266          */
267         /*private JavaFoldingStructureProviderRegistry fFoldingStructureProviderRegistry;*/
268
269         /**
270          * Mockup preference store for firing events and registering listeners on
271          * project setting changes. FIXME: Temporary solution.
272          * 
273          * @since 3.0
274          */
275         /*private MockupPreferenceStore fMockupPreferenceStore;*/
276
277         /**
278          * The constructor.
279          */
280         public PHPeclipsePlugin() {
281                 super();
282                 plugin = this;
283                 // externalTools = new ExternalToolsPlugin();
284
285                 // try {
286                 // resourceBundle =
287                 // ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
288                 // } catch (MissingResourceException x) {
289                 // resourceBundle = null;
290                 // }
291         }
292
293         // /**
294         // * Returns all Java editor text hovers contributed to the workbench.
295         // *
296         // * @return an array of JavaEditorTextHoverDescriptor
297         // * @since 2.1
298         // */
299         // public JavaEditorTextHoverDescriptor[]
300         // getJavaEditorTextHoverDescriptors()
301         // {
302         // if (fJavaEditorTextHoverDescriptors == null)
303         // fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
304         // .getContributedHovers();
305         // return fJavaEditorTextHoverDescriptors;
306         // }
307         /**
308          * Returns all Java editor text hovers contributed to the workbench.
309          * 
310          * @return an array of JavaEditorTextHoverDescriptor
311          * @since 2.1
312          */
313 //      public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
314 //              if (fJavaEditorTextHoverDescriptors == null) {
315 //                      fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
316 //                                      .getContributedHovers();
317 //                      ConfigurationElementSorter sorter = new ConfigurationElementSorter() {
318 //                              /*
319 //                               * @see org.eclipse.ui.texteditor.ConfigurationElementSorter#getConfigurationElement(java.lang.Object)
320 //                               */
321 //                              public IConfigurationElement getConfigurationElement(
322 //                                              Object object) {
323 //                                      return ((JavaEditorTextHoverDescriptor) object)
324 //                                                      .getConfigurationElement();
325 //                              }
326 //                      };
327 //                      sorter.sort(fJavaEditorTextHoverDescriptors);
328 //
329 //                      // The Problem hover has to be the first and the Annotation hover
330 //                      // has to
331 //                      // be the last one in the JDT UI's hover list
332 //                      int length = fJavaEditorTextHoverDescriptors.length;
333 //                      int first = -1;
334 //                      int last = length - 1;
335 //                      int problemHoverIndex = -1;
336 //                      int annotationHoverIndex = -1;
337 //                      for (int i = 0; i < length; i++) {
338 //                              if (!fJavaEditorTextHoverDescriptors[i].getId().startsWith(
339 //                                              PLUGIN_ID)) {
340 //                                      if (problemHoverIndex == -1 || annotationHoverIndex == -1)
341 //                                              continue;
342 //                                      else {
343 //                                              last = i - 1;
344 //                                              break;
345 //                                      }
346 //                              }
347 //                              if (first == -1)
348 //                                      first = i;
349 //
350 //                              if (fJavaEditorTextHoverDescriptors[i].getId().equals(
351 //                                              "net.sourceforge.phpdt.ui.AnnotationHover")) { //$NON-NLS-1$
352 //                                      annotationHoverIndex = i;
353 //                                      continue;
354 //                              }
355 //                              if (fJavaEditorTextHoverDescriptors[i].getId().equals(
356 //                                              "net.sourceforge.phpdt.ui.ProblemHover")) { //$NON-NLS-1$
357 //                                      problemHoverIndex = i;
358 //                                      continue;
359 //                              }
360 //                      }
361 //
362 //                      JavaEditorTextHoverDescriptor hoverDescriptor = null;
363 //
364 //                      if (first > -1 && problemHoverIndex > -1
365 //                                      && problemHoverIndex != first) {
366 //                              // move problem hover to beginning
367 //                              hoverDescriptor = fJavaEditorTextHoverDescriptors[first];
368 //                              fJavaEditorTextHoverDescriptors[first] = fJavaEditorTextHoverDescriptors[problemHoverIndex];
369 //                              fJavaEditorTextHoverDescriptors[problemHoverIndex] = hoverDescriptor;
370 //
371 //                              // update annotation hover index if needed
372 //                              if (annotationHoverIndex == first)
373 //                                      annotationHoverIndex = problemHoverIndex;
374 //                      }
375 //
376 //                      if (annotationHoverIndex > -1 && annotationHoverIndex != last) {
377 //                              // move annotation hover to end
378 //                              hoverDescriptor = fJavaEditorTextHoverDescriptors[last];
379 //                              fJavaEditorTextHoverDescriptors[last] = fJavaEditorTextHoverDescriptors[annotationHoverIndex];
380 //                              fJavaEditorTextHoverDescriptors[annotationHoverIndex] = hoverDescriptor;
381 //                      }
382 //
383 //                      // Move Best Match hover to front
384 //                      for (int i = 0; i < fJavaEditorTextHoverDescriptors.length - 1; i++) {
385 //                              if (PreferenceConstants.ID_BESTMATCH_HOVER
386 //                                              .equals(fJavaEditorTextHoverDescriptors[i].getId())) {
387 //                                      hoverDescriptor = fJavaEditorTextHoverDescriptors[i];
388 //                                      for (int j = i; j > 0; j--)
389 //                                              fJavaEditorTextHoverDescriptors[j] = fJavaEditorTextHoverDescriptors[j - 1];
390 //                                      fJavaEditorTextHoverDescriptors[0] = hoverDescriptor;
391 //                                      break;
392 //                              }
393 //
394 //                      }
395 //              }
396 //
397 //              return fJavaEditorTextHoverDescriptors;
398 //      }
399
400         /**
401          * Resets the Java editor text hovers contributed to the workbench.
402          * <p>
403          * This will force a rebuild of the descriptors the next time a client asks
404          * for them.
405          * </p>
406          * 
407          * @return an array of JavaEditorTextHoverDescriptor
408          * @since 2.1
409          */
410 //      public void resetJavaEditorTextHoverDescriptors() {
411 //              fJavaEditorTextHoverDescriptors = null;
412 //      }
413
414         /**
415          * Creates the PHP plugin standard groups in a context menu.
416          */
417 //      public static void createStandardGroups(IMenuManager menu) {
418 //              if (!menu.isEmpty())
419 //                      return;
420 //              menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
421 //              menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
422 //              menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
423 //              menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
424 //              menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
425 //              menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
426 //              menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
427 //              menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
428 //              menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
429 //              menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
430 //              menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
431 //      }
432 //
433 //      public static IWorkbenchPage getActivePage() {
434 //              return getDefault().internalGetActivePage();
435 //      }
436 //
437 //      public static Shell getActiveWorkbenchShell() {
438 //              return getActiveWorkbenchWindow().getShell();
439 //      }
440
441         /**
442          * Returns an array of all editors that have an unsaved content. If the
443          * identical content is presented in more than one editor, only one of those
444          * editor parts is part of the result.
445          * 
446          * @return an array of all dirty editor parts.
447          */
448 //      public static IEditorPart[] getDirtyEditors() {
449 //              Set inputs = new HashSet();
450 //              List result = new ArrayList(0);
451 //              IWorkbench workbench = getDefault().getWorkbench();
452 //              IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
453 //              for (int i = 0; i < windows.length; i++) {
454 //                      IWorkbenchPage[] pages = windows[i].getPages();
455 //                      for (int x = 0; x < pages.length; x++) {
456 //                              IEditorPart[] editors = pages[x].getDirtyEditors();
457 //                              for (int z = 0; z < editors.length; z++) {
458 //                                      IEditorPart ep = editors[z];
459 //                                      IEditorInput input = ep.getEditorInput();
460 //                                      if (!inputs.contains(input)) {
461 //                                              inputs.add(input);
462 //                                              result.add(ep);
463 //                                      }
464 //                              }
465 //                      }
466 //              }
467 //              return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]);
468 //      }
469 //
470 //      public static IWorkbenchWindow getActiveWorkbenchWindow() {
471 //              return getDefault().getWorkbench().getActiveWorkbenchWindow();
472 //      }
473
474         /**
475          * Returns the shared instance.
476          */
477         public static PHPeclipsePlugin getDefault() {
478                 return plugin;
479         }
480
481 //      public static ImageDescriptorRegistry getImageDescriptorRegistry() {
482 //              return getDefault().internalGetImageDescriptorRegistry();
483 //      }
484
485         static IPath getInstallLocation() {
486                 return new Path(getDefault().getBundle().getEntry("/").getFile());
487         }
488
489         // public static int getJVM() {
490         // return jvm;
491         // }
492
493         public static String getPluginId() {
494                 return getDefault().getBundle().getSymbolicName();
495         }
496
497         /**
498          * Returns the standard display to be used. The method first checks, if the
499          * thread calling this method has an associated display. If so, this display
500          * is returned. Otherwise the method returns the default display.
501          */
502 //      public static Display getStandardDisplay() {
503 //              Display display = Display.getCurrent();
504 //              if (display == null) {
505 //                      display = Display.getDefault();
506 //              }
507 //              return display;
508 //      }
509
510         // public static ExternalToolsPlugin getExternalTools() {
511         // return externalTools;
512         // }
513         /**
514          * Returns the workspace instance.
515          */
516         public static IWorkspace getWorkspace() {
517                 return ResourcesPlugin.getWorkspace();
518         }
519
520         public static boolean isDebug() {
521                 return getDefault().isDebugging();
522         }
523
524         // public static void logErrorMessage(String message) {
525         // log(new Status(IStatus.ERROR, getPluginId(),
526         // JavaStatusConstants.INTERNAL_ERROR, message, null));
527         // }
528         //
529         // public static void logErrorStatus(String message, IStatus status) {
530         // if (status == null) {
531         // logErrorMessage(message);
532         // return;
533         // }
534         // MultiStatus multi= new MultiStatus(getPluginId(),
535         // JavaStatusConstants.INTERNAL_ERROR, message, null);
536         // multi.add(status);
537         // log(multi);
538         // }
539         //
540         // public static void log(Throwable e) {
541         // log(new Status(IStatus.ERROR, getPluginId(),
542         // JavaStatusConstants.INTERNAL_ERROR,
543         // JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
544         // }
545         public static void log(int severity, String message) {
546                 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message,
547                                 null);
548                 log(status);
549         }
550
551         public static void log(IStatus status) {
552                 getDefault().getLog().log(status);
553         }
554
555         public static void log(Throwable t) {
556                 log(error(t));
557         }
558
559         public static void log(String message, Throwable t) {
560                 log(error(message, t));
561         }
562
563 //      public static void logErrorMessage(String message) {
564 //              log(new Status(IStatus.ERROR, getPluginId(),
565 //                              IJavaStatusConstants.INTERNAL_ERROR, message, null));
566 //      }
567
568         public static IStatus error(Throwable t) {
569                 return error("PHPeclipsePlugin.internalErrorOccurred", t); //$NON-NLS-1$
570         }
571
572         public static IStatus error(String message, Throwable t) {
573                 return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, t);
574         }
575
576         // private static void setJVM() {
577         // String osName = System.getProperty("os.name");
578         // if (osName.startsWith("Mac OS")) {
579         // String mrjVersion = System.getProperty("mrj.version");
580         // String majorMRJVersion = mrjVersion.substring(0, 3);
581         // jvm = OTHER;
582         // try {
583         // double version = Double.valueOf(majorMRJVersion).doubleValue();
584         // if (version == 2) {
585         // jvm = MRJ_2_0;
586         // } else if (version >= 2.1 && version < 3) {
587         // jvm = MRJ_2_1;
588         // } else if (version == 3.0) {
589         // jvm = MRJ_3_0;
590         // } else if (version >= 3.1) {
591         // jvm = MRJ_3_1;
592         // }
593         // } catch (NumberFormatException nfe) {
594         // }
595         // } else if (osName.startsWith("Windows")) {
596         // if (osName.indexOf("9") != -1) {
597         // jvm = WINDOWS_9x;
598         // } else {
599         // jvm = WINDOWS_NT;
600         // }
601         // }
602         // }
603
604         // TODO: refactor this into a better method name !
605 //      public synchronized ICompilationUnitDocumentProvider getCompilationUnitDocumentProvider() {
606 //              if (fCompilationUnitDocumentProvider == null)
607 //                      fCompilationUnitDocumentProvider = new PHPDocumentProvider();
608 //              return fCompilationUnitDocumentProvider;
609 //      }
610
611         /**
612          * Get the identifier index manager for the given project
613          * 
614          * @param iProject
615          *            the current project
616          * @return
617          */
618         public IdentifierIndexManager getIndexManager(IProject iProject) {
619                 IPath path = iProject.getWorkingLocation(PHPeclipsePlugin.PLUGIN_ID);
620                 path = path.append("project.index");
621                 String indexFilename = path.toString();
622                 // try {
623                 // IdentDB db = IdentDB.getInstance();
624                 // } catch (ClassNotFoundException e) {
625                 // e.printStackTrace();
626                 // } catch (SQLException e) {
627                 // e.printStackTrace();
628                 // }
629                 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap
630                                 .get(indexFilename);
631                 if (indexManager == null) {
632                         indexManager = new IdentifierIndexManager(indexFilename);
633                         fIndexManagerMap.put(indexFilename, indexManager);
634                 }
635                 return indexManager;
636         }
637 //
638 //      public synchronized IWorkingCopyManager getWorkingCopyManager() {
639 //              if (fWorkingCopyManager == null) {
640 //                      ICompilationUnitDocumentProvider provider = getCompilationUnitDocumentProvider();
641 //                      fWorkingCopyManager = new WorkingCopyManager(provider);
642 //              }
643 //              return fWorkingCopyManager;
644 //      }
645 //
646 //      public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
647 //              if (fMembersOrderPreferenceCache == null)
648 //                      fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
649 //              return fMembersOrderPreferenceCache;
650 //      }
651 //
652 //      /**
653 //       * Returns the mockup preference store for firing events and registering
654 //       * listeners on project setting changes. Temporary solution.
655 //       */
656 //      public MockupPreferenceStore getMockupPreferenceStore() {
657 //              if (fMockupPreferenceStore == null)
658 //                      fMockupPreferenceStore = new MockupPreferenceStore();
659 //
660 //              return fMockupPreferenceStore;
661 //      }
662 //
663 //      public synchronized ProblemMarkerManager getProblemMarkerManager() {
664 //              if (fProblemMarkerManager == null)
665 //                      fProblemMarkerManager = new ProblemMarkerManager();
666 //              return fProblemMarkerManager;
667 //      }
668
669         // public synchronized JavaTextTools getJavaTextTools() {
670         // if (fJavaTextTools == null)
671         // fJavaTextTools = new JavaTextTools(getPreferenceStore());
672         // return fJavaTextTools;
673         // }
674 //      public synchronized JavaTextTools getJavaTextTools() {
675 //              if (fJavaTextTools == null)
676 //                      fJavaTextTools = new JavaTextTools(getPreferenceStore(), JavaCore
677 //                                      .getPlugin().getPluginPreferences());
678 //              return fJavaTextTools;
679 //      }
680
681         public IFile getLastEditorFile() {
682                 return fLastEditorFile;
683         }
684
685         /**
686          * Returns the string from the plugin's resource bundle, or 'key' if not
687          * found.
688          */
689         // public static String getResourceString(String key) {
690         // ResourceBundle bundle =
691         // PHPeclipsePlugin.getDefault().getResourceBundle();
692         // try {
693         // return bundle.getString(key);
694         // } catch (MissingResourceException e) {
695         // return key;
696         // }
697         // }
698         /**
699          * Returns the plugin's resource bundle,
700          */
701         // public ResourceBundle getResourceBundle() {
702         // return resourceBundle;
703         // }
704 //      protected void initializeDefaultPreferences(IPreferenceStore store) {
705 //              String operatingSystem = Platform.getOS();
706 //              // maxosx, linux, solaris, win32,...
707 //              try {
708 //                      InputStream is = getDefault()
709 //                                      .openStream(
710 //                                                      new Path("prefs/default_" + operatingSystem
711 //                                                                      + ".properties"));
712 //                      PropertyResourceBundle resourceBundle = new PropertyResourceBundle(
713 //                                      is);
714 //                      Enumeration e = resourceBundle.getKeys();
715 //                      String key;
716 //                      while (e.hasMoreElements()) {
717 //                              key = (String) e.nextElement();
718 //                              store.setDefault(key, resourceBundle.getString(key));
719 //                      }
720 //              } catch (Exception e) {
721 //                      // no default properties found
722 //                      if (operatingSystem.equals(Platform.OS_WIN32)) {
723 //                              // store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
724 //                              // store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php
725 //                              // -l -f {0}");
726 //                              // store.setDefault(MYSQL_RUN_PREF,
727 //                              // "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
728 //                              // store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
729 //                              // store.setDefault(XAMPP_START_PREF,
730 //                              // "c:\\xampp\\xampp_start.exe");
731 //                              // store.setDefault(XAMPP_STOP_PREF,
732 //                              // "c:\\xampp\\xampp_stop.exe");
733 //                              // store.setDefault(
734 //                              // ETC_HOSTS_PATH_PREF,
735 //                              // "c:\\windows\\system32\\drivers\\etc\\hosts");
736 //                      } else {
737 //                              // store.setDefault(PHP_RUN_PREF, "/apache/php/php");
738 //                              // store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f
739 //                              // {0}");
740 //                              // store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
741 //                              // store.setDefault(APACHE_RUN_PREF, "/apache/apache");
742 //                              // store.setDefault(XAMPP_START_PREF, "xamp/xampp_start");
743 //                              // store.setDefault(XAMPP_STOP_PREF, "xampp/xampp_stop");
744 //                      }
745 //                      // store.setDefault(MYSQL_PREF, "--standalone");
746 //                      // store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot
747 //                      // \"{0}\"\"");
748 //                      // store.setDefault(APACHE_STOP_PREF, "-k shutdown");
749 //                      // store.setDefault(APACHE_RESTART_PREF, "-k restart");
750 //                      // store.setDefault(MYSQL_START_BACKGROUND, "true");
751 //                      // store.setDefault(APACHE_START_BACKGROUND, "true");
752 //                      // store.setDefault(APACHE_STOP_BACKGROUND, "true");
753 //                      // store.setDefault(APACHE_RESTART_BACKGROUND, "true");
754 //              }
755 //
756 //              // php syntax highlighting
757 //              store.setDefault(PHP_USERDEF_XMLFILE, "");
758 //              PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
759 //              PreferenceConverter.setDefault(store, PHP_KEYWORD,
760 //                              PHPColorProvider.KEYWORD);
761 //              PreferenceConverter.setDefault(store, PHP_VARIABLE,
762 //                              PHPColorProvider.VARIABLE);
763 //              PreferenceConverter.setDefault(store, PHP_VARIABLE_DOLLAR,
764 //                              PHPColorProvider.VARIABLE);
765 //              PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME,
766 //                              PHPColorProvider.FUNCTION_NAME);
767 //              PreferenceConverter.setDefault(store, PHP_CONSTANT,
768 //                              PHPColorProvider.CONSTANT);
769 //              PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
770 //              PreferenceConverter.setDefault(store, PHP_DEFAULT,
771 //                              PHPColorProvider.DEFAULT);
772 //              PreferenceConverter.setDefault(store, PHPDOC_KEYWORD,
773 //                              PHPColorProvider.PHPDOC_KEYWORD);
774 //              PreferenceConverter.setDefault(store, PHPDOC_TAG,
775 //                              PHPColorProvider.PHPDOC_TAG);
776 //              PreferenceConverter.setDefault(store, PHPDOC_LINK,
777 //                              PHPColorProvider.PHPDOC_LINK);
778 //              PreferenceConverter.setDefault(store, PHPDOC_DEFAULT,
779 //                              PHPColorProvider.PHPDOC_DEFAULT);
780 //
781 //              PreferenceConverter.setDefault(store, EDITOR_PHP_KEYWORD_RETURN_COLOR,
782 //                              new RGB(127, 0, 85));
783 //              store.setDefault(EDITOR_PHP_KEYWORD_RETURN_BOLD, true);
784 //              store.setDefault(EDITOR_PHP_KEYWORD_RETURN_ITALIC, false);
785 //
786 //              PreferenceConverter.setDefault(store, EDITOR_PHP_OPERATOR_COLOR,
787 //                              new RGB(0, 0, 0));
788 //              store.setDefault(EDITOR_PHP_OPERATOR_BOLD, false);
789 //              store.setDefault(EDITOR_PHP_OPERATOR_ITALIC, false);
790 //
791 //              PreferenceConverter.setDefault(store, EDITOR_PHP_BRACE_OPERATOR_COLOR,
792 //                              new RGB(0, 0, 0));
793 //              store.setDefault(EDITOR_PHP_BRACE_OPERATOR_BOLD, false);
794 //              store.setDefault(EDITOR_PHP_BRACE_OPERATOR_ITALIC, false);
795 //
796 //              // this will initialize the static fields in the syntaxrdr class
797 //              new PHPSyntaxRdr();
798 //              JavaCore.initializeDefaultPluginPreferences();
799 //              PreferenceConstants.initializeDefaultValues(store);
800 //              // externalTools.initializeDefaultPreferences(store);
801 //              // MarkerAnnotationPreferences.initializeDefaultValues(store);
802 //      }
803 //
804 //      private IWorkbenchPage internalGetActivePage() {
805 //              IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
806 //              if (window != null)
807 //                      return window.getActivePage();
808 //              return null;
809 //      }
810 //
811 //      private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
812 //              if (fImageDescriptorRegistry == null)
813 //                      fImageDescriptorRegistry = new ImageDescriptorRegistry();
814 //              return fImageDescriptorRegistry;
815 //      }
816
817         /**
818          * Open a file in the Workbench that may or may not exist in the workspace.
819          * Must be run on the UI thread.
820          * 
821          * @param filename
822          * @throws CoreException
823          */
824 //      public ITextEditor openFileInTextEditor(String filename)
825 //                      throws CoreException {
826 //              // reject directories
827 //              if (new File(filename).isDirectory())
828 //                      return null;
829 //              IWorkbench workbench = PlatformUI.getWorkbench();
830 //              IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
831 //              IWorkbenchPage page = window.getActivePage();
832 //              IPath path = new Path(filename);
833 //              // If the file exists in the workspace, open it
834 //              IFile file = getWorkspace().getRoot().getFile(path);
835 //              IEditorPart editor;
836 //              ITextEditor textEditor;
837 //              if (file != null && file.exists()) {
838 //                      editor = IDE.openEditor(page, file, true);
839 //                      textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
840 //              } else {
841 //                      // Otherwise open the stream directly
842 //                      if (page == null)
843 //                              return null;
844 //                      FileStorage storage = new FileStorage(path);
845 //                      IEditorRegistry registry = getWorkbench().getEditorRegistry();
846 //                      IEditorDescriptor desc = registry.getDefaultEditor(filename);
847 //                      if (desc == null) {
848 //                              desc = registry
849 //                                              .findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
850 //                              // desc = registry.getDefaultEditor();
851 //                      }
852 //                      IEditorInput input = new ExternalEditorInput(storage);
853 //                      editor = page.openEditor(input, desc.getId());
854 //                      textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
855 //                      // If the storage provider is not ours, we can't guarantee
856 //                      // read/write.
857 //                      if (textEditor != null) {
858 //                              IDocumentProvider documentProvider = textEditor
859 //                                              .getDocumentProvider();
860 //                              if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
861 //                                      storage.setReadOnly();
862 //                              }
863 //                      }
864 //              }
865 //              return textEditor;
866 //      }
867
868         /**
869          * Open a file in the Workbench that may or may not exist in the workspace.
870          * Must be run on the UI thread.
871          * 
872          * @param filename
873          * @param line
874          * @throws CoreException
875          */
876 //      public void openFileAndGotoLine(String filename, int line)
877 //                      throws CoreException {
878 //              ITextEditor textEditor = openFileInTextEditor(filename);
879 //              if (textEditor != null) {
880 //                      // If a line number was given, go to it
881 //                      if (line > 0) {
882 //                              try {
883 //                                      line--; // document is 0 based
884 //                                      IDocument document = textEditor.getDocumentProvider()
885 //                                                      .getDocument(textEditor.getEditorInput());
886 //                                      textEditor.selectAndReveal(document.getLineOffset(line),
887 //                                                      document.getLineLength(line));
888 //                              } catch (BadLocationException e) {
889 //                                      // invalid text position -> do nothing
890 //                              }
891 //                      }
892 //              }
893 //      }
894
895         /**
896          * Open a file in the Workbench that may or may not exist in the workspace.
897          * Must be run on the UI thread.
898          * 
899          * @param filename
900          * @param offset
901          * @throws CoreException
902          */
903 //      public void openFileAndGotoOffset(String filename, int offset, int length)
904 //                      throws CoreException {
905 //              ITextEditor textEditor = openFileInTextEditor(filename);
906 //              if (textEditor != null) {
907 //                      // If a line number was given, go to it
908 //                      if (offset >= 0) {
909 //                              IDocument document = textEditor.getDocumentProvider()
910 //                                              .getDocument(textEditor.getEditorInput());
911 //                              textEditor.selectAndReveal(offset, length);
912 //                      }
913 //              }
914 //      }
915 //
916 //      public void openFileAndFindString(String filename, String findString)
917 //                      throws CoreException {
918 //              ITextEditor textEditor = openFileInTextEditor(filename);
919 //              if (textEditor != null) {
920 //                      // If a string was given, go to it
921 //                      if (findString != null) {
922 //                              try {
923 //                                      IDocument document = textEditor.getDocumentProvider()
924 //                                                      .getDocument(textEditor.getEditorInput());
925 //                                      int offset = document.search(0, findString, true, false,
926 //                                                      true);
927 //                                      textEditor.selectAndReveal(offset, findString.length());
928 //                              } catch (BadLocationException e) {
929 //                                      // invalid text position -> do nothing
930 //                              }
931 //                      }
932 //              }
933 //      }
934
935         public void setLastEditorFile(IFile textEditor) {
936                 this.fLastEditorFile = textEditor;
937         }
938
939         /*
940          * @see org.eclipse.core.runtime.Plugin#stop
941          */
942 //      public void stop(BundleContext context) throws Exception {
943 //              try {
944 //                      // JavaCore.stop(this, context);
945 //                      plugin.savePluginPreferences();
946 //                      IWorkspace workspace = ResourcesPlugin.getWorkspace();
947 //                      workspace.removeResourceChangeListener(JavaModelManager
948 //                                      .getJavaModelManager().deltaState);
949 //                      workspace.removeSaveParticipant(plugin);
950 //
951 //                      JavaModelManager.getJavaModelManager().shutdown();
952 //
953 //                      // save the information from the php index files if necessary
954 //                      Collection collection = fIndexManagerMap.values();
955 //                      Iterator iterator = collection.iterator();
956 //                      IdentifierIndexManager indexManager = null;
957 //                      while (iterator.hasNext()) {
958 //                              indexManager = (IdentifierIndexManager) iterator.next();
959 //                              indexManager.writeFile();
960 //                      }
961 //                      if (fImageDescriptorRegistry != null)
962 //                              fImageDescriptorRegistry.dispose();
963 //
964 //                      // AllTypesCache.terminate();
965 //
966 //                      if (fImageDescriptorRegistry != null)
967 //                              fImageDescriptorRegistry.dispose();
968 //
969 //                      unregisterAdapters();
970 //
971 //                      // if (fASTProvider != null) {
972 //                      // fASTProvider.dispose();
973 //                      // fASTProvider= null;
974 //                      // }
975 //
976 //                      if (fWorkingCopyManager != null) {
977 //                              fWorkingCopyManager.shutdown();
978 //                              fWorkingCopyManager = null;
979 //                      }
980 //
981 //                      if (fCompilationUnitDocumentProvider != null) {
982 //                              fCompilationUnitDocumentProvider.shutdown();
983 //                              fCompilationUnitDocumentProvider = null;
984 //                      }
985 //
986 //                      if (fJavaTextTools != null) {
987 //                              fJavaTextTools.dispose();
988 //                              fJavaTextTools = null;
989 //                      }
990 //                      // JavaDocLocations.shutdownJavadocLocations();
991 //
992 //                      uninstallPreferenceStoreBackwardsCompatibility();
993 //
994 //                      // RefactoringCore.getUndoManager().shutdown();
995 //              } finally {
996 //                      super.stop(context);
997 //              }
998 //      }
999
1000         /**
1001          * Installs backwards compatibility for the preference store.
1002          */
1003 //      private void installPreferenceStoreBackwardsCompatibility() {
1004 //
1005 //              /*
1006 //               * Installs backwards compatibility: propagate the Java editor font from
1007 //               * a pre-2.1 plug-in to the Platform UI's preference store to preserve
1008 //               * the Java editor font from a pre-2.1 workspace. This is done only
1009 //               * once.
1010 //               */
1011 //              String fontPropagatedKey = "fontPropagated"; //$NON-NLS-1$
1012 //              if (getPreferenceStore().contains(JFaceResources.TEXT_FONT)
1013 //                              && !getPreferenceStore().isDefault(JFaceResources.TEXT_FONT)) {
1014 //                      if (!getPreferenceStore().getBoolean(fontPropagatedKey))
1015 //                              PreferenceConverter
1016 //                                              .setValue(PlatformUI.getWorkbench()
1017 //                                                              .getPreferenceStore(),
1018 //                                                              PreferenceConstants.EDITOR_TEXT_FONT,
1019 //                                                              PreferenceConverter.getFontDataArray(
1020 //                                                                              getPreferenceStore(),
1021 //                                                                              JFaceResources.TEXT_FONT));
1022 //              }
1023 //              getPreferenceStore().setValue(fontPropagatedKey, true);
1024 //
1025 //              /*
1026 //               * Backwards compatibility: set the Java editor font in this plug-in's
1027 //               * preference store to let older versions access it. Since 2.1 the Java
1028 //               * editor font is managed by the workbench font preference page.
1029 //               */
1030 //              PreferenceConverter.putValue(getPreferenceStore(),
1031 //                              JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry()
1032 //                                              .getFontData(PreferenceConstants.EDITOR_TEXT_FONT));
1033 //
1034 //              fFontPropertyChangeListener = new IPropertyChangeListener() {
1035 //                      public void propertyChange(PropertyChangeEvent event) {
1036 //                              if (PreferenceConstants.EDITOR_TEXT_FONT.equals(event
1037 //                                              .getProperty()))
1038 //                                      PreferenceConverter.putValue(getPreferenceStore(),
1039 //                                                      JFaceResources.TEXT_FONT,
1040 //                                                      JFaceResources.getFontRegistry().getFontData(
1041 //                                                                      PreferenceConstants.EDITOR_TEXT_FONT));
1042 //                      }
1043 //              };
1044 //              JFaceResources.getFontRegistry().addListener(
1045 //                              fFontPropertyChangeListener);
1046 //      }
1047
1048         /**
1049          * Uninstalls backwards compatibility for the preference store.
1050          */
1051 //      private void uninstallPreferenceStoreBackwardsCompatibility() {
1052 //              JFaceResources.getFontRegistry().removeListener(
1053 //                              fFontPropertyChangeListener);
1054 //              // getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
1055 //      }
1056
1057         /*
1058          * (non - Javadoc) Method declared in Plugin
1059          */
1060 //      public void start(BundleContext context) throws Exception {
1061 //              super.start(context);
1062 //
1063 //              // JavaCore.start(this, context);
1064 //              final JavaModelManager modelManager = JavaModelManager
1065 //                              .getJavaModelManager();
1066 //              try {
1067 //                      modelManager.configurePluginDebugOptions();
1068 //
1069 //                      // request state folder creation (workaround 19885)
1070 //                      getStateLocation();
1071 //                      // retrieve variable values
1072 //                      PHPeclipsePlugin.getDefault().getPluginPreferences()
1073 //                                      .addPropertyChangeListener(
1074 //                                                      new JavaModelManager.PluginPreferencesListener());
1075 //                      // manager.loadVariablesAndContainers();
1076 //
1077 //                      final IWorkspace workspace = ResourcesPlugin.getWorkspace();
1078 //                      workspace.addResourceChangeListener(modelManager.deltaState,
1079 //                                      IResourceChangeEvent.PRE_BUILD
1080 //                                                      | IResourceChangeEvent.POST_BUILD
1081 //                                                      | IResourceChangeEvent.POST_CHANGE
1082 //                                                      | IResourceChangeEvent.PRE_DELETE
1083 //                                                      | IResourceChangeEvent.PRE_CLOSE);
1084 //
1085 //                      ISavedState savedState = workspace.addSaveParticipant(
1086 //                                      PHPeclipsePlugin.this, modelManager);
1087 //
1088 //                      // process deltas since last activated in indexer thread so that
1089 //                      // indexes are up-to-date.
1090 //                      // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658
1091 //// This causes timeout at EclipseLazyStarter
1092 ////                    Job processSavedState = new Job(Util.bind("savedState.jobName")) { //$NON-NLS-1$
1093 ////                            protected IStatus run(IProgressMonitor monitor) {
1094 ////                                    try {
1095 ////                                            // add save participant and process delta atomically
1096 ////                                            // see
1097 ////                                            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=59937
1098 ////                                            workspace.run(new IWorkspaceRunnable() {
1099 ////                                                    public void run(IProgressMonitor progress)
1100 ////                                                                    throws CoreException {
1101 ////                                                            ISavedState savedState = workspace
1102 ////                                                                            .addSaveParticipant(
1103 ////                                                                                            PHPeclipsePlugin.this,
1104 ////                                                                                            modelManager);
1105 ////                                                            if (savedState != null) {
1106 ////                                                                    // the event type coming from the saved
1107 ////                                                                    // state is always POST_AUTO_BUILD
1108 ////                                                                    // force it to be POST_CHANGE so that the
1109 ////                                                                    // delta processor can handle it
1110 ////                                                                    modelManager.deltaState.getDeltaProcessor().overridenEventType = IResourceChangeEvent.POST_CHANGE;
1111 ////                                                                    savedState
1112 ////                                                                                    .processResourceChangeEvents(modelManager.deltaState);
1113 ////                                                            }
1114 ////                                                    }
1115 ////                                            }, monitor);
1116 ////                                    } catch (CoreException e) {
1117 ////                                            return e.getStatus();
1118 ////                                    }
1119 ////                                    return Status.OK_STATUS;
1120 ////                            }
1121 ////                    };
1122 //// Replace Job + IWorkspace.run() to WorkspaceJob
1123 //                      WorkspaceJob processSavedState = new WorkspaceJob(
1124 //                                      Util.bind("savedState.jobName")) { //$NON-NLS-1$
1125 //                              public IStatus runInWorkspace(IProgressMonitor monitor)
1126 //                                              throws CoreException {
1127 //                                      ISavedState savedState = workspace.addSaveParticipant(
1128 //                                                      PHPeclipsePlugin.this, modelManager);
1129 //                                      if (savedState != null) {
1130 //                                              modelManager.deltaState.getDeltaProcessor().overridenEventType
1131 //                                                              = IResourceChangeEvent.POST_CHANGE;
1132 //                                              savedState.processResourceChangeEvents(modelManager.deltaState);
1133 //                                      }
1134 //                                      return Status.OK_STATUS;
1135 //                              }
1136 //                      };
1137 //                      processSavedState.setSystem(true);
1138 //                      processSavedState.setPriority(Job.SHORT); // process asap
1139 //                      processSavedState.schedule();
1140 //              } catch (RuntimeException e) {
1141 //                      modelManager.shutdown();
1142 //                      throw e;
1143 //              }
1144 //
1145 //              registerAdapters();
1146 //
1147 //              // if (USE_WORKING_COPY_OWNERS) {
1148 //              WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
1149 //                      public IBuffer createBuffer(ICompilationUnit workingCopy) {
1150 //                              ICompilationUnit original = workingCopy.getPrimary();
1151 //                              IResource resource = original.getResource();
1152 //                              if (resource instanceof IFile)
1153 //                                      return new DocumentAdapter(workingCopy, (IFile) resource);
1154 //                              return DocumentAdapter.NULL;
1155 //                      }
1156 //              });
1157 //              // }
1158 //
1159 //              installPreferenceStoreBackwardsCompatibility();
1160 //
1161 //      }
1162 //
1163 //      private void registerAdapters() {
1164 //              fJavaElementAdapterFactory = new JavaElementAdapterFactory();
1165 //              fResourceAdapterFactory = new ResourceAdapterFactory();
1166 //
1167 //              IAdapterManager manager = Platform.getAdapterManager();
1168 //              manager
1169 //                              .registerAdapters(fJavaElementAdapterFactory,
1170 //                                              IJavaElement.class);
1171 //              manager.registerAdapters(fResourceAdapterFactory, IResource.class);
1172 //      }
1173
1174 //      private void unregisterAdapters() {
1175 //              IAdapterManager manager = Platform.getAdapterManager();
1176 //              manager.unregisterAdapters(fJavaElementAdapterFactory);
1177 //              manager.unregisterAdapters(fResourceAdapterFactory);
1178 //      }
1179
1180         /**
1181          * Returns a combined preference store, this store is read-only.
1182          * 
1183          * @return the combined preference store
1184          * 
1185          * @since 3.0
1186          */
1187 //      public IPreferenceStore getCombinedPreferenceStore() {
1188 //              if (fCombinedPreferenceStore == null) {
1189 //                      IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
1190 //                      fCombinedPreferenceStore = new ChainedPreferenceStore(
1191 //                                      new IPreferenceStore[] {
1192 //                                                      getPreferenceStore(),
1193 //                                                      new PreferencesAdapter(PHPeclipsePlugin
1194 //                                                                      .getDefault().getPluginPreferences()),
1195 //                                                      generalTextStore });
1196 //              }
1197 //              return fCombinedPreferenceStore;
1198 //      }
1199 //
1200         public synchronized IBufferFactory getBufferFactory() {
1201                 if (fBufferFactory == null)
1202                         fBufferFactory = new CustomBufferFactory();
1203                 return fBufferFactory;
1204         }
1205
1206         /**
1207          * Returns the registry of the extensions to the
1208          * <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code>
1209          * extension point.
1210          * 
1211          * @return the registry of contributed
1212          *         <code>IJavaFoldingStructureProvider</code>
1213          * @since 3.0
1214          */
1215 //      public synchronized JavaFoldingStructureProviderRegistry getFoldingStructureProviderRegistry() {
1216 //              if (fFoldingStructureProviderRegistry == null)
1217 //                      fFoldingStructureProviderRegistry = new JavaFoldingStructureProviderRegistry();
1218 //              return fFoldingStructureProviderRegistry;
1219 //      }
1220
1221         /**
1222          * Runs the given action as an atomic Java model operation.
1223          * <p>
1224          * After running a method that modifies java elements, registered listeners
1225          * receive after-the-fact notification of what just transpired, in the form
1226          * of a element changed event. This method allows clients to call a number
1227          * of methods that modify java elements and only have element changed event
1228          * notifications reported at the end of the entire batch.
1229          * </p>
1230          * <p>
1231          * If this method is called outside the dynamic scope of another such call,
1232          * this method runs the action and then reports a single element changed
1233          * event describing the net effect of all changes done to java elements by
1234          * the action.
1235          * </p>
1236          * <p>
1237          * If this method is called in the dynamic scope of another such call, this
1238          * method simply runs the action.
1239          * </p>
1240          * 
1241          * @param action
1242          *            the action to perform
1243          * @param monitor
1244          *            a progress monitor, or <code>null</code> if progress
1245          *            reporting and cancellation are not desired
1246          * @exception CoreException
1247          *                if the operation failed.
1248          * @since 2.1
1249          */
1250         public static void run(IWorkspaceRunnable action, IProgressMonitor monitor)
1251                         throws CoreException {
1252                 run(action, ResourcesPlugin.getWorkspace().getRoot(), monitor);
1253         }
1254
1255         /**
1256          * Runs the given action as an atomic Java model operation.
1257          * <p>
1258          * After running a method that modifies java elements, registered listeners
1259          * receive after-the-fact notification of what just transpired, in the form
1260          * of a element changed event. This method allows clients to call a number
1261          * of methods that modify java elements and only have element changed event
1262          * notifications reported at the end of the entire batch.
1263          * </p>
1264          * <p>
1265          * If this method is called outside the dynamic scope of another such call,
1266          * this method runs the action and then reports a single element changed
1267          * event describing the net effect of all changes done to java elements by
1268          * the action.
1269          * </p>
1270          * <p>
1271          * If this method is called in the dynamic scope of another such call, this
1272          * method simply runs the action.
1273          * </p>
1274          * <p>
1275          * The supplied scheduling rule is used to determine whether this operation
1276          * can be run simultaneously with workspace changes in other threads. See
1277          * <code>IWorkspace.run(...)</code> for more details.
1278          * </p>
1279          * 
1280          * @param action
1281          *            the action to perform
1282          * @param rule
1283          *            the scheduling rule to use when running this operation, or
1284          *            <code>null</code> if there are no scheduling restrictions
1285          *            for this operation.
1286          * @param monitor
1287          *            a progress monitor, or <code>null</code> if progress
1288          *            reporting and cancellation are not desired
1289          * @exception CoreException
1290          *                if the operation failed.
1291          * @since 3.0
1292          */
1293         public static void run(IWorkspaceRunnable action, ISchedulingRule rule,
1294                         IProgressMonitor monitor) throws CoreException {
1295                 IWorkspace workspace = ResourcesPlugin.getWorkspace();
1296                 if (workspace.isTreeLocked()) {
1297                         new BatchOperation(action).run(monitor);
1298                 } else {
1299                         // use IWorkspace.run(...) to ensure that a build will be done in
1300                         // autobuild mode
1301                         workspace.run(new BatchOperation(action), rule,
1302                                         IWorkspace.AVOID_UPDATE, monitor);
1303                 }
1304         }
1305
1306         /**
1307          * Returns the template context type registry for the java plugin.
1308          * 
1309          * @return the template context type registry for the java plugin
1310          * @since 3.0
1311          */
1312 //      public ContextTypeRegistry getTemplateContextRegistry() {
1313 //              if (fContextTypeRegistry == null) {
1314 //                      fContextTypeRegistry = new ContributionContextTypeRegistry();
1315 //
1316 //                      fContextTypeRegistry.addContextType(new JavaContextType());
1317 //                      fContextTypeRegistry.addContextType(new JavaDocContextType());
1318 //                      fContextTypeRegistry.addContextType(new HTMLContextType());
1319 //              }
1320 //
1321 //              return fContextTypeRegistry;
1322 //      }
1323
1324         /**
1325          * Returns the template store for the java editor templates.
1326          * 
1327          * @return the template store for the java editor templates
1328          * @since 3.0
1329          */
1330 //      public TemplateStore getTemplateStore() {
1331 //              if (fTemplateStore == null) {
1332 //                      fTemplateStore = new ContributionTemplateStore(
1333 //                                      getTemplateContextRegistry(), getPreferenceStore(),
1334 //                                      TEMPLATES_KEY);
1335 //                      try {
1336 //                              fTemplateStore.load();
1337 //                      } catch (IOException e) {
1338 //                              log(e);
1339 //                      }
1340 //              }
1341 //
1342 //              return fTemplateStore;
1343 //      }
1344
1345         /**
1346          * Returns the template context type registry for the code generation
1347          * templates.
1348          * 
1349          * @return the template context type registry for the code generation
1350          *         templates
1351          * @since 3.0
1352          */
1353 //      public ContextTypeRegistry getCodeTemplateContextRegistry() {
1354 //              if (fCodeTemplateContextTypeRegistry == null) {
1355 //                      fCodeTemplateContextTypeRegistry = new ContributionContextTypeRegistry();
1356 //
1357 //                      CodeTemplateContextType
1358 //                                      .registerContextTypes(fCodeTemplateContextTypeRegistry);
1359 //              }
1360 //
1361 //              return fCodeTemplateContextTypeRegistry;
1362 //      }
1363
1364         /**
1365          * Returns the template store for the code generation templates.
1366          * 
1367          * @return the template store for the code generation templates
1368          * @since 3.0
1369          */
1370 //      public TemplateStore getCodeTemplateStore() {
1371 //              if (fCodeTemplateStore == null) {
1372 //                      fCodeTemplateStore = new ContributionTemplateStore(
1373 //                                      getCodeTemplateContextRegistry(), getPreferenceStore(),
1374 //                                      CODE_TEMPLATES_KEY);
1375 //                      try {
1376 //                              fCodeTemplateStore.load();
1377 //                      } catch (IOException e) {
1378 //                              log(e);
1379 //                      }
1380 //              }
1381 //
1382 //              return fCodeTemplateStore;
1383 //      }
1384 }