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
8 **********************************************************************/
9 package net.sourceforge.phpeclipse;
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;
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.externaltools.internal.model.ColorManager;
31 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsPlugin;
32 import net.sourceforge.phpdt.internal.core.BatchOperation;
33 import net.sourceforge.phpdt.internal.core.JavaModelManager;
34 import net.sourceforge.phpdt.internal.core.util.Util;
35 import net.sourceforge.phpdt.internal.corext.template.php.CodeTemplateContextType;
36 import net.sourceforge.phpdt.internal.corext.template.php.HTMLContextType;
37 import net.sourceforge.phpdt.internal.corext.template.php.JavaContextType;
38 import net.sourceforge.phpdt.internal.corext.template.php.JavaDocContextType;
39 import net.sourceforge.phpdt.internal.ui.IJavaStatusConstants;
40 import net.sourceforge.phpdt.internal.ui.JavaElementAdapterFactory;
41 import net.sourceforge.phpdt.internal.ui.ResourceAdapterFactory;
42 import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache;
43 import net.sourceforge.phpdt.internal.ui.preferences.MockupPreferenceStore;
44 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
45 import net.sourceforge.phpdt.internal.ui.text.folding.JavaFoldingStructureProviderRegistry;
46 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
47 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
48 import net.sourceforge.phpdt.internal.ui.viewsupport.ProblemMarkerManager;
49 import net.sourceforge.phpdt.ui.IContextMenuConstants;
50 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
51 import net.sourceforge.phpdt.ui.PreferenceConstants;
52 import net.sourceforge.phpdt.ui.text.JavaTextTools;
53 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
54 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
55 import net.sourceforge.phpeclipse.builder.FileStorage;
56 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
57 import net.sourceforge.phpeclipse.phpeditor.CustomBufferFactory;
58 import net.sourceforge.phpeclipse.phpeditor.DocumentAdapter;
59 import net.sourceforge.phpeclipse.phpeditor.ICompilationUnitDocumentProvider;
60 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
61 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
62 import net.sourceforge.phpeclipse.phpeditor.WorkingCopyManager;
63 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
65 import org.eclipse.core.resources.IFile;
66 import org.eclipse.core.resources.IProject;
67 import org.eclipse.core.resources.IResource;
68 import org.eclipse.core.resources.IResourceChangeEvent;
69 import org.eclipse.core.resources.ISavedState;
70 import org.eclipse.core.resources.IWorkspace;
71 import org.eclipse.core.resources.IWorkspaceRunnable;
72 import org.eclipse.core.resources.ResourcesPlugin;
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.IPluginDescriptor;
78 import org.eclipse.core.runtime.IProgressMonitor;
79 import org.eclipse.core.runtime.IStatus;
80 import org.eclipse.core.runtime.Path;
81 import org.eclipse.core.runtime.Platform;
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.action.GroupMarker;
86 import org.eclipse.jface.action.IMenuManager;
87 import org.eclipse.jface.action.Separator;
88 import org.eclipse.jface.preference.IPreferenceStore;
89 import org.eclipse.jface.preference.PreferenceConverter;
90 import org.eclipse.jface.resource.JFaceResources;
91 import org.eclipse.jface.text.BadLocationException;
92 import org.eclipse.jface.text.IDocument;
93 import org.eclipse.jface.text.templates.ContextTypeRegistry;
94 import org.eclipse.jface.text.templates.persistence.TemplateStore;
95 import org.eclipse.jface.util.IPropertyChangeListener;
96 import org.eclipse.jface.util.PropertyChangeEvent;
97 import org.eclipse.swt.graphics.RGB;
98 import org.eclipse.swt.widgets.Display;
99 import org.eclipse.swt.widgets.Shell;
100 import org.eclipse.ui.IEditorDescriptor;
101 import org.eclipse.ui.IEditorInput;
102 import org.eclipse.ui.IEditorPart;
103 import org.eclipse.ui.IEditorRegistry;
104 import org.eclipse.ui.IWorkbench;
105 import org.eclipse.ui.IWorkbenchPage;
106 import org.eclipse.ui.IWorkbenchWindow;
107 import org.eclipse.ui.PlatformUI;
108 import org.eclipse.ui.editors.text.EditorsUI;
109 import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
110 import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
111 import org.eclipse.ui.ide.IDE;
112 import org.eclipse.ui.plugin.AbstractUIPlugin;
113 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
114 import org.eclipse.ui.texteditor.ConfigurationElementSorter;
115 import org.eclipse.ui.texteditor.IDocumentProvider;
116 import org.eclipse.ui.texteditor.ITextEditor;
117 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
118 import org.osgi.framework.BundleContext;
121 * The main plugin class to be used in the desktop.
123 public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceConstants {
125 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
127 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
132 * id of builder - matches plugin.xml (concatenate pluginid.builderid)
134 public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
136 //public static final String BUILDER_INDEX_ID = PLUGIN_ID + ".indexbuilder";
137 /** General debug flag */
139 public static final boolean DEBUG = false;
142 * The maximum number of allowed proposals by category
144 public final static int MAX_PROPOSALS = 200;
147 * The key to store customized templates.
151 private static final String TEMPLATES_KEY = "net.sourceforge.phpdt.ui.text.custom_templates"; //$NON-NLS-1$
154 * The key to store customized code templates.
158 private static final String CODE_TEMPLATES_KEY = "net.sourceforge.phpdt.ui.text.custom_code_templates"; //$NON-NLS-1$
161 * The key to store whether the legacy templates have been migrated
165 // private static final String TEMPLATES_MIGRATION_KEY= "net.sourceforge.phpdt.ui.text.templates_migrated"; //$NON-NLS-1$
167 * The key to store whether the legacy code templates have been migrated
171 // private static final String CODE_TEMPLATES_MIGRATION_KEY= "net.sourceforge.phpdt.ui.text.code_templates_migrated";
173 private static ExternalToolsPlugin externalTools;
176 * The Java virtual machine that we are running on.
178 // private static int jvm;
180 // private static final int MRJ_2_0 = 0;
182 // /** MRJ 2.1 or later */
183 // private static final int MRJ_2_1 = 1;
185 // /** Java on Mac OS X 10.0 (MRJ 3.0) */
186 // private static final int MRJ_3_0 = 3;
189 // private static final int MRJ_3_1 = 4;
191 // /** JVM constant for any other platform */
192 // private static final int OTHER = -1;
193 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID +
194 // ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
195 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID + ".ui.CodingActionSet"; //$NON-NLS-1$
197 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
199 public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
201 public static final String PHPPARSER_NEW = "test.PHPParser";
203 /** Change this if you want to switch PHP Parser. */
204 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
206 //The shared instance.
207 private static PHPeclipsePlugin plugin;
210 * The template context type registry for the java editor.
214 private ContextTypeRegistry fContextTypeRegistry;
217 * The code template context type registry for the java editor.
221 private ContextTypeRegistry fCodeTemplateContextTypeRegistry;
224 * The template store for the java editor.
228 private TemplateStore fTemplateStore;
231 * The coded template store for the java editor.
235 private TemplateStore fCodeTemplateStore;
238 private static final int WINDOWS_9x = 6;
241 private static final int WINDOWS_NT = 5;
243 private ImageDescriptorRegistry fImageDescriptorRegistry;
245 private HashMap fIndexManagerMap = new HashMap();
247 private IWorkingCopyManager fWorkingCopyManager;
249 private IBufferFactory fBufferFactory;
251 private ICompilationUnitDocumentProvider fCompilationUnitDocumentProvider;
253 private JavaTextTools fJavaTextTools;
255 private ProblemMarkerManager fProblemMarkerManager;
257 private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
259 private IFile fLastEditorFile = null;
261 private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
263 private JavaElementAdapterFactory fJavaElementAdapterFactory;
265 // private MarkerAdapterFactory fMarkerAdapterFactory;
266 // private EditorInputAdapterFactory fEditorInputAdapterFactory;
267 private ResourceAdapterFactory fResourceAdapterFactory;
269 // private LogicalPackageAdapterFactory fLogicalPackageAdapterFactory;
270 private IPropertyChangeListener fFontPropertyChangeListener;
273 * Property change listener on this plugin's preference store.
277 // private IPropertyChangeListener fPropertyChangeListener;
279 * The combined preference store.
283 private IPreferenceStore fCombinedPreferenceStore;
286 * The extension point registry for the <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code> extension point.
290 private JavaFoldingStructureProviderRegistry fFoldingStructureProviderRegistry;
293 * Mockup preference store for firing events and registering listeners on project setting changes. FIXME: Temporary solution.
297 private MockupPreferenceStore fMockupPreferenceStore;
302 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
305 externalTools = new ExternalToolsPlugin();
309 // ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
310 // } catch (MissingResourceException x) {
311 // resourceBundle = null;
316 // * Returns all Java editor text hovers contributed to the workbench.
318 // * @return an array of JavaEditorTextHoverDescriptor
321 // public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors()
323 // if (fJavaEditorTextHoverDescriptors == null)
324 // fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
325 // .getContributedHovers();
326 // return fJavaEditorTextHoverDescriptors;
329 * Returns all Java editor text hovers contributed to the workbench.
331 * @return an array of JavaEditorTextHoverDescriptor
334 public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
335 if (fJavaEditorTextHoverDescriptors == null) {
336 fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor.getContributedHovers();
337 ConfigurationElementSorter sorter = new ConfigurationElementSorter() {
339 * @see org.eclipse.ui.texteditor.ConfigurationElementSorter#getConfigurationElement(java.lang.Object)
341 public IConfigurationElement getConfigurationElement(Object object) {
342 return ((JavaEditorTextHoverDescriptor) object).getConfigurationElement();
345 sorter.sort(fJavaEditorTextHoverDescriptors);
347 // The Problem hover has to be the first and the Annotation hover has to
348 // be the last one in the JDT UI's hover list
349 int length = fJavaEditorTextHoverDescriptors.length;
351 int last = length - 1;
352 int problemHoverIndex = -1;
353 int annotationHoverIndex = -1;
354 for (int i = 0; i < length; i++) {
355 if (!fJavaEditorTextHoverDescriptors[i].getId().startsWith(PLUGIN_ID)) {
356 if (problemHoverIndex == -1 || annotationHoverIndex == -1)
366 if (fJavaEditorTextHoverDescriptors[i].getId().equals("net.sourceforge.phpdt.ui.AnnotationHover")) { //$NON-NLS-1$
367 annotationHoverIndex = i;
370 if (fJavaEditorTextHoverDescriptors[i].getId().equals("net.sourceforge.phpdt.ui.ProblemHover")) { //$NON-NLS-1$
371 problemHoverIndex = i;
376 JavaEditorTextHoverDescriptor hoverDescriptor = null;
378 if (first > -1 && problemHoverIndex > -1 && problemHoverIndex != first) {
379 // move problem hover to beginning
380 hoverDescriptor = fJavaEditorTextHoverDescriptors[first];
381 fJavaEditorTextHoverDescriptors[first] = fJavaEditorTextHoverDescriptors[problemHoverIndex];
382 fJavaEditorTextHoverDescriptors[problemHoverIndex] = hoverDescriptor;
384 // update annotation hover index if needed
385 if (annotationHoverIndex == first)
386 annotationHoverIndex = problemHoverIndex;
389 if (annotationHoverIndex > -1 && annotationHoverIndex != last) {
390 // move annotation hover to end
391 hoverDescriptor = fJavaEditorTextHoverDescriptors[last];
392 fJavaEditorTextHoverDescriptors[last] = fJavaEditorTextHoverDescriptors[annotationHoverIndex];
393 fJavaEditorTextHoverDescriptors[annotationHoverIndex] = hoverDescriptor;
396 // Move Best Match hover to front
397 for (int i = 0; i < fJavaEditorTextHoverDescriptors.length - 1; i++) {
398 if (PreferenceConstants.ID_BESTMATCH_HOVER.equals(fJavaEditorTextHoverDescriptors[i].getId())) {
399 hoverDescriptor = fJavaEditorTextHoverDescriptors[i];
400 for (int j = i; j > 0; j--)
401 fJavaEditorTextHoverDescriptors[j] = fJavaEditorTextHoverDescriptors[j - 1];
402 fJavaEditorTextHoverDescriptors[0] = hoverDescriptor;
409 return fJavaEditorTextHoverDescriptors;
413 * Resets the Java editor text hovers contributed to the workbench.
415 * This will force a rebuild of the descriptors the next time a client asks for them.
418 * @return an array of JavaEditorTextHoverDescriptor
421 public void resetJavaEditorTextHoverDescriptors() {
422 fJavaEditorTextHoverDescriptors = null;
426 * Creates the PHP plugin standard groups in a context menu.
428 public static void createStandardGroups(IMenuManager menu) {
431 menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
432 menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
433 menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
434 menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
435 menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
436 menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
437 menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
438 menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
439 menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
440 menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
441 menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
444 public static IWorkbenchPage getActivePage() {
445 return getDefault().internalGetActivePage();
448 public static Shell getActiveWorkbenchShell() {
449 return getActiveWorkbenchWindow().getShell();
453 * Returns an array of all editors that have an unsaved content. If the identical content is presented in more than one editor,
454 * only one of those editor parts is part of the result.
456 * @return an array of all dirty editor parts.
458 public static IEditorPart[] getDirtyEditors() {
459 Set inputs = new HashSet();
460 List result = new ArrayList(0);
461 IWorkbench workbench = getDefault().getWorkbench();
462 IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
463 for (int i = 0; i < windows.length; i++) {
464 IWorkbenchPage[] pages = windows[i].getPages();
465 for (int x = 0; x < pages.length; x++) {
466 IEditorPart[] editors = pages[x].getDirtyEditors();
467 for (int z = 0; z < editors.length; z++) {
468 IEditorPart ep = editors[z];
469 IEditorInput input = ep.getEditorInput();
470 if (!inputs.contains(input)) {
477 return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]);
480 public static IWorkbenchWindow getActiveWorkbenchWindow() {
481 return getDefault().getWorkbench().getActiveWorkbenchWindow();
485 * Returns the shared instance.
487 public static PHPeclipsePlugin getDefault() {
491 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
492 return getDefault().internalGetImageDescriptorRegistry();
495 static IPath getInstallLocation() {
496 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
499 // public static int getJVM() {
503 public static String getPluginId() {
504 return getDefault().getDescriptor().getUniqueIdentifier();
508 * Returns the standard display to be used. The method first checks, if the thread calling this method has an associated display.
509 * If so, this display is returned. Otherwise the method returns the default display.
511 public static Display getStandardDisplay() {
512 Display display = Display.getCurrent();
513 if (display == null) {
514 display = Display.getDefault();
519 // public static ExternalToolsPlugin getExternalTools() {
520 // return externalTools;
523 * Returns the workspace instance.
525 public static IWorkspace getWorkspace() {
526 return ResourcesPlugin.getWorkspace();
529 public static boolean isDebug() {
530 return getDefault().isDebugging();
533 // public static void logErrorMessage(String message) {
534 // log(new Status(IStatus.ERROR, getPluginId(),
535 // JavaStatusConstants.INTERNAL_ERROR, message, null));
538 // public static void logErrorStatus(String message, IStatus status) {
539 // if (status == null) {
540 // logErrorMessage(message);
543 // MultiStatus multi= new MultiStatus(getPluginId(),
544 // JavaStatusConstants.INTERNAL_ERROR, message, null);
545 // multi.add(status);
549 // public static void log(Throwable e) {
550 // log(new Status(IStatus.ERROR, getPluginId(),
551 // JavaStatusConstants.INTERNAL_ERROR,
552 // JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
554 public static void log(int severity, String message) {
555 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
559 public static void log(IStatus status) {
560 getDefault().getLog().log(status);
563 public static void log(Throwable e) {
564 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
567 public static void logErrorMessage(String message) {
568 log(new Status(IStatus.ERROR, getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, null));
571 // private static void setJVM() {
572 // String osName = System.getProperty("os.name");
573 // if (osName.startsWith("Mac OS")) {
574 // String mrjVersion = System.getProperty("mrj.version");
575 // String majorMRJVersion = mrjVersion.substring(0, 3);
578 // double version = Double.valueOf(majorMRJVersion).doubleValue();
579 // if (version == 2) {
581 // } else if (version >= 2.1 && version < 3) {
583 // } else if (version == 3.0) {
585 // } else if (version >= 3.1) {
588 // } catch (NumberFormatException nfe) {
590 // } else if (osName.startsWith("Windows")) {
591 // if (osName.indexOf("9") != -1) {
599 // TODO: refactor this into a better method name !
600 public synchronized ICompilationUnitDocumentProvider getCompilationUnitDocumentProvider() {
601 if (fCompilationUnitDocumentProvider == null)
602 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
603 return fCompilationUnitDocumentProvider;
607 * Get the identifier index manager for the given project
610 * the current project
613 public IdentifierIndexManager getIndexManager(IProject iProject) {
614 IPath path = iProject.getWorkingLocation(PHPeclipsePlugin.PLUGIN_ID);
615 path = path.append("project.index");
616 String indexFilename = path.toString();
617 // System.out.println(indexFilename);
618 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap.get(indexFilename);
619 if (indexManager == null) {
620 indexManager = new IdentifierIndexManager(indexFilename);
621 fIndexManagerMap.put(indexFilename, indexManager);
626 public synchronized IWorkingCopyManager getWorkingCopyManager() {
627 if (fWorkingCopyManager == null) {
628 ICompilationUnitDocumentProvider provider = getCompilationUnitDocumentProvider();
629 fWorkingCopyManager = new WorkingCopyManager(provider);
631 return fWorkingCopyManager;
634 public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
635 if (fMembersOrderPreferenceCache == null)
636 fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
637 return fMembersOrderPreferenceCache;
641 * Returns the mockup preference store for firing events and registering listeners on project setting changes. Temporary solution.
643 public MockupPreferenceStore getMockupPreferenceStore() {
644 if (fMockupPreferenceStore == null)
645 fMockupPreferenceStore = new MockupPreferenceStore();
647 return fMockupPreferenceStore;
650 public synchronized ProblemMarkerManager getProblemMarkerManager() {
651 if (fProblemMarkerManager == null)
652 fProblemMarkerManager = new ProblemMarkerManager();
653 return fProblemMarkerManager;
656 // public synchronized JavaTextTools getJavaTextTools() {
657 // if (fJavaTextTools == null)
658 // fJavaTextTools = new JavaTextTools(getPreferenceStore());
659 // return fJavaTextTools;
661 public synchronized JavaTextTools getJavaTextTools() {
662 if (fJavaTextTools == null)
663 fJavaTextTools = new JavaTextTools(getPreferenceStore(), JavaCore.getPlugin().getPluginPreferences());
664 return fJavaTextTools;
667 public IFile getLastEditorFile() {
668 return fLastEditorFile;
672 * Returns the string from the plugin's resource bundle, or 'key' if not found.
674 // public static String getResourceString(String key) {
675 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
677 // return bundle.getString(key);
678 // } catch (MissingResourceException e) {
683 * Returns the plugin's resource bundle,
685 // public ResourceBundle getResourceBundle() {
686 // return resourceBundle;
688 protected void initializeDefaultPreferences(IPreferenceStore store) {
689 String operatingSystem = Platform.getOS();
690 // maxosx, linux, solaris, win32,...
692 InputStream is = getDefault().openStream(new Path("prefs/default_" + operatingSystem + ".properties"));
693 PropertyResourceBundle resourceBundle = new PropertyResourceBundle(is);
694 Enumeration enum = resourceBundle.getKeys();
696 while (enum.hasMoreElements()) {
697 key = (String)enum.nextElement();
698 store.setDefault(key, resourceBundle.getString( key ));
700 // store.setDefault(PHP_RUN_PREF, resourceBundle.getString(PHP_RUN_PREF));
701 // store.setDefault(EXTERNAL_PARSER_PREF, resourceBundle.getString(EXTERNAL_PARSER_PREF));
702 // store.setDefault(MYSQL_RUN_PREF, resourceBundle.getString(MYSQL_RUN_PREF));
703 // store.setDefault(APACHE_RUN_PREF, resourceBundle.getString(APACHE_RUN_PREF));
705 // store.setDefault(MYSQL_PREF, resourceBundle.getString(MYSQL_PREF));
706 // store.setDefault(APACHE_START_PREF, resourceBundle.getString(APACHE_START_PREF));
707 // store.setDefault(APACHE_STOP_PREF, resourceBundle.getString(APACHE_STOP_PREF));
708 // store.setDefault(APACHE_RESTART_PREF, resourceBundle.getString(APACHE_RESTART_PREF));
709 // store.setDefault(MYSQL_START_BACKGROUND, resourceBundle.getString(MYSQL_START_BACKGROUND));
710 // store.setDefault(APACHE_START_BACKGROUND, resourceBundle.getString(APACHE_START_BACKGROUND));
711 // store.setDefault(APACHE_STOP_BACKGROUND, resourceBundle.getString(APACHE_STOP_BACKGROUND));
712 // store.setDefault(APACHE_RESTART_BACKGROUND, resourceBundle.getString(APACHE_RESTART_BACKGROUND));
713 } catch (Exception e) {
714 // no default properties found
715 if (operatingSystem.equals(Platform.OS_WIN32)) {
716 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
717 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
718 store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
719 store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
721 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
722 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
723 store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
724 store.setDefault(APACHE_RUN_PREF, "/apache/apache");
726 store.setDefault(MYSQL_PREF, "--standalone");
727 store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
728 store.setDefault(APACHE_STOP_PREF, "-k shutdown");
729 store.setDefault(APACHE_RESTART_PREF, "-k restart");
730 store.setDefault(MYSQL_START_BACKGROUND, "true");
731 store.setDefault(APACHE_START_BACKGROUND, "true");
732 store.setDefault(APACHE_STOP_BACKGROUND, "true");
733 store.setDefault(APACHE_RESTART_BACKGROUND, "true");
736 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
737 store.setDefault(PHP_OBFUSCATOR_DEFAULT, "c:\\temp");
738 if (operatingSystem.equals(Platform.OS_WIN32)) {
739 // store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
740 } else if (operatingSystem.equals(Platform.OS_MACOSX)) {
741 store.setDefault(PHP_OBFUSCATOR_DEFAULT, "/tmp");
742 // TODO How do we start Safari on Mac OS X ?
743 // store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
745 store.setDefault(PHP_OBFUSCATOR_DEFAULT, "/tmp");
746 // store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
749 store.setDefault(PHP_EXTENSION_PREFS, "php,php3,php4,php5,phtml,inc,module,class");
751 // store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
752 // store.setDefault(PHP_INTERNAL_PARSER, "false");
753 // store.setDefault(PHP_EXTERNAL_PARSER, "true");
754 // store.setDefault(PHP_PARSE_ON_SAVE, "true");
755 // show line numbers:
756 // store.setDefault(LINE_NUMBER_RULER, "false");
757 // store.setDefault(FORMATTER_TAB_SIZE, "4");
758 // php syntax highlighting
759 store.setDefault(PHP_USERDEF_XMLFILE, "");
760 //assume there is none chooA
761 PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT, PHPColorProvider.MULTI_LINE_COMMENT);
762 PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT, PHPColorProvider.SINGLE_LINE_COMMENT);
763 PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
764 PreferenceConverter.setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
765 PreferenceConverter.setDefault(store, PHP_VARIABLE, PHPColorProvider.VARIABLE);
766 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME, PHPColorProvider.FUNCTION_NAME);
767 PreferenceConverter.setDefault(store, PHP_CONSTANT, PHPColorProvider.CONSTANT);
768 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
769 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
770 PreferenceConverter.setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
771 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD, PHPColorProvider.PHPDOC_KEYWORD);
772 PreferenceConverter.setDefault(store, PHPDOC_TAG, PHPColorProvider.PHPDOC_TAG);
773 PreferenceConverter.setDefault(store, PHPDOC_LINK, PHPColorProvider.PHPDOC_LINK);
774 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT, PHPColorProvider.PHPDOC_DEFAULT);
776 PreferenceConverter.setDefault(store, EDITOR_PHP_KEYWORD_RETURN_COLOR, new RGB(127, 0, 85));
777 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_BOLD, true);
778 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_ITALIC, false);
780 PreferenceConverter.setDefault(store, EDITOR_PHP_OPERATOR_COLOR, new RGB(0, 0, 0));
781 store.setDefault(EDITOR_PHP_OPERATOR_BOLD, false);
782 store.setDefault(EDITOR_PHP_OPERATOR_ITALIC, false);
784 PreferenceConverter.setDefault(store, EDITOR_PHP_BRACE_OPERATOR_COLOR, new RGB(0, 0, 0));
785 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_BOLD, false);
786 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_ITALIC, false);
787 // PreferenceConverter.setDefault(
789 // PHP_EDITOR_BACKGROUND,
790 // PHPColorProvider.BACKGROUND);
791 // PreferenceConverter.setDefault(
793 // LINKED_POSITION_COLOR,
794 // PHPColorProvider.LINKED_POSITION_COLOR);
795 // PreferenceConverter.setDefault(
797 // LINE_NUMBER_COLOR,
798 // PHPColorProvider.LINE_NUMBER_COLOR);
799 // // set default PHPDoc colors:
800 // PreferenceConverter.setDefault(
803 // PHPColorProvider.PHPDOC_KEYWORD);
804 // PreferenceConverter.setDefault(
807 // PHPColorProvider.PHPDOC_LINK);
808 // PreferenceConverter.setDefault(
811 // PHPColorProvider.PHPDOC_DEFAULT);
812 // PreferenceConverter.setDefault(
815 // PHPColorProvider.PHPDOC_TAG);
816 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
817 // PreferenceConverter.setDefault(
819 // PREFERENCE_COLOR_BACKGROUND,
820 // PHPColorProvider.BACKGROUND_COLOR);
822 // store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
823 // store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
824 // store.setDefault(RESOURCE_BUNDLE_DE, "false");
825 // store.setDefault(RESOURCE_BUNDLE_FR, "false");
826 // store.setDefault(RESOURCE_BUNDLE_ES, "false");
827 // TemplatePreferencePage.initDefaults(store);
828 //this will initialize the static fields in the syntaxrdr class
830 JavaCore.initializeDefaultPluginPreferences();
831 PreferenceConstants.initializeDefaultValues(store);
832 externalTools.initializeDefaultPreferences(store);
833 MarkerAnnotationPreferences.initializeDefaultValues(store);
836 private IWorkbenchPage internalGetActivePage() {
837 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
839 return window.getActivePage();
843 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
844 if (fImageDescriptorRegistry == null)
845 fImageDescriptorRegistry = new ImageDescriptorRegistry();
846 return fImageDescriptorRegistry;
850 * Open a file in the Workbench that may or may not exist in the workspace. Must be run on the UI thread.
853 * @throws CoreException
855 public ITextEditor openFileInTextEditor(String filename) throws CoreException {
856 // reject directories
857 if (new File(filename).isDirectory())
859 IWorkbench workbench = PlatformUI.getWorkbench();
860 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
861 IWorkbenchPage page = window.getActivePage();
862 IPath path = new Path(filename);
863 // If the file exists in the workspace, open it
864 IFile file = getWorkspace().getRoot().getFileForLocation(path);
866 ITextEditor textEditor;
867 if (file != null && file.exists()) {
868 editor = IDE.openEditor(page, file, true);
869 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
871 // Otherwise open the stream directly
874 FileStorage storage = new FileStorage(path);
875 IEditorRegistry registry = getWorkbench().getEditorRegistry();
876 IEditorDescriptor desc = registry.getDefaultEditor(filename);
878 desc = registry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
879 // desc = registry.getDefaultEditor();
881 IEditorInput input = new ExternalEditorInput(storage);
882 editor = page.openEditor(input, desc.getId());
883 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
884 // If the storage provider is not ours, we can't guarantee read/write.
885 if (textEditor != null) {
886 IDocumentProvider documentProvider = textEditor.getDocumentProvider();
887 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
888 storage.setReadOnly();
896 * Open a file in the Workbench that may or may not exist in the workspace. Must be run on the UI thread.
900 * @throws CoreException
902 public void openFileAndGotoLine(String filename, int line) throws CoreException {
903 ITextEditor textEditor = openFileInTextEditor(filename);
904 if (textEditor != null) {
905 // If a line number was given, go to it
908 line--; // document is 0 based
909 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
910 textEditor.selectAndReveal(document.getLineOffset(line), document.getLineLength(line));
911 } catch (BadLocationException e) {
912 // invalid text position -> do nothing
919 * Open a file in the Workbench that may or may not exist in the workspace. Must be run on the UI thread.
923 * @throws CoreException
925 public void openFileAndGotoOffset(String filename, int offset, int length) throws CoreException {
926 ITextEditor textEditor = openFileInTextEditor(filename);
927 if (textEditor != null) {
928 // If a line number was given, go to it
930 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
931 textEditor.selectAndReveal(offset, length);
936 public void openFileAndFindString(String filename, String findString) throws CoreException {
937 ITextEditor textEditor = openFileInTextEditor(filename);
938 if (textEditor != null) {
939 // If a string was given, go to it
940 if (findString != null) {
942 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
943 int offset = document.search(0, findString, true, false, true);
944 textEditor.selectAndReveal(offset, findString.length());
945 } catch (BadLocationException e) {
946 // invalid text position -> do nothing
952 public void setLastEditorFile(IFile textEditor) {
953 this.fLastEditorFile = textEditor;
957 * @see org.eclipse.core.runtime.Plugin#stop
959 public void stop(BundleContext context) throws Exception {
961 // JavaCore.stop(this, context);
962 plugin.savePluginPreferences();
963 IWorkspace workspace = ResourcesPlugin.getWorkspace();
964 workspace.removeResourceChangeListener(JavaModelManager.getJavaModelManager().deltaState);
965 workspace.removeSaveParticipant(plugin);
967 JavaModelManager.getJavaModelManager().shutdown();
969 ColorManager.getDefault().dispose();
970 // save the information from the php index files if necessary
971 Collection collection = fIndexManagerMap.values();
972 Iterator iterator = collection.iterator();
973 IdentifierIndexManager indexManager = null;
974 while (iterator.hasNext()) {
975 indexManager = (IdentifierIndexManager) iterator.next();
976 indexManager.writeFile();
978 if (fImageDescriptorRegistry != null)
979 fImageDescriptorRegistry.dispose();
981 // AllTypesCache.terminate();
983 if (fImageDescriptorRegistry != null)
984 fImageDescriptorRegistry.dispose();
986 unregisterAdapters();
988 // if (fASTProvider != null) {
989 // fASTProvider.dispose();
990 // fASTProvider= null;
993 if (fWorkingCopyManager != null) {
994 fWorkingCopyManager.shutdown();
995 fWorkingCopyManager = null;
998 if (fCompilationUnitDocumentProvider != null) {
999 fCompilationUnitDocumentProvider.shutdown();
1000 fCompilationUnitDocumentProvider = null;
1003 if (fJavaTextTools != null) {
1004 fJavaTextTools.dispose();
1005 fJavaTextTools = null;
1007 // JavaDocLocations.shutdownJavadocLocations();
1009 uninstallPreferenceStoreBackwardsCompatibility();
1011 // RefactoringCore.getUndoManager().shutdown();
1013 super.stop(context);
1018 * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
1020 // public void shutdown() throws CoreException {
1021 // // moved down (see below):
1022 // // super.shutdown();
1023 // // externalTools.shutDown();
1024 // ColorManager.getDefault().dispose();
1025 // // save the information from the php index files if necessary
1026 // Collection collection = fIndexManagerMap.values();
1027 // Iterator iterator = collection.iterator();
1028 // IdentifierIndexManager indexManager = null;
1029 // while (iterator.hasNext()) {
1030 // indexManager = (IdentifierIndexManager) iterator.next();
1031 // indexManager.writeFile();
1033 // if (fImageDescriptorRegistry != null)
1034 // fImageDescriptorRegistry.dispose();
1035 // // unregisterAdapters();
1036 // super.shutdown();
1037 // if (fWorkingCopyManager != null) {
1038 // fWorkingCopyManager.shutdown();
1039 // fWorkingCopyManager = null;
1041 // if (fCompilationUnitDocumentProvider != null) {
1042 // fCompilationUnitDocumentProvider.shutdown();
1043 // fCompilationUnitDocumentProvider = null;
1045 // if (fJavaTextTools != null) {
1046 // fJavaTextTools.dispose();
1047 // fJavaTextTools = null;
1049 // // JavaDocLocations.shutdownJavadocLocations();
1052 // JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
1053 // // begin JavaCore#shutdown()
1054 // //savePluginPreferences();
1055 // savePluginPreferences();
1056 // IWorkspace workspace = ResourcesPlugin.getWorkspace();
1057 // workspace.removeResourceChangeListener(JavaModelManager.getJavaModelManager().deltaState);
1058 // workspace.removeSaveParticipant(this);
1059 // ((JavaModelManager) JavaModelManager.getJavaModelManager()).shutdown();
1060 // // end JavaCore#shutdown()
1063 * Installs backwards compatibility for the preference store.
1065 private void installPreferenceStoreBackwardsCompatibility() {
1068 * Installs backwards compatibility: propagate the Java editor font from a pre-2.1 plug-in to the Platform UI's preference store
1069 * to preserve the Java editor font from a pre-2.1 workspace. This is done only once.
1071 String fontPropagatedKey = "fontPropagated"; //$NON-NLS-1$
1072 if (getPreferenceStore().contains(JFaceResources.TEXT_FONT) && !getPreferenceStore().isDefault(JFaceResources.TEXT_FONT)) {
1073 if (!getPreferenceStore().getBoolean(fontPropagatedKey))
1074 PreferenceConverter.setValue(PlatformUI.getWorkbench().getPreferenceStore(), PreferenceConstants.EDITOR_TEXT_FONT,
1075 PreferenceConverter.getFontDataArray(getPreferenceStore(), JFaceResources.TEXT_FONT));
1077 getPreferenceStore().setValue(fontPropagatedKey, true);
1080 * Backwards compatibility: set the Java editor font in this plug-in's preference store to let older versions access it. Since
1081 * 2.1 the Java editor font is managed by the workbench font preference page.
1083 PreferenceConverter.putValue(getPreferenceStore(), JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry().getFontData(
1084 PreferenceConstants.EDITOR_TEXT_FONT));
1086 fFontPropertyChangeListener = new IPropertyChangeListener() {
1087 public void propertyChange(PropertyChangeEvent event) {
1088 if (PreferenceConstants.EDITOR_TEXT_FONT.equals(event.getProperty()))
1089 PreferenceConverter.putValue(getPreferenceStore(), JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry()
1090 .getFontData(PreferenceConstants.EDITOR_TEXT_FONT));
1093 JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
1096 * Backwards compatibility: propagate the Java editor tab width from a pre-3.0 plug-in to the new preference key. This is done
1099 // final String oldTabWidthKey = PreferenceConstants.EDITOR_TAB_WIDTH;
1100 // final String newTabWidthKey = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH;
1101 // String tabWidthPropagatedKey = "tabWidthPropagated"; //$NON-NLS-1$
1102 // if (getPreferenceStore().contains(oldTabWidthKey) && !getPreferenceStore().isDefault(oldTabWidthKey)) {
1103 // if (!getPreferenceStore().getBoolean(tabWidthPropagatedKey))
1104 // getPreferenceStore().setValue(newTabWidthKey, getPreferenceStore().getInt(oldTabWidthKey));
1106 // getPreferenceStore().setValue(tabWidthPropagatedKey, true);
1109 // * Backwards compatibility: set the Java editor tab width in this plug-in's preference store with the old key to let older
1110 // * versions access it. Since 3.0 the tab width is managed by the extended texteditor and uses a new key.
1112 // getPreferenceStore().putValue(oldTabWidthKey, getPreferenceStore().getString(newTabWidthKey));
1113 // fPropertyChangeListener = new IPropertyChangeListener() {
1114 // public void propertyChange(PropertyChangeEvent event) {
1115 // if (newTabWidthKey.equals(event.getProperty()))
1116 // getPreferenceStore().putValue(oldTabWidthKey, getPreferenceStore().getString(newTabWidthKey));
1119 // getPreferenceStore().addPropertyChangeListener(fPropertyChangeListener);
1121 * Backward compatibility for the refactoring preference key.
1123 // getPreferenceStore().setValue(
1124 // PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD,
1125 // RefactoringCore.getConditionCheckingFailedSeverity());
1129 * Uninstalls backwards compatibility for the preference store.
1131 private void uninstallPreferenceStoreBackwardsCompatibility() {
1132 JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
1133 // getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
1137 * (non - Javadoc) Method declared in Plugin
1139 public void start(BundleContext context) throws Exception {
1140 super.start(context);
1142 // JavaCore.start(this, context);
1143 final JavaModelManager manager = JavaModelManager.getJavaModelManager();
1145 manager.configurePluginDebugOptions();
1147 // request state folder creation (workaround 19885)
1148 // JavaCore.getPlugin().getStateLocation();
1150 // retrieve variable values
1151 PHPeclipsePlugin.getDefault().getPluginPreferences().addPropertyChangeListener(
1152 new JavaModelManager.PluginPreferencesListener());
1153 // manager.loadVariablesAndContainers();
1155 final IWorkspace workspace = ResourcesPlugin.getWorkspace();
1156 workspace.addResourceChangeListener(manager.deltaState, IResourceChangeEvent.PRE_BUILD | IResourceChangeEvent.POST_BUILD
1157 | IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.PRE_CLOSE);
1160 ISavedState savedState = workspace.addSaveParticipant(PHPeclipsePlugin.this, manager);
1162 // process deltas since last activated in indexer thread so that indexes are up-to-date.
1163 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658
1164 Job processSavedState = new Job(Util.bind("savedState.jobName")) { //$NON-NLS-1$
1165 protected IStatus run(IProgressMonitor monitor) {
1167 // add save participant and process delta atomically
1168 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59937
1169 workspace.run(new IWorkspaceRunnable() {
1170 public void run(IProgressMonitor progress) throws CoreException {
1171 ISavedState savedState = workspace.addSaveParticipant(PHPeclipsePlugin.this, manager);
1172 if (savedState != null) {
1173 // the event type coming from the saved state is always POST_AUTO_BUILD
1174 // force it to be POST_CHANGE so that the delta processor can handle it
1175 manager.deltaState.getDeltaProcessor().overridenEventType = IResourceChangeEvent.POST_CHANGE;
1176 savedState.processResourceChangeEvents(manager.deltaState);
1180 } catch (CoreException e) {
1181 return e.getStatus();
1183 return Status.OK_STATUS;
1186 processSavedState.setSystem(true);
1187 processSavedState.setPriority(Job.SHORT); // process asap
1188 processSavedState.schedule();
1189 } catch (RuntimeException e) {
1196 // if (USE_WORKING_COPY_OWNERS) {
1197 WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
1198 public IBuffer createBuffer(ICompilationUnit workingCopy) {
1199 ICompilationUnit original = workingCopy.getPrimary();
1200 IResource resource = original.getResource();
1201 if (resource instanceof IFile)
1202 return new DocumentAdapter(workingCopy, (IFile) resource);
1203 return DocumentAdapter.NULL;
1208 installPreferenceStoreBackwardsCompatibility();
1212 // registerAdapters();
1214 // // externalTools.startUp();
1215 // getStandardDisplay().asyncExec(new Runnable() {
1216 // public void run() {
1217 // //initialize the variable context manager
1218 // VariableContextManager.getDefault();
1222 // // if (USE_WORKING_COPY_OWNERS) {
1223 // WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
1224 // public IBuffer createBuffer(ICompilationUnit workingCopy) {
1225 // ICompilationUnit original = workingCopy.getPrimary();
1226 // IResource resource = original.getResource();
1227 // if (resource instanceof IFile)
1228 // return new DocumentAdapter(workingCopy, (IFile) resource);
1229 // return DocumentAdapter.NULL;
1234 // installPreferenceStoreBackwardsCompatibility();
1236 // AllTypesCache.initialize();
1238 // Initialize AST provider
1239 // getASTProvider();
1242 // public void startup() throws CoreException {
1244 // // begin JavaCore.startup();
1245 // JavaModelManager manager = JavaModelManager.getJavaModelManager();
1247 // manager.configurePluginDebugOptions();
1248 // // request state folder creation (workaround 19885)
1249 // // JavaCore.getPlugin().getStateLocation();
1250 // getStateLocation();
1251 // // retrieve variable values
1253 // JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new
1254 // // JavaModelManager.PluginPreferencesListener());
1255 // getPluginPreferences().addPropertyChangeListener(
1256 // new JavaModelManager.PluginPreferencesListener());
1258 // // manager.loadVariablesAndContainers();
1259 // final IWorkspace workspace = ResourcesPlugin.getWorkspace();
1260 // workspace.addResourceChangeListener(
1261 // manager.deltaState,
1262 // IResourceChangeEvent.PRE_BUILD
1263 // | IResourceChangeEvent.POST_BUILD
1264 // | IResourceChangeEvent.POST_CHANGE
1265 // | IResourceChangeEvent.PRE_DELETE
1266 // | IResourceChangeEvent.PRE_CLOSE);
1267 // // startIndexing();
1268 // workspace.addSaveParticipant(PHPeclipsePlugin.getDefault(), manager);
1269 // } catch (CoreException e) {
1270 // } catch (RuntimeException e) {
1271 // manager.shutdown();
1274 // // end JavaCore.startup();
1275 // IAdapterManager platformManager = Platform.getAdapterManager();
1276 // platformManager.registerAdapters(new PHPElementAdapterFactory(),
1277 // PHPElement.class);
1278 // platformManager.registerAdapters(new ResourceAdapterFactory(),
1279 // IResource.class);
1280 // // externalTools.startUp();
1281 // getStandardDisplay().asyncExec(new Runnable() {
1282 // public void run() {
1283 // //initialize the variable context manager
1284 // VariableContextManager.getDefault();
1289 private void registerAdapters() {
1290 fJavaElementAdapterFactory = new JavaElementAdapterFactory();
1291 // fMarkerAdapterFactory= new MarkerAdapterFactory();
1292 // fEditorInputAdapterFactory= new EditorInputAdapterFactory();
1293 fResourceAdapterFactory = new ResourceAdapterFactory();
1294 // fLogicalPackageAdapterFactory= new LogicalPackageAdapterFactory();
1296 IAdapterManager manager = Platform.getAdapterManager();
1297 manager.registerAdapters(fJavaElementAdapterFactory, IJavaElement.class);
1298 // manager.registerAdapters(fMarkerAdapterFactory, IMarker.class);
1299 // manager.registerAdapters(fEditorInputAdapterFactory, IEditorInput.class);
1300 manager.registerAdapters(fResourceAdapterFactory, IResource.class);
1301 // manager.registerAdapters(fLogicalPackageAdapterFactory,
1302 // LogicalPackage.class);
1305 private void unregisterAdapters() {
1306 IAdapterManager manager = Platform.getAdapterManager();
1307 manager.unregisterAdapters(fJavaElementAdapterFactory);
1308 // manager.unregisterAdapters(fMarkerAdapterFactory);
1309 // manager.unregisterAdapters(fEditorInputAdapterFactory);
1310 manager.unregisterAdapters(fResourceAdapterFactory);
1311 // manager.unregisterAdapters(fLogicalPackageAdapterFactory);
1315 * Returns a combined preference store, this store is read-only.
1317 * @return the combined preference store
1321 public IPreferenceStore getCombinedPreferenceStore() {
1322 if (fCombinedPreferenceStore == null) {
1323 IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
1324 fCombinedPreferenceStore = new ChainedPreferenceStore(new IPreferenceStore[] {
1325 getPreferenceStore(),
1326 new PreferencesAdapter(PHPeclipsePlugin.getDefault().getPluginPreferences()),
1327 generalTextStore });
1329 return fCombinedPreferenceStore;
1332 public synchronized IBufferFactory getBufferFactory() {
1333 if (fBufferFactory == null)
1334 fBufferFactory = new CustomBufferFactory();
1335 return fBufferFactory;
1339 * Returns the registry of the extensions to the <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code> extension
1342 * @return the registry of contributed <code>IJavaFoldingStructureProvider</code>
1345 public synchronized JavaFoldingStructureProviderRegistry getFoldingStructureProviderRegistry() {
1346 if (fFoldingStructureProviderRegistry == null)
1347 fFoldingStructureProviderRegistry = new JavaFoldingStructureProviderRegistry();
1348 return fFoldingStructureProviderRegistry;
1352 * Runs the given action as an atomic Java model operation.
1354 * After running a method that modifies java elements, registered listeners receive after-the-fact notification of what just
1355 * transpired, in the form of a element changed event. This method allows clients to call a number of methods that modify java
1356 * elements and only have element changed event notifications reported at the end of the entire batch.
1359 * If this method is called outside the dynamic scope of another such call, this method runs the action and then reports a single
1360 * element changed event describing the net effect of all changes done to java elements by the action.
1363 * If this method is called in the dynamic scope of another such call, this method simply runs the action.
1367 * the action to perform
1369 * a progress monitor, or <code>null</code> if progress reporting and cancellation are not desired
1370 * @exception CoreException
1371 * if the operation failed.
1374 public static void run(IWorkspaceRunnable action, IProgressMonitor monitor) throws CoreException {
1375 run(action, ResourcesPlugin.getWorkspace().getRoot(), monitor);
1379 * Runs the given action as an atomic Java model operation.
1381 * After running a method that modifies java elements, registered listeners receive after-the-fact notification of what just
1382 * transpired, in the form of a element changed event. This method allows clients to call a number of methods that modify java
1383 * elements and only have element changed event notifications reported at the end of the entire batch.
1386 * If this method is called outside the dynamic scope of another such call, this method runs the action and then reports a single
1387 * element changed event describing the net effect of all changes done to java elements by the action.
1390 * If this method is called in the dynamic scope of another such call, this method simply runs the action.
1393 * The supplied scheduling rule is used to determine whether this operation can be run simultaneously with workspace changes in
1394 * other threads. See <code>IWorkspace.run(...)</code> for more details.
1398 * the action to perform
1400 * the scheduling rule to use when running this operation, or <code>null</code> if there are no scheduling restrictions
1401 * for this operation.
1403 * a progress monitor, or <code>null</code> if progress reporting and cancellation are not desired
1404 * @exception CoreException
1405 * if the operation failed.
1408 public static void run(IWorkspaceRunnable action, ISchedulingRule rule, IProgressMonitor monitor) throws CoreException {
1409 IWorkspace workspace = ResourcesPlugin.getWorkspace();
1410 if (workspace.isTreeLocked()) {
1411 new BatchOperation(action).run(monitor);
1413 // use IWorkspace.run(...) to ensure that a build will be done in
1415 workspace.run(new BatchOperation(action), rule, IWorkspace.AVOID_UPDATE, monitor);
1420 * Returns the template context type registry for the java plugin.
1422 * @return the template context type registry for the java plugin
1425 public ContextTypeRegistry getTemplateContextRegistry() {
1426 if (fContextTypeRegistry == null) {
1427 fContextTypeRegistry = new ContributionContextTypeRegistry();
1429 fContextTypeRegistry.addContextType(new JavaContextType());
1430 fContextTypeRegistry.addContextType(new JavaDocContextType());
1431 fContextTypeRegistry.addContextType(new HTMLContextType());
1434 return fContextTypeRegistry;
1438 * Returns the template store for the java editor templates.
1440 * @return the template store for the java editor templates
1443 public TemplateStore getTemplateStore() {
1444 if (fTemplateStore == null) {
1445 // boolean alreadyMigrated= getPreferenceStore().getBoolean(TEMPLATES_MIGRATION_KEY);
1446 // if (alreadyMigrated)
1447 fTemplateStore = new ContributionTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), TEMPLATES_KEY);
1449 // fTemplateStore= new CompatibilityTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), TEMPLATES_KEY,
1450 // Templates.getInstance());
1451 // getPreferenceStore().setValue(TEMPLATES_MIGRATION_KEY, true);
1455 fTemplateStore.load();
1456 } catch (IOException e) {
1461 return fTemplateStore;
1465 * Returns the template context type registry for the code generation templates.
1467 * @return the template context type registry for the code generation templates
1470 public ContextTypeRegistry getCodeTemplateContextRegistry() {
1471 if (fCodeTemplateContextTypeRegistry == null) {
1472 fCodeTemplateContextTypeRegistry = new ContributionContextTypeRegistry();
1474 CodeTemplateContextType.registerContextTypes(fCodeTemplateContextTypeRegistry);
1477 return fCodeTemplateContextTypeRegistry;
1481 * Returns the template store for the code generation templates.
1483 * @return the template store for the code generation templates
1486 public TemplateStore getCodeTemplateStore() {
1487 if (fCodeTemplateStore == null) {
1488 // boolean alreadyMigrated= getPreferenceStore().getBoolean(CODE_TEMPLATES_MIGRATION_KEY);
1489 // if (alreadyMigrated)
1490 fCodeTemplateStore = new ContributionTemplateStore(getCodeTemplateContextRegistry(), getPreferenceStore(), CODE_TEMPLATES_KEY);
1492 // fCodeTemplateStore= new CompatibilityTemplateStore(getCodeTemplateContextRegistry(), getPreferenceStore(),
1493 // CODE_TEMPLATES_KEY, CodeTemplates.getInstance());
1494 // getPreferenceStore().setValue(CODE_TEMPLATES_MIGRATION_KEY, true);
1498 fCodeTemplateStore.load();
1499 } catch (IOException e) {
1503 // compatibility / bug fixing code for duplicated templates
1504 // TODO remove for 3.0
1505 // CompatibilityTemplateStore.pruneDuplicates(fCodeTemplateStore, true);
1508 return fCodeTemplateStore;