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.internal.core.BatchOperation;
32 import net.sourceforge.phpdt.internal.core.JavaModelManager;
33 import net.sourceforge.phpdt.internal.core.util.Util;
34 import net.sourceforge.phpdt.internal.corext.template.php.CodeTemplateContextType;
35 import net.sourceforge.phpdt.internal.corext.template.php.HTMLContextType;
36 import net.sourceforge.phpdt.internal.corext.template.php.JavaContextType;
37 import net.sourceforge.phpdt.internal.corext.template.php.JavaDocContextType;
38 import net.sourceforge.phpdt.internal.ui.IJavaStatusConstants;
39 import net.sourceforge.phpdt.internal.ui.JavaElementAdapterFactory;
40 import net.sourceforge.phpdt.internal.ui.ResourceAdapterFactory;
41 import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache;
42 import net.sourceforge.phpdt.internal.ui.preferences.MockupPreferenceStore;
43 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
44 import net.sourceforge.phpdt.internal.ui.text.folding.JavaFoldingStructureProviderRegistry;
45 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
46 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
47 import net.sourceforge.phpdt.internal.ui.viewsupport.ProblemMarkerManager;
48 import net.sourceforge.phpdt.ui.IContextMenuConstants;
49 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
50 import net.sourceforge.phpdt.ui.PreferenceConstants;
51 import net.sourceforge.phpdt.ui.text.JavaTextTools;
52 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
53 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
54 import net.sourceforge.phpeclipse.builder.FileStorage;
55 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
56 import net.sourceforge.phpeclipse.phpeditor.CustomBufferFactory;
57 import net.sourceforge.phpeclipse.phpeditor.DocumentAdapter;
58 import net.sourceforge.phpeclipse.phpeditor.ICompilationUnitDocumentProvider;
59 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
60 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
61 import net.sourceforge.phpeclipse.phpeditor.WorkingCopyManager;
62 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
64 import org.eclipse.core.resources.IFile;
65 import org.eclipse.core.resources.IProject;
66 import org.eclipse.core.resources.IResource;
67 import org.eclipse.core.resources.IResourceChangeEvent;
68 import org.eclipse.core.resources.ISavedState;
69 import org.eclipse.core.resources.IWorkspace;
70 import org.eclipse.core.resources.IWorkspaceRunnable;
71 import org.eclipse.core.resources.ResourcesPlugin;
72 import org.eclipse.core.runtime.CoreException;
73 import org.eclipse.core.runtime.IAdapterManager;
74 import org.eclipse.core.runtime.IConfigurationElement;
75 import org.eclipse.core.runtime.IPath;
76 import org.eclipse.core.runtime.IPluginDescriptor;
77 import org.eclipse.core.runtime.IProgressMonitor;
78 import org.eclipse.core.runtime.IStatus;
79 import org.eclipse.core.runtime.Path;
80 import org.eclipse.core.runtime.Platform;
81 import org.eclipse.core.runtime.Status;
82 import org.eclipse.core.runtime.jobs.ISchedulingRule;
83 import org.eclipse.core.runtime.jobs.Job;
84 import org.eclipse.jface.action.GroupMarker;
85 import org.eclipse.jface.action.IMenuManager;
86 import org.eclipse.jface.action.Separator;
87 import org.eclipse.jface.preference.IPreferenceStore;
88 import org.eclipse.jface.preference.PreferenceConverter;
89 import org.eclipse.jface.resource.JFaceResources;
90 import org.eclipse.jface.text.BadLocationException;
91 import org.eclipse.jface.text.IDocument;
92 import org.eclipse.jface.text.templates.ContextTypeRegistry;
93 import org.eclipse.jface.text.templates.persistence.TemplateStore;
94 import org.eclipse.jface.util.IPropertyChangeListener;
95 import org.eclipse.jface.util.PropertyChangeEvent;
96 import org.eclipse.swt.graphics.RGB;
97 import org.eclipse.swt.widgets.Display;
98 import org.eclipse.swt.widgets.Shell;
99 import org.eclipse.ui.IEditorDescriptor;
100 import org.eclipse.ui.IEditorInput;
101 import org.eclipse.ui.IEditorPart;
102 import org.eclipse.ui.IEditorRegistry;
103 import org.eclipse.ui.IWorkbench;
104 import org.eclipse.ui.IWorkbenchPage;
105 import org.eclipse.ui.IWorkbenchWindow;
106 import org.eclipse.ui.PlatformUI;
107 import org.eclipse.ui.editors.text.EditorsUI;
108 import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
109 import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
110 import org.eclipse.ui.ide.IDE;
111 import org.eclipse.ui.plugin.AbstractUIPlugin;
112 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
113 import org.eclipse.ui.texteditor.ConfigurationElementSorter;
114 import org.eclipse.ui.texteditor.IDocumentProvider;
115 import org.eclipse.ui.texteditor.ITextEditor;
116 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
117 import org.osgi.framework.BundleContext;
120 * The main plugin class to be used in the desktop.
122 public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceConstants {
124 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
126 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
127 public static final String ID_PERSPECTIVE = "net.sourceforge.phpeclipse.PHPPerspective"; //$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 t) {
564 log("PHPeclipsePlugin.internalErrorOccurred", t); //$NON-NLS-1$
567 public static void log(String message, Throwable t) {
568 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, t));
571 public static void logErrorMessage(String message) {
572 log(new Status(IStatus.ERROR, getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, null));
575 // private static void setJVM() {
576 // String osName = System.getProperty("os.name");
577 // if (osName.startsWith("Mac OS")) {
578 // String mrjVersion = System.getProperty("mrj.version");
579 // String majorMRJVersion = mrjVersion.substring(0, 3);
582 // double version = Double.valueOf(majorMRJVersion).doubleValue();
583 // if (version == 2) {
585 // } else if (version >= 2.1 && version < 3) {
587 // } else if (version == 3.0) {
589 // } else if (version >= 3.1) {
592 // } catch (NumberFormatException nfe) {
594 // } else if (osName.startsWith("Windows")) {
595 // if (osName.indexOf("9") != -1) {
603 // TODO: refactor this into a better method name !
604 public synchronized ICompilationUnitDocumentProvider getCompilationUnitDocumentProvider() {
605 if (fCompilationUnitDocumentProvider == null)
606 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
607 return fCompilationUnitDocumentProvider;
611 * Get the identifier index manager for the given project
614 * the current project
617 public IdentifierIndexManager getIndexManager(IProject iProject) {
618 IPath path = iProject.getWorkingLocation(PHPeclipsePlugin.PLUGIN_ID);
619 path = path.append("project.index");
620 String indexFilename = path.toString();
622 // IdentDB db = IdentDB.getInstance();
623 // } catch (ClassNotFoundException e) {
624 // e.printStackTrace();
625 // } catch (SQLException e) {
626 // e.printStackTrace();
628 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap.get(indexFilename);
629 if (indexManager == null) {
630 indexManager = new IdentifierIndexManager(indexFilename);
631 fIndexManagerMap.put(indexFilename, indexManager);
636 public synchronized IWorkingCopyManager getWorkingCopyManager() {
637 if (fWorkingCopyManager == null) {
638 ICompilationUnitDocumentProvider provider = getCompilationUnitDocumentProvider();
639 fWorkingCopyManager = new WorkingCopyManager(provider);
641 return fWorkingCopyManager;
644 public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
645 if (fMembersOrderPreferenceCache == null)
646 fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
647 return fMembersOrderPreferenceCache;
651 * Returns the mockup preference store for firing events and registering listeners on project setting changes. Temporary solution.
653 public MockupPreferenceStore getMockupPreferenceStore() {
654 if (fMockupPreferenceStore == null)
655 fMockupPreferenceStore = new MockupPreferenceStore();
657 return fMockupPreferenceStore;
660 public synchronized ProblemMarkerManager getProblemMarkerManager() {
661 if (fProblemMarkerManager == null)
662 fProblemMarkerManager = new ProblemMarkerManager();
663 return fProblemMarkerManager;
666 // public synchronized JavaTextTools getJavaTextTools() {
667 // if (fJavaTextTools == null)
668 // fJavaTextTools = new JavaTextTools(getPreferenceStore());
669 // return fJavaTextTools;
671 public synchronized JavaTextTools getJavaTextTools() {
672 if (fJavaTextTools == null)
673 fJavaTextTools = new JavaTextTools(getPreferenceStore(), JavaCore.getPlugin().getPluginPreferences());
674 return fJavaTextTools;
677 public IFile getLastEditorFile() {
678 return fLastEditorFile;
682 * Returns the string from the plugin's resource bundle, or 'key' if not found.
684 // public static String getResourceString(String key) {
685 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
687 // return bundle.getString(key);
688 // } catch (MissingResourceException e) {
693 * Returns the plugin's resource bundle,
695 // public ResourceBundle getResourceBundle() {
696 // return resourceBundle;
698 protected void initializeDefaultPreferences(IPreferenceStore store) {
699 String operatingSystem = Platform.getOS();
700 // maxosx, linux, solaris, win32,...
702 InputStream is = getDefault().openStream(
703 new Path("prefs/default_" + operatingSystem + ".properties"));
704 PropertyResourceBundle resourceBundle = new PropertyResourceBundle(is);
705 Enumeration enum = resourceBundle.getKeys();
707 while (enum.hasMoreElements()) {
708 key = (String)enum.nextElement();
709 store.setDefault(key, resourceBundle.getString( key ));
711 } catch (Exception e) {
712 // no default properties found
713 if (operatingSystem.equals(Platform.OS_WIN32)) {
714 // store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
715 // store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
716 // store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
717 // store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
718 // store.setDefault(XAMPP_START_PREF, "c:\\xampp\\xampp_start.exe");
719 // store.setDefault(XAMPP_STOP_PREF, "c:\\xampp\\xampp_stop.exe");
721 // ETC_HOSTS_PATH_PREF, "c:\\windows\\system32\\drivers\\etc\\hosts");
723 // store.setDefault(PHP_RUN_PREF, "/apache/php/php");
724 // store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
725 // store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
726 // store.setDefault(APACHE_RUN_PREF, "/apache/apache");
727 // store.setDefault(XAMPP_START_PREF, "xamp/xampp_start");
728 // store.setDefault(XAMPP_STOP_PREF, "xampp/xampp_stop");
730 // store.setDefault(MYSQL_PREF, "--standalone");
731 // store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
732 // store.setDefault(APACHE_STOP_PREF, "-k shutdown");
733 // store.setDefault(APACHE_RESTART_PREF, "-k restart");
734 // store.setDefault(MYSQL_START_BACKGROUND, "true");
735 // store.setDefault(APACHE_START_BACKGROUND, "true");
736 // store.setDefault(APACHE_STOP_BACKGROUND, "true");
737 // store.setDefault(APACHE_RESTART_BACKGROUND, "true");
740 // store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
741 // store.setDefault(PHP_OBFUSCATOR_DEFAULT, "c:\\temp");
742 // if (operatingSystem.equals(Platform.OS_WIN32)) {
743 // store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
744 // } else if (operatingSystem.equals(Platform.OS_MACOSX)) {
745 // store.setDefault(PHP_OBFUSCATOR_DEFAULT, "/tmp");
746 // TODO How do we start Safari on Mac OS X ?
747 // store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
749 // store.setDefault(PHP_OBFUSCATOR_DEFAULT, "/tmp");
750 // store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
753 store.setDefault(PHP_EXTENSION_PREFS, "php,php3,php4,php5,phtml,inc,module,class");
755 // store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
756 // store.setDefault(PHP_INTERNAL_PARSER, "false");
757 // store.setDefault(PHP_EXTERNAL_PARSER, "true");
758 // store.setDefault(PHP_PARSE_ON_SAVE, "true");
759 // show line numbers:
760 // store.setDefault(LINE_NUMBER_RULER, "false");
761 // store.setDefault(FORMATTER_TAB_SIZE, "4");
762 // php syntax highlighting
763 store.setDefault(PHP_USERDEF_XMLFILE, "");
764 //assume there is none chooA
765 // PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT, PHPColorProvider.MULTI_LINE_COMMENT);
766 // PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT, PHPColorProvider.SINGLE_LINE_COMMENT);
767 PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
768 PreferenceConverter.setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
769 PreferenceConverter.setDefault(store, PHP_VARIABLE, PHPColorProvider.VARIABLE);
770 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME, PHPColorProvider.FUNCTION_NAME);
771 PreferenceConverter.setDefault(store, PHP_CONSTANT, PHPColorProvider.CONSTANT);
772 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
773 // PreferenceConverter.setDefault(store, PHP_STRING_DQ, PHPColorProvider.STRING_DQ);
774 // store.setDefault(PHP_STRING_BOLD_DQ, true);
775 // PreferenceConverter.setDefault(store, PHP_STRING_SQ, PHPColorProvider.STRING_SQ);
776 PreferenceConverter.setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
777 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD, PHPColorProvider.PHPDOC_KEYWORD);
778 PreferenceConverter.setDefault(store, PHPDOC_TAG, PHPColorProvider.PHPDOC_TAG);
779 PreferenceConverter.setDefault(store, PHPDOC_LINK, PHPColorProvider.PHPDOC_LINK);
780 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT, PHPColorProvider.PHPDOC_DEFAULT);
782 PreferenceConverter.setDefault(store, EDITOR_PHP_KEYWORD_RETURN_COLOR, new RGB(127, 0, 85));
783 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_BOLD, true);
784 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_ITALIC, false);
786 PreferenceConverter.setDefault(store, EDITOR_PHP_OPERATOR_COLOR, new RGB(0, 0, 0));
787 store.setDefault(EDITOR_PHP_OPERATOR_BOLD, false);
788 store.setDefault(EDITOR_PHP_OPERATOR_ITALIC, false);
790 PreferenceConverter.setDefault(store, EDITOR_PHP_BRACE_OPERATOR_COLOR, new RGB(0, 0, 0));
791 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_BOLD, false);
792 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_ITALIC, false);
793 // PreferenceConverter.setDefault(
795 // PHP_EDITOR_BACKGROUND,
796 // PHPColorProvider.BACKGROUND);
797 // PreferenceConverter.setDefault(
799 // LINKED_POSITION_COLOR,
800 // PHPColorProvider.LINKED_POSITION_COLOR);
801 // PreferenceConverter.setDefault(
803 // LINE_NUMBER_COLOR,
804 // PHPColorProvider.LINE_NUMBER_COLOR);
805 // // set default PHPDoc colors:
806 // PreferenceConverter.setDefault(
809 // PHPColorProvider.PHPDOC_KEYWORD);
810 // PreferenceConverter.setDefault(
813 // PHPColorProvider.PHPDOC_LINK);
814 // PreferenceConverter.setDefault(
817 // PHPColorProvider.PHPDOC_DEFAULT);
818 // PreferenceConverter.setDefault(
821 // PHPColorProvider.PHPDOC_TAG);
822 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
823 // PreferenceConverter.setDefault(
825 // PREFERENCE_COLOR_BACKGROUND,
826 // PHPColorProvider.BACKGROUND_COLOR);
828 // store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
829 // store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
830 // store.setDefault(RESOURCE_BUNDLE_DE, "false");
831 // store.setDefault(RESOURCE_BUNDLE_FR, "false");
832 // store.setDefault(RESOURCE_BUNDLE_ES, "false");
833 // TemplatePreferencePage.initDefaults(store);
834 //this will initialize the static fields in the syntaxrdr class
836 JavaCore.initializeDefaultPluginPreferences();
837 PreferenceConstants.initializeDefaultValues(store);
838 // externalTools.initializeDefaultPreferences(store);
839 MarkerAnnotationPreferences.initializeDefaultValues(store);
842 private IWorkbenchPage internalGetActivePage() {
843 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
845 return window.getActivePage();
849 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
850 if (fImageDescriptorRegistry == null)
851 fImageDescriptorRegistry = new ImageDescriptorRegistry();
852 return fImageDescriptorRegistry;
856 * Open a file in the Workbench that may or may not exist in the workspace. Must be run on the UI thread.
859 * @throws CoreException
861 public ITextEditor openFileInTextEditor(String filename) throws CoreException {
862 // reject directories
863 if (new File(filename).isDirectory())
865 IWorkbench workbench = PlatformUI.getWorkbench();
866 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
867 IWorkbenchPage page = window.getActivePage();
868 IPath path = new Path(filename);
869 // If the file exists in the workspace, open it
870 IFile file = getWorkspace().getRoot().getFileForLocation(path);
872 ITextEditor textEditor;
873 if (file != null && file.exists()) {
874 editor = IDE.openEditor(page, file, true);
875 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
877 // Otherwise open the stream directly
880 FileStorage storage = new FileStorage(path);
881 IEditorRegistry registry = getWorkbench().getEditorRegistry();
882 IEditorDescriptor desc = registry.getDefaultEditor(filename);
884 desc = registry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
885 // desc = registry.getDefaultEditor();
887 IEditorInput input = new ExternalEditorInput(storage);
888 editor = page.openEditor(input, desc.getId());
889 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
890 // If the storage provider is not ours, we can't guarantee read/write.
891 if (textEditor != null) {
892 IDocumentProvider documentProvider = textEditor.getDocumentProvider();
893 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
894 storage.setReadOnly();
902 * Open a file in the Workbench that may or may not exist in the workspace. Must be run on the UI thread.
906 * @throws CoreException
908 public void openFileAndGotoLine(String filename, int line) throws CoreException {
909 ITextEditor textEditor = openFileInTextEditor(filename);
910 if (textEditor != null) {
911 // If a line number was given, go to it
914 line--; // document is 0 based
915 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
916 textEditor.selectAndReveal(document.getLineOffset(line), document.getLineLength(line));
917 } catch (BadLocationException e) {
918 // invalid text position -> do nothing
925 * Open a file in the Workbench that may or may not exist in the workspace. Must be run on the UI thread.
929 * @throws CoreException
931 public void openFileAndGotoOffset(String filename, int offset, int length) throws CoreException {
932 ITextEditor textEditor = openFileInTextEditor(filename);
933 if (textEditor != null) {
934 // If a line number was given, go to it
936 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
937 textEditor.selectAndReveal(offset, length);
942 public void openFileAndFindString(String filename, String findString) throws CoreException {
943 ITextEditor textEditor = openFileInTextEditor(filename);
944 if (textEditor != null) {
945 // If a string was given, go to it
946 if (findString != null) {
948 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
949 int offset = document.search(0, findString, true, false, true);
950 textEditor.selectAndReveal(offset, findString.length());
951 } catch (BadLocationException e) {
952 // invalid text position -> do nothing
958 public void setLastEditorFile(IFile textEditor) {
959 this.fLastEditorFile = textEditor;
963 * @see org.eclipse.core.runtime.Plugin#stop
965 public void stop(BundleContext context) throws Exception {
967 // JavaCore.stop(this, context);
968 plugin.savePluginPreferences();
969 IWorkspace workspace = ResourcesPlugin.getWorkspace();
970 workspace.removeResourceChangeListener(JavaModelManager.getJavaModelManager().deltaState);
971 workspace.removeSaveParticipant(plugin);
973 JavaModelManager.getJavaModelManager().shutdown();
975 ColorManager.getDefault().dispose();
976 // save the information from the php index files if necessary
977 Collection collection = fIndexManagerMap.values();
978 Iterator iterator = collection.iterator();
979 IdentifierIndexManager indexManager = null;
980 while (iterator.hasNext()) {
981 indexManager = (IdentifierIndexManager) iterator.next();
982 indexManager.writeFile();
984 if (fImageDescriptorRegistry != null)
985 fImageDescriptorRegistry.dispose();
987 // AllTypesCache.terminate();
989 if (fImageDescriptorRegistry != null)
990 fImageDescriptorRegistry.dispose();
992 unregisterAdapters();
994 // if (fASTProvider != null) {
995 // fASTProvider.dispose();
996 // fASTProvider= null;
999 if (fWorkingCopyManager != null) {
1000 fWorkingCopyManager.shutdown();
1001 fWorkingCopyManager = null;
1004 if (fCompilationUnitDocumentProvider != null) {
1005 fCompilationUnitDocumentProvider.shutdown();
1006 fCompilationUnitDocumentProvider = null;
1009 if (fJavaTextTools != null) {
1010 fJavaTextTools.dispose();
1011 fJavaTextTools = null;
1013 // JavaDocLocations.shutdownJavadocLocations();
1015 uninstallPreferenceStoreBackwardsCompatibility();
1017 // RefactoringCore.getUndoManager().shutdown();
1019 super.stop(context);
1024 * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
1026 // public void shutdown() throws CoreException {
1027 // // moved down (see below):
1028 // // super.shutdown();
1029 // // externalTools.shutDown();
1030 // ColorManager.getDefault().dispose();
1031 // // save the information from the php index files if necessary
1032 // Collection collection = fIndexManagerMap.values();
1033 // Iterator iterator = collection.iterator();
1034 // IdentifierIndexManager indexManager = null;
1035 // while (iterator.hasNext()) {
1036 // indexManager = (IdentifierIndexManager) iterator.next();
1037 // indexManager.writeFile();
1039 // if (fImageDescriptorRegistry != null)
1040 // fImageDescriptorRegistry.dispose();
1041 // // unregisterAdapters();
1042 // super.shutdown();
1043 // if (fWorkingCopyManager != null) {
1044 // fWorkingCopyManager.shutdown();
1045 // fWorkingCopyManager = null;
1047 // if (fCompilationUnitDocumentProvider != null) {
1048 // fCompilationUnitDocumentProvider.shutdown();
1049 // fCompilationUnitDocumentProvider = null;
1051 // if (fJavaTextTools != null) {
1052 // fJavaTextTools.dispose();
1053 // fJavaTextTools = null;
1055 // // JavaDocLocations.shutdownJavadocLocations();
1058 // JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
1059 // // begin JavaCore#shutdown()
1060 // //savePluginPreferences();
1061 // savePluginPreferences();
1062 // IWorkspace workspace = ResourcesPlugin.getWorkspace();
1063 // workspace.removeResourceChangeListener(JavaModelManager.getJavaModelManager().deltaState);
1064 // workspace.removeSaveParticipant(this);
1065 // ((JavaModelManager) JavaModelManager.getJavaModelManager()).shutdown();
1066 // // end JavaCore#shutdown()
1069 * Installs backwards compatibility for the preference store.
1071 private void installPreferenceStoreBackwardsCompatibility() {
1074 * Installs backwards compatibility: propagate the Java editor font from a pre-2.1 plug-in to the Platform UI's preference store
1075 * to preserve the Java editor font from a pre-2.1 workspace. This is done only once.
1077 String fontPropagatedKey = "fontPropagated"; //$NON-NLS-1$
1078 if (getPreferenceStore().contains(JFaceResources.TEXT_FONT) && !getPreferenceStore().isDefault(JFaceResources.TEXT_FONT)) {
1079 if (!getPreferenceStore().getBoolean(fontPropagatedKey))
1080 PreferenceConverter.setValue(PlatformUI.getWorkbench().getPreferenceStore(), PreferenceConstants.EDITOR_TEXT_FONT,
1081 PreferenceConverter.getFontDataArray(getPreferenceStore(), JFaceResources.TEXT_FONT));
1083 getPreferenceStore().setValue(fontPropagatedKey, true);
1086 * Backwards compatibility: set the Java editor font in this plug-in's preference store to let older versions access it. Since
1087 * 2.1 the Java editor font is managed by the workbench font preference page.
1089 PreferenceConverter.putValue(getPreferenceStore(), JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry().getFontData(
1090 PreferenceConstants.EDITOR_TEXT_FONT));
1092 fFontPropertyChangeListener = new IPropertyChangeListener() {
1093 public void propertyChange(PropertyChangeEvent event) {
1094 if (PreferenceConstants.EDITOR_TEXT_FONT.equals(event.getProperty()))
1095 PreferenceConverter.putValue(getPreferenceStore(), JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry()
1096 .getFontData(PreferenceConstants.EDITOR_TEXT_FONT));
1099 JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
1102 * Backwards compatibility: propagate the Java editor tab width from a pre-3.0 plug-in to the new preference key. This is done
1105 // final String oldTabWidthKey = PreferenceConstants.EDITOR_TAB_WIDTH;
1106 // final String newTabWidthKey = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH;
1107 // String tabWidthPropagatedKey = "tabWidthPropagated"; //$NON-NLS-1$
1108 // if (getPreferenceStore().contains(oldTabWidthKey) && !getPreferenceStore().isDefault(oldTabWidthKey)) {
1109 // if (!getPreferenceStore().getBoolean(tabWidthPropagatedKey))
1110 // getPreferenceStore().setValue(newTabWidthKey, getPreferenceStore().getInt(oldTabWidthKey));
1112 // getPreferenceStore().setValue(tabWidthPropagatedKey, true);
1115 // * Backwards compatibility: set the Java editor tab width in this plug-in's preference store with the old key to let older
1116 // * versions access it. Since 3.0 the tab width is managed by the extended texteditor and uses a new key.
1118 // getPreferenceStore().putValue(oldTabWidthKey, getPreferenceStore().getString(newTabWidthKey));
1119 // fPropertyChangeListener = new IPropertyChangeListener() {
1120 // public void propertyChange(PropertyChangeEvent event) {
1121 // if (newTabWidthKey.equals(event.getProperty()))
1122 // getPreferenceStore().putValue(oldTabWidthKey, getPreferenceStore().getString(newTabWidthKey));
1125 // getPreferenceStore().addPropertyChangeListener(fPropertyChangeListener);
1127 * Backward compatibility for the refactoring preference key.
1129 // getPreferenceStore().setValue(
1130 // PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD,
1131 // RefactoringCore.getConditionCheckingFailedSeverity());
1135 * Uninstalls backwards compatibility for the preference store.
1137 private void uninstallPreferenceStoreBackwardsCompatibility() {
1138 JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
1139 // getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
1143 * (non - Javadoc) Method declared in Plugin
1145 public void start(BundleContext context) throws Exception {
1146 super.start(context);
1148 // JavaCore.start(this, context);
1149 final JavaModelManager manager = JavaModelManager.getJavaModelManager();
1151 manager.configurePluginDebugOptions();
1153 // request state folder creation (workaround 19885)
1154 // JavaCore.getPlugin().getStateLocation();
1156 // retrieve variable values
1157 PHPeclipsePlugin.getDefault().getPluginPreferences().addPropertyChangeListener(
1158 new JavaModelManager.PluginPreferencesListener());
1159 // manager.loadVariablesAndContainers();
1161 final IWorkspace workspace = ResourcesPlugin.getWorkspace();
1162 workspace.addResourceChangeListener(manager.deltaState, IResourceChangeEvent.PRE_BUILD | IResourceChangeEvent.POST_BUILD
1163 | IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.PRE_CLOSE);
1166 ISavedState savedState = workspace.addSaveParticipant(PHPeclipsePlugin.this, manager);
1168 // process deltas since last activated in indexer thread so that indexes are up-to-date.
1169 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658
1170 Job processSavedState = new Job(Util.bind("savedState.jobName")) { //$NON-NLS-1$
1171 protected IStatus run(IProgressMonitor monitor) {
1173 // add save participant and process delta atomically
1174 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59937
1175 workspace.run(new IWorkspaceRunnable() {
1176 public void run(IProgressMonitor progress) throws CoreException {
1177 ISavedState savedState = workspace.addSaveParticipant(PHPeclipsePlugin.this, manager);
1178 if (savedState != null) {
1179 // the event type coming from the saved state is always POST_AUTO_BUILD
1180 // force it to be POST_CHANGE so that the delta processor can handle it
1181 manager.deltaState.getDeltaProcessor().overridenEventType = IResourceChangeEvent.POST_CHANGE;
1182 savedState.processResourceChangeEvents(manager.deltaState);
1186 } catch (CoreException e) {
1187 return e.getStatus();
1189 return Status.OK_STATUS;
1192 processSavedState.setSystem(true);
1193 processSavedState.setPriority(Job.SHORT); // process asap
1194 processSavedState.schedule();
1195 } catch (RuntimeException e) {
1202 // if (USE_WORKING_COPY_OWNERS) {
1203 WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
1204 public IBuffer createBuffer(ICompilationUnit workingCopy) {
1205 ICompilationUnit original = workingCopy.getPrimary();
1206 IResource resource = original.getResource();
1207 if (resource instanceof IFile)
1208 return new DocumentAdapter(workingCopy, (IFile) resource);
1209 return DocumentAdapter.NULL;
1214 installPreferenceStoreBackwardsCompatibility();
1218 // registerAdapters();
1220 // // externalTools.startUp();
1221 // getStandardDisplay().asyncExec(new Runnable() {
1222 // public void run() {
1223 // //initialize the variable context manager
1224 // VariableContextManager.getDefault();
1228 // // if (USE_WORKING_COPY_OWNERS) {
1229 // WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
1230 // public IBuffer createBuffer(ICompilationUnit workingCopy) {
1231 // ICompilationUnit original = workingCopy.getPrimary();
1232 // IResource resource = original.getResource();
1233 // if (resource instanceof IFile)
1234 // return new DocumentAdapter(workingCopy, (IFile) resource);
1235 // return DocumentAdapter.NULL;
1240 // installPreferenceStoreBackwardsCompatibility();
1242 // AllTypesCache.initialize();
1244 // Initialize AST provider
1245 // getASTProvider();
1248 // public void startup() throws CoreException {
1250 // // begin JavaCore.startup();
1251 // JavaModelManager manager = JavaModelManager.getJavaModelManager();
1253 // manager.configurePluginDebugOptions();
1254 // // request state folder creation (workaround 19885)
1255 // // JavaCore.getPlugin().getStateLocation();
1256 // getStateLocation();
1257 // // retrieve variable values
1259 // JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new
1260 // // JavaModelManager.PluginPreferencesListener());
1261 // getPluginPreferences().addPropertyChangeListener(
1262 // new JavaModelManager.PluginPreferencesListener());
1264 // // manager.loadVariablesAndContainers();
1265 // final IWorkspace workspace = ResourcesPlugin.getWorkspace();
1266 // workspace.addResourceChangeListener(
1267 // manager.deltaState,
1268 // IResourceChangeEvent.PRE_BUILD
1269 // | IResourceChangeEvent.POST_BUILD
1270 // | IResourceChangeEvent.POST_CHANGE
1271 // | IResourceChangeEvent.PRE_DELETE
1272 // | IResourceChangeEvent.PRE_CLOSE);
1273 // // startIndexing();
1274 // workspace.addSaveParticipant(PHPeclipsePlugin.getDefault(), manager);
1275 // } catch (CoreException e) {
1276 // } catch (RuntimeException e) {
1277 // manager.shutdown();
1280 // // end JavaCore.startup();
1281 // IAdapterManager platformManager = Platform.getAdapterManager();
1282 // platformManager.registerAdapters(new PHPElementAdapterFactory(),
1283 // PHPElement.class);
1284 // platformManager.registerAdapters(new ResourceAdapterFactory(),
1285 // IResource.class);
1286 // // externalTools.startUp();
1287 // getStandardDisplay().asyncExec(new Runnable() {
1288 // public void run() {
1289 // //initialize the variable context manager
1290 // VariableContextManager.getDefault();
1295 private void registerAdapters() {
1296 fJavaElementAdapterFactory = new JavaElementAdapterFactory();
1297 // fMarkerAdapterFactory= new MarkerAdapterFactory();
1298 // fEditorInputAdapterFactory= new EditorInputAdapterFactory();
1299 fResourceAdapterFactory = new ResourceAdapterFactory();
1300 // fLogicalPackageAdapterFactory= new LogicalPackageAdapterFactory();
1302 IAdapterManager manager = Platform.getAdapterManager();
1303 manager.registerAdapters(fJavaElementAdapterFactory, IJavaElement.class);
1304 // manager.registerAdapters(fMarkerAdapterFactory, IMarker.class);
1305 // manager.registerAdapters(fEditorInputAdapterFactory, IEditorInput.class);
1306 manager.registerAdapters(fResourceAdapterFactory, IResource.class);
1307 // manager.registerAdapters(fLogicalPackageAdapterFactory,
1308 // LogicalPackage.class);
1311 private void unregisterAdapters() {
1312 IAdapterManager manager = Platform.getAdapterManager();
1313 manager.unregisterAdapters(fJavaElementAdapterFactory);
1314 // manager.unregisterAdapters(fMarkerAdapterFactory);
1315 // manager.unregisterAdapters(fEditorInputAdapterFactory);
1316 manager.unregisterAdapters(fResourceAdapterFactory);
1317 // manager.unregisterAdapters(fLogicalPackageAdapterFactory);
1321 * Returns a combined preference store, this store is read-only.
1323 * @return the combined preference store
1327 public IPreferenceStore getCombinedPreferenceStore() {
1328 if (fCombinedPreferenceStore == null) {
1329 IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
1330 fCombinedPreferenceStore = new ChainedPreferenceStore(new IPreferenceStore[] {
1331 getPreferenceStore(),
1332 new PreferencesAdapter(PHPeclipsePlugin.getDefault().getPluginPreferences()),
1333 generalTextStore });
1335 return fCombinedPreferenceStore;
1338 public synchronized IBufferFactory getBufferFactory() {
1339 if (fBufferFactory == null)
1340 fBufferFactory = new CustomBufferFactory();
1341 return fBufferFactory;
1345 * Returns the registry of the extensions to the <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code> extension
1348 * @return the registry of contributed <code>IJavaFoldingStructureProvider</code>
1351 public synchronized JavaFoldingStructureProviderRegistry getFoldingStructureProviderRegistry() {
1352 if (fFoldingStructureProviderRegistry == null)
1353 fFoldingStructureProviderRegistry = new JavaFoldingStructureProviderRegistry();
1354 return fFoldingStructureProviderRegistry;
1358 * Runs the given action as an atomic Java model operation.
1360 * After running a method that modifies java elements, registered listeners receive after-the-fact notification of what just
1361 * transpired, in the form of a element changed event. This method allows clients to call a number of methods that modify java
1362 * elements and only have element changed event notifications reported at the end of the entire batch.
1365 * If this method is called outside the dynamic scope of another such call, this method runs the action and then reports a single
1366 * element changed event describing the net effect of all changes done to java elements by the action.
1369 * If this method is called in the dynamic scope of another such call, this method simply runs the action.
1373 * the action to perform
1375 * a progress monitor, or <code>null</code> if progress reporting and cancellation are not desired
1376 * @exception CoreException
1377 * if the operation failed.
1380 public static void run(IWorkspaceRunnable action, IProgressMonitor monitor) throws CoreException {
1381 run(action, ResourcesPlugin.getWorkspace().getRoot(), monitor);
1385 * Runs the given action as an atomic Java model operation.
1387 * After running a method that modifies java elements, registered listeners receive after-the-fact notification of what just
1388 * transpired, in the form of a element changed event. This method allows clients to call a number of methods that modify java
1389 * elements and only have element changed event notifications reported at the end of the entire batch.
1392 * If this method is called outside the dynamic scope of another such call, this method runs the action and then reports a single
1393 * element changed event describing the net effect of all changes done to java elements by the action.
1396 * If this method is called in the dynamic scope of another such call, this method simply runs the action.
1399 * The supplied scheduling rule is used to determine whether this operation can be run simultaneously with workspace changes in
1400 * other threads. See <code>IWorkspace.run(...)</code> for more details.
1404 * the action to perform
1406 * the scheduling rule to use when running this operation, or <code>null</code> if there are no scheduling restrictions
1407 * for this operation.
1409 * a progress monitor, or <code>null</code> if progress reporting and cancellation are not desired
1410 * @exception CoreException
1411 * if the operation failed.
1414 public static void run(IWorkspaceRunnable action, ISchedulingRule rule, IProgressMonitor monitor) throws CoreException {
1415 IWorkspace workspace = ResourcesPlugin.getWorkspace();
1416 if (workspace.isTreeLocked()) {
1417 new BatchOperation(action).run(monitor);
1419 // use IWorkspace.run(...) to ensure that a build will be done in
1421 workspace.run(new BatchOperation(action), rule, IWorkspace.AVOID_UPDATE, monitor);
1426 * Returns the template context type registry for the java plugin.
1428 * @return the template context type registry for the java plugin
1431 public ContextTypeRegistry getTemplateContextRegistry() {
1432 if (fContextTypeRegistry == null) {
1433 fContextTypeRegistry = new ContributionContextTypeRegistry();
1435 fContextTypeRegistry.addContextType(new JavaContextType());
1436 fContextTypeRegistry.addContextType(new JavaDocContextType());
1437 fContextTypeRegistry.addContextType(new HTMLContextType());
1440 return fContextTypeRegistry;
1444 * Returns the template store for the java editor templates.
1446 * @return the template store for the java editor templates
1449 public TemplateStore getTemplateStore() {
1450 if (fTemplateStore == null) {
1451 // boolean alreadyMigrated= getPreferenceStore().getBoolean(TEMPLATES_MIGRATION_KEY);
1452 // if (alreadyMigrated)
1453 fTemplateStore = new ContributionTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), TEMPLATES_KEY);
1455 // fTemplateStore= new CompatibilityTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), TEMPLATES_KEY,
1456 // Templates.getInstance());
1457 // getPreferenceStore().setValue(TEMPLATES_MIGRATION_KEY, true);
1461 fTemplateStore.load();
1462 } catch (IOException e) {
1467 return fTemplateStore;
1471 * Returns the template context type registry for the code generation templates.
1473 * @return the template context type registry for the code generation templates
1476 public ContextTypeRegistry getCodeTemplateContextRegistry() {
1477 if (fCodeTemplateContextTypeRegistry == null) {
1478 fCodeTemplateContextTypeRegistry = new ContributionContextTypeRegistry();
1480 CodeTemplateContextType.registerContextTypes(fCodeTemplateContextTypeRegistry);
1483 return fCodeTemplateContextTypeRegistry;
1487 * Returns the template store for the code generation templates.
1489 * @return the template store for the code generation templates
1492 public TemplateStore getCodeTemplateStore() {
1493 if (fCodeTemplateStore == null) {
1494 // boolean alreadyMigrated= getPreferenceStore().getBoolean(CODE_TEMPLATES_MIGRATION_KEY);
1495 // if (alreadyMigrated)
1496 fCodeTemplateStore = new ContributionTemplateStore(getCodeTemplateContextRegistry(), getPreferenceStore(), CODE_TEMPLATES_KEY);
1498 // fCodeTemplateStore= new CompatibilityTemplateStore(getCodeTemplateContextRegistry(), getPreferenceStore(),
1499 // CODE_TEMPLATES_KEY, CodeTemplates.getInstance());
1500 // getPreferenceStore().setValue(CODE_TEMPLATES_MIGRATION_KEY, true);
1504 fCodeTemplateStore.load();
1505 } catch (IOException e) {
1509 // compatibility / bug fixing code for duplicated templates
1510 // TODO remove for 3.0
1511 // CompatibilityTemplateStore.pruneDuplicates(fCodeTemplateStore, true);
1514 return fCodeTemplateStore;