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.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.phpdt.internal.ui.IJavaStatusConstants;
38 import net.sourceforge.phpdt.internal.ui.JavaElementAdapterFactory;
39 import net.sourceforge.phpdt.internal.ui.ResourceAdapterFactory;
40 import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache;
41 import net.sourceforge.phpdt.internal.ui.preferences.MockupPreferenceStore;
42 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
43 import net.sourceforge.phpdt.internal.ui.text.folding.JavaFoldingStructureProviderRegistry;
44 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
45 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
46 import net.sourceforge.phpdt.internal.ui.viewsupport.ProblemMarkerManager;
47 import net.sourceforge.phpdt.ui.IContextMenuConstants;
48 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
49 import net.sourceforge.phpdt.ui.PreferenceConstants;
50 import net.sourceforge.phpdt.ui.text.JavaTextTools;
51 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
52 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
53 import net.sourceforge.phpeclipse.builder.FileStorage;
54 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
55 import net.sourceforge.phpeclipse.phpeditor.CustomBufferFactory;
56 import net.sourceforge.phpeclipse.phpeditor.DocumentAdapter;
57 import net.sourceforge.phpeclipse.phpeditor.ICompilationUnitDocumentProvider;
58 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
59 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
60 import net.sourceforge.phpeclipse.phpeditor.WorkingCopyManager;
61 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
63 import org.eclipse.core.resources.IFile;
64 import org.eclipse.core.resources.IProject;
65 import org.eclipse.core.resources.IResource;
66 import org.eclipse.core.resources.IResourceChangeEvent;
67 import org.eclipse.core.resources.ISavedState;
68 import org.eclipse.core.resources.IWorkspace;
69 import org.eclipse.core.resources.IWorkspaceRunnable;
70 import org.eclipse.core.resources.ResourcesPlugin;
71 import org.eclipse.core.runtime.CoreException;
72 import org.eclipse.core.runtime.IAdapterManager;
73 import org.eclipse.core.runtime.IConfigurationElement;
74 import org.eclipse.core.runtime.IPath;
75 import org.eclipse.core.runtime.IProgressMonitor;
76 import org.eclipse.core.runtime.IStatus;
77 import org.eclipse.core.runtime.Path;
78 import org.eclipse.core.runtime.Platform;
79 import org.eclipse.core.runtime.Status;
80 import org.eclipse.core.runtime.jobs.ISchedulingRule;
81 import org.eclipse.core.runtime.jobs.Job;
82 import org.eclipse.jface.action.GroupMarker;
83 import org.eclipse.jface.action.IMenuManager;
84 import org.eclipse.jface.action.Separator;
85 import org.eclipse.jface.preference.IPreferenceStore;
86 import org.eclipse.jface.preference.PreferenceConverter;
87 import org.eclipse.jface.resource.JFaceResources;
88 import org.eclipse.jface.text.BadLocationException;
89 import org.eclipse.jface.text.IDocument;
90 import org.eclipse.jface.text.templates.ContextTypeRegistry;
91 import org.eclipse.jface.text.templates.persistence.TemplateStore;
92 import org.eclipse.jface.util.IPropertyChangeListener;
93 import org.eclipse.jface.util.PropertyChangeEvent;
94 import org.eclipse.swt.graphics.RGB;
95 import org.eclipse.swt.widgets.Display;
96 import org.eclipse.swt.widgets.Shell;
97 import org.eclipse.ui.IEditorDescriptor;
98 import org.eclipse.ui.IEditorInput;
99 import org.eclipse.ui.IEditorPart;
100 import org.eclipse.ui.IEditorRegistry;
101 import org.eclipse.ui.IWorkbench;
102 import org.eclipse.ui.IWorkbenchPage;
103 import org.eclipse.ui.IWorkbenchWindow;
104 import org.eclipse.ui.PlatformUI;
105 import org.eclipse.ui.editors.text.EditorsUI;
106 import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
107 import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
108 import org.eclipse.ui.ide.IDE;
109 import org.eclipse.ui.plugin.AbstractUIPlugin;
110 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
111 import org.eclipse.ui.texteditor.ConfigurationElementSorter;
112 import org.eclipse.ui.texteditor.IDocumentProvider;
113 import org.eclipse.ui.texteditor.ITextEditor;
114 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
115 import org.osgi.framework.BundleContext;
118 * The main plugin class to be used in the desktop.
120 public class PHPeclipsePlugin extends AbstractUIPlugin implements
121 IPreferenceConstants {
123 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
125 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
127 public static final String EDITOR_ID = PHPeclipsePlugin.PLUGIN_ID
130 public static final String ID_PERSPECTIVE = "net.sourceforge.phpeclipse.PHPPerspective"; //$NON-NLS-1$
135 * id of builder - matches plugin.xml (concatenate pluginid.builderid)
137 public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
139 // public static final String BUILDER_INDEX_ID = PLUGIN_ID +
141 /** General debug flag */
143 public static final boolean DEBUG = false;
146 * The maximum number of allowed proposals by category
148 public final static int MAX_PROPOSALS = 200;
151 * The key to store customized templates.
155 private static final String TEMPLATES_KEY = "net.sourceforge.phpdt.ui.text.custom_templates"; //$NON-NLS-1$
158 * The key to store customized code templates.
162 private static final String CODE_TEMPLATES_KEY = "net.sourceforge.phpdt.ui.text.custom_code_templates"; //$NON-NLS-1$
165 * The key to store whether the legacy templates have been migrated
169 // private static final String TEMPLATES_MIGRATION_KEY=
170 // "net.sourceforge.phpdt.ui.text.templates_migrated"; //$NON-NLS-1$
172 * The key to store whether the legacy code templates have been migrated
176 // private static final String CODE_TEMPLATES_MIGRATION_KEY=
177 // "net.sourceforge.phpdt.ui.text.code_templates_migrated";
179 // private static ExternalToolsPlugin externalTools;
181 * The Java virtual machine that we are running on.
183 // private static int jvm;
185 // private static final int MRJ_2_0 = 0;
187 // /** MRJ 2.1 or later */
188 // private static final int MRJ_2_1 = 1;
190 // /** Java on Mac OS X 10.0 (MRJ 3.0) */
191 // private static final int MRJ_3_0 = 3;
194 // private static final int MRJ_3_1 = 4;
196 // /** JVM constant for any other platform */
197 // private static final int OTHER = -1;
198 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID +
199 // ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
200 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID
201 + ".ui.CodingActionSet"; //$NON-NLS-1$
203 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
205 public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
207 public static final String PHPPARSER_NEW = "test.PHPParser";
209 /** Change this if you want to switch PHP Parser. */
210 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
212 // The shared instance.
213 private static PHPeclipsePlugin plugin;
216 * The template context type registry for the java editor.
220 private ContextTypeRegistry fContextTypeRegistry;
223 * The code template context type registry for the java editor.
227 private ContextTypeRegistry fCodeTemplateContextTypeRegistry;
230 * The template store for the java editor.
234 private TemplateStore fTemplateStore;
237 * The coded template store for the java editor.
241 private TemplateStore fCodeTemplateStore;
244 private static final int WINDOWS_9x = 6;
247 private static final int WINDOWS_NT = 5;
249 private ImageDescriptorRegistry fImageDescriptorRegistry;
251 private HashMap fIndexManagerMap = new HashMap();
253 private IWorkingCopyManager fWorkingCopyManager;
255 private IBufferFactory fBufferFactory;
257 private ICompilationUnitDocumentProvider fCompilationUnitDocumentProvider;
259 private JavaTextTools fJavaTextTools;
261 private ProblemMarkerManager fProblemMarkerManager;
263 private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
265 private IFile fLastEditorFile = null;
267 private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
269 private JavaElementAdapterFactory fJavaElementAdapterFactory;
271 // private MarkerAdapterFactory fMarkerAdapterFactory;
272 // private EditorInputAdapterFactory fEditorInputAdapterFactory;
273 private ResourceAdapterFactory fResourceAdapterFactory;
275 // private LogicalPackageAdapterFactory fLogicalPackageAdapterFactory;
276 private IPropertyChangeListener fFontPropertyChangeListener;
279 * Property change listener on this plugin's preference store.
283 // private IPropertyChangeListener fPropertyChangeListener;
285 * The combined preference store.
289 private IPreferenceStore fCombinedPreferenceStore;
292 * The extension point registry for the
293 * <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code>
298 private JavaFoldingStructureProviderRegistry fFoldingStructureProviderRegistry;
301 * Mockup preference store for firing events and registering listeners on
302 * project setting changes. FIXME: Temporary solution.
306 private MockupPreferenceStore fMockupPreferenceStore;
311 public PHPeclipsePlugin() {
314 // externalTools = new ExternalToolsPlugin();
318 // ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
319 // } catch (MissingResourceException x) {
320 // resourceBundle = null;
325 // * Returns all Java editor text hovers contributed to the workbench.
327 // * @return an array of JavaEditorTextHoverDescriptor
330 // public JavaEditorTextHoverDescriptor[]
331 // getJavaEditorTextHoverDescriptors()
333 // if (fJavaEditorTextHoverDescriptors == null)
334 // fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
335 // .getContributedHovers();
336 // return fJavaEditorTextHoverDescriptors;
339 * Returns all Java editor text hovers contributed to the workbench.
341 * @return an array of JavaEditorTextHoverDescriptor
344 public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
345 if (fJavaEditorTextHoverDescriptors == null) {
346 fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
347 .getContributedHovers();
348 ConfigurationElementSorter sorter = new ConfigurationElementSorter() {
350 * @see org.eclipse.ui.texteditor.ConfigurationElementSorter#getConfigurationElement(java.lang.Object)
352 public IConfigurationElement getConfigurationElement(
354 return ((JavaEditorTextHoverDescriptor) object)
355 .getConfigurationElement();
358 sorter.sort(fJavaEditorTextHoverDescriptors);
360 // The Problem hover has to be the first and the Annotation hover
362 // be the last one in the JDT UI's hover list
363 int length = fJavaEditorTextHoverDescriptors.length;
365 int last = length - 1;
366 int problemHoverIndex = -1;
367 int annotationHoverIndex = -1;
368 for (int i = 0; i < length; i++) {
369 if (!fJavaEditorTextHoverDescriptors[i].getId().startsWith(
371 if (problemHoverIndex == -1 || annotationHoverIndex == -1)
381 if (fJavaEditorTextHoverDescriptors[i].getId().equals(
382 "net.sourceforge.phpdt.ui.AnnotationHover")) { //$NON-NLS-1$
383 annotationHoverIndex = i;
386 if (fJavaEditorTextHoverDescriptors[i].getId().equals(
387 "net.sourceforge.phpdt.ui.ProblemHover")) { //$NON-NLS-1$
388 problemHoverIndex = i;
393 JavaEditorTextHoverDescriptor hoverDescriptor = null;
395 if (first > -1 && problemHoverIndex > -1
396 && problemHoverIndex != first) {
397 // move problem hover to beginning
398 hoverDescriptor = fJavaEditorTextHoverDescriptors[first];
399 fJavaEditorTextHoverDescriptors[first] = fJavaEditorTextHoverDescriptors[problemHoverIndex];
400 fJavaEditorTextHoverDescriptors[problemHoverIndex] = hoverDescriptor;
402 // update annotation hover index if needed
403 if (annotationHoverIndex == first)
404 annotationHoverIndex = problemHoverIndex;
407 if (annotationHoverIndex > -1 && annotationHoverIndex != last) {
408 // move annotation hover to end
409 hoverDescriptor = fJavaEditorTextHoverDescriptors[last];
410 fJavaEditorTextHoverDescriptors[last] = fJavaEditorTextHoverDescriptors[annotationHoverIndex];
411 fJavaEditorTextHoverDescriptors[annotationHoverIndex] = hoverDescriptor;
414 // Move Best Match hover to front
415 for (int i = 0; i < fJavaEditorTextHoverDescriptors.length - 1; i++) {
416 if (PreferenceConstants.ID_BESTMATCH_HOVER
417 .equals(fJavaEditorTextHoverDescriptors[i].getId())) {
418 hoverDescriptor = fJavaEditorTextHoverDescriptors[i];
419 for (int j = i; j > 0; j--)
420 fJavaEditorTextHoverDescriptors[j] = fJavaEditorTextHoverDescriptors[j - 1];
421 fJavaEditorTextHoverDescriptors[0] = hoverDescriptor;
428 return fJavaEditorTextHoverDescriptors;
432 * Resets the Java editor text hovers contributed to the workbench.
434 * This will force a rebuild of the descriptors the next time a client asks
438 * @return an array of JavaEditorTextHoverDescriptor
441 public void resetJavaEditorTextHoverDescriptors() {
442 fJavaEditorTextHoverDescriptors = null;
446 * Creates the PHP plugin standard groups in a context menu.
448 public static void createStandardGroups(IMenuManager menu) {
451 menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
452 menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
453 menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
454 menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
455 menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
456 menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
457 menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
458 menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
459 menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
460 menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
461 menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
464 public static IWorkbenchPage getActivePage() {
465 return getDefault().internalGetActivePage();
468 public static Shell getActiveWorkbenchShell() {
469 return getActiveWorkbenchWindow().getShell();
473 * Returns an array of all editors that have an unsaved content. If the
474 * identical content is presented in more than one editor, only one of those
475 * editor parts is part of the result.
477 * @return an array of all dirty editor parts.
479 public static IEditorPart[] getDirtyEditors() {
480 Set inputs = new HashSet();
481 List result = new ArrayList(0);
482 IWorkbench workbench = getDefault().getWorkbench();
483 IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
484 for (int i = 0; i < windows.length; i++) {
485 IWorkbenchPage[] pages = windows[i].getPages();
486 for (int x = 0; x < pages.length; x++) {
487 IEditorPart[] editors = pages[x].getDirtyEditors();
488 for (int z = 0; z < editors.length; z++) {
489 IEditorPart ep = editors[z];
490 IEditorInput input = ep.getEditorInput();
491 if (!inputs.contains(input)) {
498 return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]);
501 public static IWorkbenchWindow getActiveWorkbenchWindow() {
502 return getDefault().getWorkbench().getActiveWorkbenchWindow();
506 * Returns the shared instance.
508 public static PHPeclipsePlugin getDefault() {
512 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
513 return getDefault().internalGetImageDescriptorRegistry();
516 static IPath getInstallLocation() {
517 return new Path(getDefault().getBundle().getEntry("/").getFile());
520 // public static int getJVM() {
524 public static String getPluginId() {
525 return getDefault().getBundle().getSymbolicName();
529 * Returns the standard display to be used. The method first checks, if the
530 * thread calling this method has an associated display. If so, this display
531 * is returned. Otherwise the method returns the default display.
533 public static Display getStandardDisplay() {
534 Display display = Display.getCurrent();
535 if (display == null) {
536 display = Display.getDefault();
541 // public static ExternalToolsPlugin getExternalTools() {
542 // return externalTools;
545 * Returns the workspace instance.
547 public static IWorkspace getWorkspace() {
548 return ResourcesPlugin.getWorkspace();
551 public static boolean isDebug() {
552 return getDefault().isDebugging();
555 // public static void logErrorMessage(String message) {
556 // log(new Status(IStatus.ERROR, getPluginId(),
557 // JavaStatusConstants.INTERNAL_ERROR, message, null));
560 // public static void logErrorStatus(String message, IStatus status) {
561 // if (status == null) {
562 // logErrorMessage(message);
565 // MultiStatus multi= new MultiStatus(getPluginId(),
566 // JavaStatusConstants.INTERNAL_ERROR, message, null);
567 // multi.add(status);
571 // public static void log(Throwable e) {
572 // log(new Status(IStatus.ERROR, getPluginId(),
573 // JavaStatusConstants.INTERNAL_ERROR,
574 // JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
576 public static void log(int severity, String message) {
577 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message,
582 public static void log(IStatus status) {
583 getDefault().getLog().log(status);
586 public static void log(Throwable t) {
590 public static void log(String message, Throwable t) {
591 log(error(message, t));
594 public static void logErrorMessage(String message) {
595 log(new Status(IStatus.ERROR, getPluginId(),
596 IJavaStatusConstants.INTERNAL_ERROR, message, null));
599 public static IStatus error(Throwable t) {
600 return error("PHPeclipsePlugin.internalErrorOccurred", t); //$NON-NLS-1$
603 public static IStatus error(String message, Throwable t) {
604 return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, t);
607 // private static void setJVM() {
608 // String osName = System.getProperty("os.name");
609 // if (osName.startsWith("Mac OS")) {
610 // String mrjVersion = System.getProperty("mrj.version");
611 // String majorMRJVersion = mrjVersion.substring(0, 3);
614 // double version = Double.valueOf(majorMRJVersion).doubleValue();
615 // if (version == 2) {
617 // } else if (version >= 2.1 && version < 3) {
619 // } else if (version == 3.0) {
621 // } else if (version >= 3.1) {
624 // } catch (NumberFormatException nfe) {
626 // } else if (osName.startsWith("Windows")) {
627 // if (osName.indexOf("9") != -1) {
635 // TODO: refactor this into a better method name !
636 public synchronized ICompilationUnitDocumentProvider getCompilationUnitDocumentProvider() {
637 if (fCompilationUnitDocumentProvider == null)
638 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
639 return fCompilationUnitDocumentProvider;
643 * Get the identifier index manager for the given project
646 * the current project
649 public IdentifierIndexManager getIndexManager(IProject iProject) {
650 IPath path = iProject.getWorkingLocation(PHPeclipsePlugin.PLUGIN_ID);
651 path = path.append("project.index");
652 String indexFilename = path.toString();
654 // IdentDB db = IdentDB.getInstance();
655 // } catch (ClassNotFoundException e) {
656 // e.printStackTrace();
657 // } catch (SQLException e) {
658 // e.printStackTrace();
660 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap
662 if (indexManager == null) {
663 indexManager = new IdentifierIndexManager(indexFilename);
664 fIndexManagerMap.put(indexFilename, indexManager);
669 public synchronized IWorkingCopyManager getWorkingCopyManager() {
670 if (fWorkingCopyManager == null) {
671 ICompilationUnitDocumentProvider provider = getCompilationUnitDocumentProvider();
672 fWorkingCopyManager = new WorkingCopyManager(provider);
674 return fWorkingCopyManager;
677 public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
678 if (fMembersOrderPreferenceCache == null)
679 fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
680 return fMembersOrderPreferenceCache;
684 * Returns the mockup preference store for firing events and registering
685 * listeners on project setting changes. Temporary solution.
687 public MockupPreferenceStore getMockupPreferenceStore() {
688 if (fMockupPreferenceStore == null)
689 fMockupPreferenceStore = new MockupPreferenceStore();
691 return fMockupPreferenceStore;
694 public synchronized ProblemMarkerManager getProblemMarkerManager() {
695 if (fProblemMarkerManager == null)
696 fProblemMarkerManager = new ProblemMarkerManager();
697 return fProblemMarkerManager;
700 // public synchronized JavaTextTools getJavaTextTools() {
701 // if (fJavaTextTools == null)
702 // fJavaTextTools = new JavaTextTools(getPreferenceStore());
703 // return fJavaTextTools;
705 public synchronized JavaTextTools getJavaTextTools() {
706 if (fJavaTextTools == null)
707 fJavaTextTools = new JavaTextTools(getPreferenceStore(), JavaCore
708 .getPlugin().getPluginPreferences());
709 return fJavaTextTools;
712 public IFile getLastEditorFile() {
713 return fLastEditorFile;
717 * Returns the string from the plugin's resource bundle, or 'key' if not
720 // public static String getResourceString(String key) {
721 // ResourceBundle bundle =
722 // PHPeclipsePlugin.getDefault().getResourceBundle();
724 // return bundle.getString(key);
725 // } catch (MissingResourceException e) {
730 * Returns the plugin's resource bundle,
732 // public ResourceBundle getResourceBundle() {
733 // return resourceBundle;
735 protected void initializeDefaultPreferences(IPreferenceStore store) {
736 String operatingSystem = Platform.getOS();
737 // maxosx, linux, solaris, win32,...
739 InputStream is = getDefault()
741 new Path("prefs/default_" + operatingSystem
743 PropertyResourceBundle resourceBundle = new PropertyResourceBundle(
745 Enumeration e = resourceBundle.getKeys();
747 while (e.hasMoreElements()) {
748 key = (String) e.nextElement();
749 store.setDefault(key, resourceBundle.getString(key));
751 } catch (Exception e) {
752 // no default properties found
753 if (operatingSystem.equals(Platform.OS_WIN32)) {
754 // store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
755 // store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php
757 // store.setDefault(MYSQL_RUN_PREF,
758 // "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
759 // store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
760 // store.setDefault(XAMPP_START_PREF,
761 // "c:\\xampp\\xampp_start.exe");
762 // store.setDefault(XAMPP_STOP_PREF,
763 // "c:\\xampp\\xampp_stop.exe");
765 // ETC_HOSTS_PATH_PREF,
766 // "c:\\windows\\system32\\drivers\\etc\\hosts");
768 // store.setDefault(PHP_RUN_PREF, "/apache/php/php");
769 // store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f
771 // store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
772 // store.setDefault(APACHE_RUN_PREF, "/apache/apache");
773 // store.setDefault(XAMPP_START_PREF, "xamp/xampp_start");
774 // store.setDefault(XAMPP_STOP_PREF, "xampp/xampp_stop");
776 // store.setDefault(MYSQL_PREF, "--standalone");
777 // store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot
779 // store.setDefault(APACHE_STOP_PREF, "-k shutdown");
780 // store.setDefault(APACHE_RESTART_PREF, "-k restart");
781 // store.setDefault(MYSQL_START_BACKGROUND, "true");
782 // store.setDefault(APACHE_START_BACKGROUND, "true");
783 // store.setDefault(APACHE_STOP_BACKGROUND, "true");
784 // store.setDefault(APACHE_RESTART_BACKGROUND, "true");
787 // store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
788 // store.setDefault(PHP_OBFUSCATOR_DEFAULT, "c:\\temp");
789 // if (operatingSystem.equals(Platform.OS_WIN32)) {
790 // store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32
791 // url.dll,FileProtocolHandler {0}");
792 // } else if (operatingSystem.equals(Platform.OS_MACOSX)) {
793 // store.setDefault(PHP_OBFUSCATOR_DEFAULT, "/tmp");
794 // TODO How do we start Safari on Mac OS X ?
795 // store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
797 // store.setDefault(PHP_OBFUSCATOR_DEFAULT, "/tmp");
798 // store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
801 // store.setDefault(PHP_EXTENSION_PREFS,
802 // "php,php3,php4,php5,phtml,inc,module,class");
804 // store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
805 // store.setDefault(PHP_INTERNAL_PARSER, "false");
806 // store.setDefault(PHP_EXTERNAL_PARSER, "true");
807 // store.setDefault(PHP_PARSE_ON_SAVE, "true");
808 // show line numbers:
809 // store.setDefault(LINE_NUMBER_RULER, "false");
810 // store.setDefault(FORMATTER_TAB_SIZE, "4");
811 // php syntax highlighting
812 store.setDefault(PHP_USERDEF_XMLFILE, "");
813 // assume there is none chooA
814 // PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT,
815 // PHPColorProvider.MULTI_LINE_COMMENT);
816 // PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT,
817 // PHPColorProvider.SINGLE_LINE_COMMENT);
818 PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
819 PreferenceConverter.setDefault(store, PHP_KEYWORD,
820 PHPColorProvider.KEYWORD);
821 PreferenceConverter.setDefault(store, PHP_VARIABLE,
822 PHPColorProvider.VARIABLE);
823 PreferenceConverter.setDefault(store, PHP_VARIABLE_DOLLAR,
824 PHPColorProvider.VARIABLE);
825 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME,
826 PHPColorProvider.FUNCTION_NAME);
827 PreferenceConverter.setDefault(store, PHP_CONSTANT,
828 PHPColorProvider.CONSTANT);
829 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
830 // PreferenceConverter.setDefault(store, PHP_STRING_DQ,
831 // PHPColorProvider.STRING_DQ);
832 // store.setDefault(PHP_STRING_BOLD_DQ, true);
833 // PreferenceConverter.setDefault(store, PHP_STRING_SQ,
834 // PHPColorProvider.STRING_SQ);
835 PreferenceConverter.setDefault(store, PHP_DEFAULT,
836 PHPColorProvider.DEFAULT);
837 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD,
838 PHPColorProvider.PHPDOC_KEYWORD);
839 PreferenceConverter.setDefault(store, PHPDOC_TAG,
840 PHPColorProvider.PHPDOC_TAG);
841 PreferenceConverter.setDefault(store, PHPDOC_LINK,
842 PHPColorProvider.PHPDOC_LINK);
843 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT,
844 PHPColorProvider.PHPDOC_DEFAULT);
846 PreferenceConverter.setDefault(store, EDITOR_PHP_KEYWORD_RETURN_COLOR,
847 new RGB(127, 0, 85));
848 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_BOLD, true);
849 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_ITALIC, false);
851 PreferenceConverter.setDefault(store, EDITOR_PHP_OPERATOR_COLOR,
853 store.setDefault(EDITOR_PHP_OPERATOR_BOLD, false);
854 store.setDefault(EDITOR_PHP_OPERATOR_ITALIC, false);
856 PreferenceConverter.setDefault(store, EDITOR_PHP_BRACE_OPERATOR_COLOR,
858 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_BOLD, false);
859 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_ITALIC, false);
860 // PreferenceConverter.setDefault(
862 // PHP_EDITOR_BACKGROUND,
863 // PHPColorProvider.BACKGROUND);
864 // PreferenceConverter.setDefault(
866 // LINKED_POSITION_COLOR,
867 // PHPColorProvider.LINKED_POSITION_COLOR);
868 // PreferenceConverter.setDefault(
870 // LINE_NUMBER_COLOR,
871 // PHPColorProvider.LINE_NUMBER_COLOR);
872 // // set default PHPDoc colors:
873 // PreferenceConverter.setDefault(
876 // PHPColorProvider.PHPDOC_KEYWORD);
877 // PreferenceConverter.setDefault(
880 // PHPColorProvider.PHPDOC_LINK);
881 // PreferenceConverter.setDefault(
884 // PHPColorProvider.PHPDOC_DEFAULT);
885 // PreferenceConverter.setDefault(
888 // PHPColorProvider.PHPDOC_TAG);
889 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
890 // PreferenceConverter.setDefault(
892 // PREFERENCE_COLOR_BACKGROUND,
893 // PHPColorProvider.BACKGROUND_COLOR);
895 // store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
896 // store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
897 // store.setDefault(RESOURCE_BUNDLE_DE, "false");
898 // store.setDefault(RESOURCE_BUNDLE_FR, "false");
899 // store.setDefault(RESOURCE_BUNDLE_ES, "false");
900 // TemplatePreferencePage.initDefaults(store);
901 // this will initialize the static fields in the syntaxrdr class
903 JavaCore.initializeDefaultPluginPreferences();
904 PreferenceConstants.initializeDefaultValues(store);
905 // externalTools.initializeDefaultPreferences(store);
906 MarkerAnnotationPreferences.initializeDefaultValues(store);
909 private IWorkbenchPage internalGetActivePage() {
910 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
912 return window.getActivePage();
916 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
917 if (fImageDescriptorRegistry == null)
918 fImageDescriptorRegistry = new ImageDescriptorRegistry();
919 return fImageDescriptorRegistry;
923 * Open a file in the Workbench that may or may not exist in the workspace.
924 * Must be run on the UI thread.
927 * @throws CoreException
929 public ITextEditor openFileInTextEditor(String filename)
930 throws CoreException {
931 // reject directories
932 if (new File(filename).isDirectory())
934 IWorkbench workbench = PlatformUI.getWorkbench();
935 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
936 IWorkbenchPage page = window.getActivePage();
937 IPath path = new Path(filename);
938 // If the file exists in the workspace, open it
939 IFile file = getWorkspace().getRoot().getFileForLocation(path);
941 ITextEditor textEditor;
942 if (file != null && file.exists()) {
943 editor = IDE.openEditor(page, file, true);
944 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
946 // Otherwise open the stream directly
949 FileStorage storage = new FileStorage(path);
950 IEditorRegistry registry = getWorkbench().getEditorRegistry();
951 IEditorDescriptor desc = registry.getDefaultEditor(filename);
954 .findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
955 // desc = registry.getDefaultEditor();
957 IEditorInput input = new ExternalEditorInput(storage);
958 editor = page.openEditor(input, desc.getId());
959 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
960 // If the storage provider is not ours, we can't guarantee
962 if (textEditor != null) {
963 IDocumentProvider documentProvider = textEditor
964 .getDocumentProvider();
965 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
966 storage.setReadOnly();
974 * Open a file in the Workbench that may or may not exist in the workspace.
975 * Must be run on the UI thread.
979 * @throws CoreException
981 public void openFileAndGotoLine(String filename, int line)
982 throws CoreException {
983 ITextEditor textEditor = openFileInTextEditor(filename);
984 if (textEditor != null) {
985 // If a line number was given, go to it
988 line--; // document is 0 based
989 IDocument document = textEditor.getDocumentProvider()
990 .getDocument(textEditor.getEditorInput());
991 textEditor.selectAndReveal(document.getLineOffset(line),
992 document.getLineLength(line));
993 } catch (BadLocationException e) {
994 // invalid text position -> do nothing
1001 * Open a file in the Workbench that may or may not exist in the workspace.
1002 * Must be run on the UI thread.
1006 * @throws CoreException
1008 public void openFileAndGotoOffset(String filename, int offset, int length)
1009 throws CoreException {
1010 ITextEditor textEditor = openFileInTextEditor(filename);
1011 if (textEditor != null) {
1012 // If a line number was given, go to it
1014 IDocument document = textEditor.getDocumentProvider()
1015 .getDocument(textEditor.getEditorInput());
1016 textEditor.selectAndReveal(offset, length);
1021 public void openFileAndFindString(String filename, String findString)
1022 throws CoreException {
1023 ITextEditor textEditor = openFileInTextEditor(filename);
1024 if (textEditor != null) {
1025 // If a string was given, go to it
1026 if (findString != null) {
1028 IDocument document = textEditor.getDocumentProvider()
1029 .getDocument(textEditor.getEditorInput());
1030 int offset = document.search(0, findString, true, false,
1032 textEditor.selectAndReveal(offset, findString.length());
1033 } catch (BadLocationException e) {
1034 // invalid text position -> do nothing
1040 public void setLastEditorFile(IFile textEditor) {
1041 this.fLastEditorFile = textEditor;
1045 * @see org.eclipse.core.runtime.Plugin#stop
1047 public void stop(BundleContext context) throws Exception {
1049 // JavaCore.stop(this, context);
1050 plugin.savePluginPreferences();
1051 IWorkspace workspace = ResourcesPlugin.getWorkspace();
1052 workspace.removeResourceChangeListener(JavaModelManager
1053 .getJavaModelManager().deltaState);
1054 workspace.removeSaveParticipant(plugin);
1056 JavaModelManager.getJavaModelManager().shutdown();
1058 // save the information from the php index files if necessary
1059 Collection collection = fIndexManagerMap.values();
1060 Iterator iterator = collection.iterator();
1061 IdentifierIndexManager indexManager = null;
1062 while (iterator.hasNext()) {
1063 indexManager = (IdentifierIndexManager) iterator.next();
1064 indexManager.writeFile();
1066 if (fImageDescriptorRegistry != null)
1067 fImageDescriptorRegistry.dispose();
1069 // AllTypesCache.terminate();
1071 if (fImageDescriptorRegistry != null)
1072 fImageDescriptorRegistry.dispose();
1074 unregisterAdapters();
1076 // if (fASTProvider != null) {
1077 // fASTProvider.dispose();
1078 // fASTProvider= null;
1081 if (fWorkingCopyManager != null) {
1082 fWorkingCopyManager.shutdown();
1083 fWorkingCopyManager = null;
1086 if (fCompilationUnitDocumentProvider != null) {
1087 fCompilationUnitDocumentProvider.shutdown();
1088 fCompilationUnitDocumentProvider = null;
1091 if (fJavaTextTools != null) {
1092 fJavaTextTools.dispose();
1093 fJavaTextTools = null;
1095 // JavaDocLocations.shutdownJavadocLocations();
1097 uninstallPreferenceStoreBackwardsCompatibility();
1099 // RefactoringCore.getUndoManager().shutdown();
1101 super.stop(context);
1106 * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
1108 // public void shutdown() throws CoreException {
1109 // // moved down (see below):
1110 // // super.shutdown();
1111 // // externalTools.shutDown();
1112 // ColorManager.getDefault().dispose();
1113 // // save the information from the php index files if necessary
1114 // Collection collection = fIndexManagerMap.values();
1115 // Iterator iterator = collection.iterator();
1116 // IdentifierIndexManager indexManager = null;
1117 // while (iterator.hasNext()) {
1118 // indexManager = (IdentifierIndexManager) iterator.next();
1119 // indexManager.writeFile();
1121 // if (fImageDescriptorRegistry != null)
1122 // fImageDescriptorRegistry.dispose();
1123 // // unregisterAdapters();
1124 // super.shutdown();
1125 // if (fWorkingCopyManager != null) {
1126 // fWorkingCopyManager.shutdown();
1127 // fWorkingCopyManager = null;
1129 // if (fCompilationUnitDocumentProvider != null) {
1130 // fCompilationUnitDocumentProvider.shutdown();
1131 // fCompilationUnitDocumentProvider = null;
1133 // if (fJavaTextTools != null) {
1134 // fJavaTextTools.dispose();
1135 // fJavaTextTools = null;
1137 // // JavaDocLocations.shutdownJavadocLocations();
1140 // JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
1141 // // begin JavaCore#shutdown()
1142 // //savePluginPreferences();
1143 // savePluginPreferences();
1144 // IWorkspace workspace = ResourcesPlugin.getWorkspace();
1145 // workspace.removeResourceChangeListener(JavaModelManager.getJavaModelManager().deltaState);
1146 // workspace.removeSaveParticipant(this);
1147 // ((JavaModelManager) JavaModelManager.getJavaModelManager()).shutdown();
1148 // // end JavaCore#shutdown()
1151 * Installs backwards compatibility for the preference store.
1153 private void installPreferenceStoreBackwardsCompatibility() {
1156 * Installs backwards compatibility: propagate the Java editor font from
1157 * a pre-2.1 plug-in to the Platform UI's preference store to preserve
1158 * the Java editor font from a pre-2.1 workspace. This is done only
1161 String fontPropagatedKey = "fontPropagated"; //$NON-NLS-1$
1162 if (getPreferenceStore().contains(JFaceResources.TEXT_FONT)
1163 && !getPreferenceStore().isDefault(JFaceResources.TEXT_FONT)) {
1164 if (!getPreferenceStore().getBoolean(fontPropagatedKey))
1166 .setValue(PlatformUI.getWorkbench()
1167 .getPreferenceStore(),
1168 PreferenceConstants.EDITOR_TEXT_FONT,
1169 PreferenceConverter.getFontDataArray(
1170 getPreferenceStore(),
1171 JFaceResources.TEXT_FONT));
1173 getPreferenceStore().setValue(fontPropagatedKey, true);
1176 * Backwards compatibility: set the Java editor font in this plug-in's
1177 * preference store to let older versions access it. Since 2.1 the Java
1178 * editor font is managed by the workbench font preference page.
1180 PreferenceConverter.putValue(getPreferenceStore(),
1181 JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry()
1182 .getFontData(PreferenceConstants.EDITOR_TEXT_FONT));
1184 fFontPropertyChangeListener = new IPropertyChangeListener() {
1185 public void propertyChange(PropertyChangeEvent event) {
1186 if (PreferenceConstants.EDITOR_TEXT_FONT.equals(event
1188 PreferenceConverter.putValue(getPreferenceStore(),
1189 JFaceResources.TEXT_FONT,
1190 JFaceResources.getFontRegistry().getFontData(
1191 PreferenceConstants.EDITOR_TEXT_FONT));
1194 JFaceResources.getFontRegistry().addListener(
1195 fFontPropertyChangeListener);
1198 * Backwards compatibility: propagate the Java editor tab width from a
1199 * pre-3.0 plug-in to the new preference key. This is done only once.
1201 // final String oldTabWidthKey = PreferenceConstants.EDITOR_TAB_WIDTH;
1202 // final String newTabWidthKey =
1203 // AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH;
1204 // String tabWidthPropagatedKey = "tabWidthPropagated"; //$NON-NLS-1$
1205 // if (getPreferenceStore().contains(oldTabWidthKey) &&
1206 // !getPreferenceStore().isDefault(oldTabWidthKey)) {
1207 // if (!getPreferenceStore().getBoolean(tabWidthPropagatedKey))
1208 // getPreferenceStore().setValue(newTabWidthKey,
1209 // getPreferenceStore().getInt(oldTabWidthKey));
1211 // getPreferenceStore().setValue(tabWidthPropagatedKey, true);
1214 // * Backwards compatibility: set the Java editor tab width in this
1215 // plug-in's preference store with the old key to let older
1216 // * versions access it. Since 3.0 the tab width is managed by the
1217 // extended texteditor and uses a new key.
1219 // getPreferenceStore().putValue(oldTabWidthKey,
1220 // getPreferenceStore().getString(newTabWidthKey));
1221 // fPropertyChangeListener = new IPropertyChangeListener() {
1222 // public void propertyChange(PropertyChangeEvent event) {
1223 // if (newTabWidthKey.equals(event.getProperty()))
1224 // getPreferenceStore().putValue(oldTabWidthKey,
1225 // getPreferenceStore().getString(newTabWidthKey));
1228 // getPreferenceStore().addPropertyChangeListener(fPropertyChangeListener);
1230 * Backward compatibility for the refactoring preference key.
1232 // getPreferenceStore().setValue(
1233 // PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD,
1234 // RefactoringCore.getConditionCheckingFailedSeverity());
1238 * Uninstalls backwards compatibility for the preference store.
1240 private void uninstallPreferenceStoreBackwardsCompatibility() {
1241 JFaceResources.getFontRegistry().removeListener(
1242 fFontPropertyChangeListener);
1243 // getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
1247 * (non - Javadoc) Method declared in Plugin
1249 public void start(BundleContext context) throws Exception {
1250 super.start(context);
1252 // JavaCore.start(this, context);
1253 final JavaModelManager modelManager = JavaModelManager
1254 .getJavaModelManager();
1256 modelManager.configurePluginDebugOptions();
1258 // request state folder creation (workaround 19885)
1259 // JavaCore.getPlugin().getStateLocation();
1261 // retrieve variable values
1262 PHPeclipsePlugin.getDefault().getPluginPreferences()
1263 .addPropertyChangeListener(
1264 new JavaModelManager.PluginPreferencesListener());
1265 // manager.loadVariablesAndContainers();
1267 final IWorkspace workspace = ResourcesPlugin.getWorkspace();
1268 workspace.addResourceChangeListener(modelManager.deltaState,
1269 IResourceChangeEvent.PRE_BUILD
1270 | IResourceChangeEvent.POST_BUILD
1271 | IResourceChangeEvent.POST_CHANGE
1272 | IResourceChangeEvent.PRE_DELETE
1273 | IResourceChangeEvent.PRE_CLOSE);
1276 ISavedState savedState = workspace.addSaveParticipant(
1277 PHPeclipsePlugin.this, modelManager);
1279 // process deltas since last activated in indexer thread so that
1280 // indexes are up-to-date.
1281 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658
1282 Job processSavedState = new Job(Util.bind("savedState.jobName")) { //$NON-NLS-1$
1283 protected IStatus run(IProgressMonitor monitor) {
1285 // add save participant and process delta atomically
1287 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=59937
1288 workspace.run(new IWorkspaceRunnable() {
1289 public void run(IProgressMonitor progress)
1290 throws CoreException {
1291 ISavedState savedState = workspace
1292 .addSaveParticipant(
1293 PHPeclipsePlugin.this,
1295 if (savedState != null) {
1296 // the event type coming from the saved
1297 // state is always POST_AUTO_BUILD
1298 // force it to be POST_CHANGE so that the
1299 // delta processor can handle it
1300 modelManager.deltaState.getDeltaProcessor().overridenEventType = IResourceChangeEvent.POST_CHANGE;
1302 .processResourceChangeEvents(modelManager.deltaState);
1306 } catch (CoreException e) {
1307 return e.getStatus();
1309 return Status.OK_STATUS;
1312 processSavedState.setSystem(true);
1313 processSavedState.setPriority(Job.SHORT); // process asap
1314 processSavedState.schedule();
1315 } catch (RuntimeException e) {
1316 modelManager.shutdown();
1322 // if (USE_WORKING_COPY_OWNERS) {
1323 WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
1324 public IBuffer createBuffer(ICompilationUnit workingCopy) {
1325 ICompilationUnit original = workingCopy.getPrimary();
1326 IResource resource = original.getResource();
1327 if (resource instanceof IFile)
1328 return new DocumentAdapter(workingCopy, (IFile) resource);
1329 return DocumentAdapter.NULL;
1334 installPreferenceStoreBackwardsCompatibility();
1338 // registerAdapters();
1340 // // externalTools.startUp();
1341 // getStandardDisplay().asyncExec(new Runnable() {
1342 // public void run() {
1343 // //initialize the variable context manager
1344 // VariableContextManager.getDefault();
1348 // // if (USE_WORKING_COPY_OWNERS) {
1349 // WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
1350 // public IBuffer createBuffer(ICompilationUnit workingCopy) {
1351 // ICompilationUnit original = workingCopy.getPrimary();
1352 // IResource resource = original.getResource();
1353 // if (resource instanceof IFile)
1354 // return new DocumentAdapter(workingCopy, (IFile) resource);
1355 // return DocumentAdapter.NULL;
1360 // installPreferenceStoreBackwardsCompatibility();
1362 // AllTypesCache.initialize();
1364 // Initialize AST provider
1365 // getASTProvider();
1368 // public void startup() throws CoreException {
1370 // // begin JavaCore.startup();
1371 // JavaModelManager manager = JavaModelManager.getJavaModelManager();
1373 // manager.configurePluginDebugOptions();
1374 // // request state folder creation (workaround 19885)
1375 // // JavaCore.getPlugin().getStateLocation();
1376 // getStateLocation();
1377 // // retrieve variable values
1379 // JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new
1380 // // JavaModelManager.PluginPreferencesListener());
1381 // getPluginPreferences().addPropertyChangeListener(
1382 // new JavaModelManager.PluginPreferencesListener());
1384 // // manager.loadVariablesAndContainers();
1385 // final IWorkspace workspace = ResourcesPlugin.getWorkspace();
1386 // workspace.addResourceChangeListener(
1387 // manager.deltaState,
1388 // IResourceChangeEvent.PRE_BUILD
1389 // | IResourceChangeEvent.POST_BUILD
1390 // | IResourceChangeEvent.POST_CHANGE
1391 // | IResourceChangeEvent.PRE_DELETE
1392 // | IResourceChangeEvent.PRE_CLOSE);
1393 // // startIndexing();
1394 // workspace.addSaveParticipant(PHPeclipsePlugin.getDefault(), manager);
1395 // } catch (CoreException e) {
1396 // } catch (RuntimeException e) {
1397 // manager.shutdown();
1400 // // end JavaCore.startup();
1401 // IAdapterManager platformManager = Platform.getAdapterManager();
1402 // platformManager.registerAdapters(new PHPElementAdapterFactory(),
1403 // PHPElement.class);
1404 // platformManager.registerAdapters(new ResourceAdapterFactory(),
1405 // IResource.class);
1406 // // externalTools.startUp();
1407 // getStandardDisplay().asyncExec(new Runnable() {
1408 // public void run() {
1409 // //initialize the variable context manager
1410 // VariableContextManager.getDefault();
1415 private void registerAdapters() {
1416 fJavaElementAdapterFactory = new JavaElementAdapterFactory();
1417 // fMarkerAdapterFactory= new MarkerAdapterFactory();
1418 // fEditorInputAdapterFactory= new EditorInputAdapterFactory();
1419 fResourceAdapterFactory = new ResourceAdapterFactory();
1420 // fLogicalPackageAdapterFactory= new LogicalPackageAdapterFactory();
1422 IAdapterManager manager = Platform.getAdapterManager();
1424 .registerAdapters(fJavaElementAdapterFactory,
1425 IJavaElement.class);
1426 // manager.registerAdapters(fMarkerAdapterFactory, IMarker.class);
1427 // manager.registerAdapters(fEditorInputAdapterFactory,
1428 // IEditorInput.class);
1429 manager.registerAdapters(fResourceAdapterFactory, IResource.class);
1430 // manager.registerAdapters(fLogicalPackageAdapterFactory,
1431 // LogicalPackage.class);
1434 private void unregisterAdapters() {
1435 IAdapterManager manager = Platform.getAdapterManager();
1436 manager.unregisterAdapters(fJavaElementAdapterFactory);
1437 // manager.unregisterAdapters(fMarkerAdapterFactory);
1438 // manager.unregisterAdapters(fEditorInputAdapterFactory);
1439 manager.unregisterAdapters(fResourceAdapterFactory);
1440 // manager.unregisterAdapters(fLogicalPackageAdapterFactory);
1444 * Returns a combined preference store, this store is read-only.
1446 * @return the combined preference store
1450 public IPreferenceStore getCombinedPreferenceStore() {
1451 if (fCombinedPreferenceStore == null) {
1452 IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
1453 fCombinedPreferenceStore = new ChainedPreferenceStore(
1454 new IPreferenceStore[] {
1455 getPreferenceStore(),
1456 new PreferencesAdapter(PHPeclipsePlugin
1457 .getDefault().getPluginPreferences()),
1458 generalTextStore });
1460 return fCombinedPreferenceStore;
1463 public synchronized IBufferFactory getBufferFactory() {
1464 if (fBufferFactory == null)
1465 fBufferFactory = new CustomBufferFactory();
1466 return fBufferFactory;
1470 * Returns the registry of the extensions to the
1471 * <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code>
1474 * @return the registry of contributed
1475 * <code>IJavaFoldingStructureProvider</code>
1478 public synchronized JavaFoldingStructureProviderRegistry getFoldingStructureProviderRegistry() {
1479 if (fFoldingStructureProviderRegistry == null)
1480 fFoldingStructureProviderRegistry = new JavaFoldingStructureProviderRegistry();
1481 return fFoldingStructureProviderRegistry;
1485 * Runs the given action as an atomic Java model operation.
1487 * After running a method that modifies java elements, registered listeners
1488 * receive after-the-fact notification of what just transpired, in the form
1489 * of a element changed event. This method allows clients to call a number
1490 * of methods that modify java elements and only have element changed event
1491 * notifications reported at the end of the entire batch.
1494 * If this method is called outside the dynamic scope of another such call,
1495 * this method runs the action and then reports a single element changed
1496 * event describing the net effect of all changes done to java elements by
1500 * If this method is called in the dynamic scope of another such call, this
1501 * method simply runs the action.
1505 * the action to perform
1507 * a progress monitor, or <code>null</code> if progress
1508 * reporting and cancellation are not desired
1509 * @exception CoreException
1510 * if the operation failed.
1513 public static void run(IWorkspaceRunnable action, IProgressMonitor monitor)
1514 throws CoreException {
1515 run(action, ResourcesPlugin.getWorkspace().getRoot(), monitor);
1519 * Runs the given action as an atomic Java model operation.
1521 * After running a method that modifies java elements, registered listeners
1522 * receive after-the-fact notification of what just transpired, in the form
1523 * of a element changed event. This method allows clients to call a number
1524 * of methods that modify java elements and only have element changed event
1525 * notifications reported at the end of the entire batch.
1528 * If this method is called outside the dynamic scope of another such call,
1529 * this method runs the action and then reports a single element changed
1530 * event describing the net effect of all changes done to java elements by
1534 * If this method is called in the dynamic scope of another such call, this
1535 * method simply runs the action.
1538 * The supplied scheduling rule is used to determine whether this operation
1539 * can be run simultaneously with workspace changes in other threads. See
1540 * <code>IWorkspace.run(...)</code> for more details.
1544 * the action to perform
1546 * the scheduling rule to use when running this operation, or
1547 * <code>null</code> if there are no scheduling restrictions
1548 * for this operation.
1550 * a progress monitor, or <code>null</code> if progress
1551 * reporting and cancellation are not desired
1552 * @exception CoreException
1553 * if the operation failed.
1556 public static void run(IWorkspaceRunnable action, ISchedulingRule rule,
1557 IProgressMonitor monitor) throws CoreException {
1558 IWorkspace workspace = ResourcesPlugin.getWorkspace();
1559 if (workspace.isTreeLocked()) {
1560 new BatchOperation(action).run(monitor);
1562 // use IWorkspace.run(...) to ensure that a build will be done in
1564 workspace.run(new BatchOperation(action), rule,
1565 IWorkspace.AVOID_UPDATE, monitor);
1570 * Returns the template context type registry for the java plugin.
1572 * @return the template context type registry for the java plugin
1575 public ContextTypeRegistry getTemplateContextRegistry() {
1576 if (fContextTypeRegistry == null) {
1577 fContextTypeRegistry = new ContributionContextTypeRegistry();
1579 fContextTypeRegistry.addContextType(new JavaContextType());
1580 fContextTypeRegistry.addContextType(new JavaDocContextType());
1581 fContextTypeRegistry.addContextType(new HTMLContextType());
1584 return fContextTypeRegistry;
1588 * Returns the template store for the java editor templates.
1590 * @return the template store for the java editor templates
1593 public TemplateStore getTemplateStore() {
1594 if (fTemplateStore == null) {
1595 // boolean alreadyMigrated=
1596 // getPreferenceStore().getBoolean(TEMPLATES_MIGRATION_KEY);
1597 // if (alreadyMigrated)
1598 fTemplateStore = new ContributionTemplateStore(
1599 getTemplateContextRegistry(), getPreferenceStore(),
1602 // fTemplateStore= new
1603 // CompatibilityTemplateStore(getTemplateContextRegistry(),
1604 // getPreferenceStore(), TEMPLATES_KEY,
1605 // Templates.getInstance());
1606 // getPreferenceStore().setValue(TEMPLATES_MIGRATION_KEY, true);
1610 fTemplateStore.load();
1611 } catch (IOException e) {
1616 return fTemplateStore;
1620 * Returns the template context type registry for the code generation
1623 * @return the template context type registry for the code generation
1627 public ContextTypeRegistry getCodeTemplateContextRegistry() {
1628 if (fCodeTemplateContextTypeRegistry == null) {
1629 fCodeTemplateContextTypeRegistry = new ContributionContextTypeRegistry();
1631 CodeTemplateContextType
1632 .registerContextTypes(fCodeTemplateContextTypeRegistry);
1635 return fCodeTemplateContextTypeRegistry;
1639 * Returns the template store for the code generation templates.
1641 * @return the template store for the code generation templates
1644 public TemplateStore getCodeTemplateStore() {
1645 if (fCodeTemplateStore == null) {
1646 // boolean alreadyMigrated=
1647 // getPreferenceStore().getBoolean(CODE_TEMPLATES_MIGRATION_KEY);
1648 // if (alreadyMigrated)
1649 fCodeTemplateStore = new ContributionTemplateStore(
1650 getCodeTemplateContextRegistry(), getPreferenceStore(),
1651 CODE_TEMPLATES_KEY);
1653 // fCodeTemplateStore= new
1654 // CompatibilityTemplateStore(getCodeTemplateContextRegistry(),
1655 // getPreferenceStore(),
1656 // CODE_TEMPLATES_KEY, CodeTemplates.getInstance());
1657 // getPreferenceStore().setValue(CODE_TEMPLATES_MIGRATION_KEY,
1662 fCodeTemplateStore.load();
1663 } catch (IOException e) {
1667 // compatibility / bug fixing code for duplicated templates
1668 // TODO remove for 3.0
1669 // CompatibilityTemplateStore.pruneDuplicates(fCodeTemplateStore,
1673 return fCodeTemplateStore;