1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
8 **********************************************************************/
9 package net.sourceforge.phpeclipse;
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Enumeration;
17 import java.util.HashMap;
18 import java.util.HashSet;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.PropertyResourceBundle;
24 import net.sourceforge.phpdt.core.IBuffer;
25 import net.sourceforge.phpdt.core.IBufferFactory;
26 import net.sourceforge.phpdt.core.ICompilationUnit;
27 import net.sourceforge.phpdt.core.IJavaElement;
28 import net.sourceforge.phpdt.core.JavaCore;
29 import net.sourceforge.phpdt.core.WorkingCopyOwner;
30 import net.sourceforge.phpdt.externaltools.internal.model.ColorManager;
31 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsPlugin;
32 import net.sourceforge.phpdt.internal.core.BatchOperation;
33 import net.sourceforge.phpdt.internal.core.JavaModelManager;
34 import net.sourceforge.phpdt.internal.core.util.Util;
35 import net.sourceforge.phpdt.internal.corext.template.php.CodeTemplateContextType;
36 import net.sourceforge.phpdt.internal.corext.template.php.HTMLContextType;
37 import net.sourceforge.phpdt.internal.corext.template.php.JavaContextType;
38 import net.sourceforge.phpdt.internal.corext.template.php.JavaDocContextType;
39 import net.sourceforge.phpdt.internal.ui.IJavaStatusConstants;
40 import net.sourceforge.phpdt.internal.ui.JavaElementAdapterFactory;
41 import net.sourceforge.phpdt.internal.ui.ResourceAdapterFactory;
42 import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache;
43 import net.sourceforge.phpdt.internal.ui.preferences.MockupPreferenceStore;
44 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
45 import net.sourceforge.phpdt.internal.ui.text.folding.JavaFoldingStructureProviderRegistry;
46 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
47 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
48 import net.sourceforge.phpdt.internal.ui.viewsupport.ProblemMarkerManager;
49 import net.sourceforge.phpdt.ui.IContextMenuConstants;
50 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
51 import net.sourceforge.phpdt.ui.PreferenceConstants;
52 import net.sourceforge.phpdt.ui.text.JavaTextTools;
53 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
54 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
55 import net.sourceforge.phpeclipse.builder.FileStorage;
56 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
57 import net.sourceforge.phpeclipse.phpeditor.CustomBufferFactory;
58 import net.sourceforge.phpeclipse.phpeditor.DocumentAdapter;
59 import net.sourceforge.phpeclipse.phpeditor.ICompilationUnitDocumentProvider;
60 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
61 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
62 import net.sourceforge.phpeclipse.phpeditor.WorkingCopyManager;
63 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
65 import org.eclipse.core.resources.IFile;
66 import org.eclipse.core.resources.IProject;
67 import org.eclipse.core.resources.IResource;
68 import org.eclipse.core.resources.IResourceChangeEvent;
69 import org.eclipse.core.resources.ISavedState;
70 import org.eclipse.core.resources.IWorkspace;
71 import org.eclipse.core.resources.IWorkspaceRunnable;
72 import org.eclipse.core.resources.ResourcesPlugin;
73 import org.eclipse.core.runtime.CoreException;
74 import org.eclipse.core.runtime.IAdapterManager;
75 import org.eclipse.core.runtime.IConfigurationElement;
76 import org.eclipse.core.runtime.IPath;
77 import org.eclipse.core.runtime.IPluginDescriptor;
78 import org.eclipse.core.runtime.IProgressMonitor;
79 import org.eclipse.core.runtime.IStatus;
80 import org.eclipse.core.runtime.Path;
81 import org.eclipse.core.runtime.Platform;
82 import org.eclipse.core.runtime.Status;
83 import org.eclipse.core.runtime.jobs.ISchedulingRule;
84 import org.eclipse.core.runtime.jobs.Job;
85 import org.eclipse.jface.action.GroupMarker;
86 import org.eclipse.jface.action.IMenuManager;
87 import org.eclipse.jface.action.Separator;
88 import org.eclipse.jface.preference.IPreferenceStore;
89 import org.eclipse.jface.preference.PreferenceConverter;
90 import org.eclipse.jface.resource.JFaceResources;
91 import org.eclipse.jface.text.BadLocationException;
92 import org.eclipse.jface.text.IDocument;
93 import org.eclipse.jface.text.templates.ContextTypeRegistry;
94 import org.eclipse.jface.text.templates.persistence.TemplateStore;
95 import org.eclipse.jface.util.IPropertyChangeListener;
96 import org.eclipse.jface.util.PropertyChangeEvent;
97 import org.eclipse.swt.graphics.RGB;
98 import org.eclipse.swt.widgets.Display;
99 import org.eclipse.swt.widgets.Shell;
100 import org.eclipse.ui.IEditorDescriptor;
101 import org.eclipse.ui.IEditorInput;
102 import org.eclipse.ui.IEditorPart;
103 import org.eclipse.ui.IEditorRegistry;
104 import org.eclipse.ui.IWorkbench;
105 import org.eclipse.ui.IWorkbenchPage;
106 import org.eclipse.ui.IWorkbenchWindow;
107 import org.eclipse.ui.PlatformUI;
108 import org.eclipse.ui.editors.text.EditorsUI;
109 import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
110 import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
111 import org.eclipse.ui.ide.IDE;
112 import org.eclipse.ui.plugin.AbstractUIPlugin;
113 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
114 import org.eclipse.ui.texteditor.ConfigurationElementSorter;
115 import org.eclipse.ui.texteditor.IDocumentProvider;
116 import org.eclipse.ui.texteditor.ITextEditor;
117 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
118 import org.osgi.framework.BundleContext;
121 * The main plugin class to be used in the desktop.
123 public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceConstants {
125 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
127 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
128 public static final String ID_PERSPECTIVE = "net.sourceforge.phpeclipse.PHPPerspective"; //$NON-NLS-1$
133 * id of builder - matches plugin.xml (concatenate pluginid.builderid)
135 public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
137 //public static final String BUILDER_INDEX_ID = PLUGIN_ID + ".indexbuilder";
138 /** General debug flag */
140 public static final boolean DEBUG = false;
143 * The maximum number of allowed proposals by category
145 public final static int MAX_PROPOSALS = 200;
148 * The key to store customized templates.
152 private static final String TEMPLATES_KEY = "net.sourceforge.phpdt.ui.text.custom_templates"; //$NON-NLS-1$
155 * The key to store customized code templates.
159 private static final String CODE_TEMPLATES_KEY = "net.sourceforge.phpdt.ui.text.custom_code_templates"; //$NON-NLS-1$
162 * The key to store whether the legacy templates have been migrated
166 // private static final String TEMPLATES_MIGRATION_KEY= "net.sourceforge.phpdt.ui.text.templates_migrated"; //$NON-NLS-1$
168 * The key to store whether the legacy code templates have been migrated
172 // private static final String CODE_TEMPLATES_MIGRATION_KEY= "net.sourceforge.phpdt.ui.text.code_templates_migrated";
174 private static ExternalToolsPlugin externalTools;
177 * The Java virtual machine that we are running on.
179 // private static int jvm;
181 // private static final int MRJ_2_0 = 0;
183 // /** MRJ 2.1 or later */
184 // private static final int MRJ_2_1 = 1;
186 // /** Java on Mac OS X 10.0 (MRJ 3.0) */
187 // private static final int MRJ_3_0 = 3;
190 // private static final int MRJ_3_1 = 4;
192 // /** JVM constant for any other platform */
193 // private static final int OTHER = -1;
194 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID +
195 // ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
196 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID + ".ui.CodingActionSet"; //$NON-NLS-1$
198 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
200 public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
202 public static final String PHPPARSER_NEW = "test.PHPParser";
204 /** Change this if you want to switch PHP Parser. */
205 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
207 //The shared instance.
208 private static PHPeclipsePlugin plugin;
211 * The template context type registry for the java editor.
215 private ContextTypeRegistry fContextTypeRegistry;
218 * The code template context type registry for the java editor.
222 private ContextTypeRegistry fCodeTemplateContextTypeRegistry;
225 * The template store for the java editor.
229 private TemplateStore fTemplateStore;
232 * The coded template store for the java editor.
236 private TemplateStore fCodeTemplateStore;
239 private static final int WINDOWS_9x = 6;
242 private static final int WINDOWS_NT = 5;
244 private ImageDescriptorRegistry fImageDescriptorRegistry;
246 private HashMap fIndexManagerMap = new HashMap();
248 private IWorkingCopyManager fWorkingCopyManager;
250 private IBufferFactory fBufferFactory;
252 private ICompilationUnitDocumentProvider fCompilationUnitDocumentProvider;
254 private JavaTextTools fJavaTextTools;
256 private ProblemMarkerManager fProblemMarkerManager;
258 private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
260 private IFile fLastEditorFile = null;
262 private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
264 private JavaElementAdapterFactory fJavaElementAdapterFactory;
266 // private MarkerAdapterFactory fMarkerAdapterFactory;
267 // private EditorInputAdapterFactory fEditorInputAdapterFactory;
268 private ResourceAdapterFactory fResourceAdapterFactory;
270 // private LogicalPackageAdapterFactory fLogicalPackageAdapterFactory;
271 private IPropertyChangeListener fFontPropertyChangeListener;
274 * Property change listener on this plugin's preference store.
278 // private IPropertyChangeListener fPropertyChangeListener;
280 * The combined preference store.
284 private IPreferenceStore fCombinedPreferenceStore;
287 * The extension point registry for the <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code> extension point.
291 private JavaFoldingStructureProviderRegistry fFoldingStructureProviderRegistry;
294 * Mockup preference store for firing events and registering listeners on project setting changes. FIXME: Temporary solution.
298 private MockupPreferenceStore fMockupPreferenceStore;
303 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
306 externalTools = new ExternalToolsPlugin();
310 // ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
311 // } catch (MissingResourceException x) {
312 // resourceBundle = null;
317 // * Returns all Java editor text hovers contributed to the workbench.
319 // * @return an array of JavaEditorTextHoverDescriptor
322 // public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors()
324 // if (fJavaEditorTextHoverDescriptors == null)
325 // fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
326 // .getContributedHovers();
327 // return fJavaEditorTextHoverDescriptors;
330 * Returns all Java editor text hovers contributed to the workbench.
332 * @return an array of JavaEditorTextHoverDescriptor
335 public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
336 if (fJavaEditorTextHoverDescriptors == null) {
337 fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor.getContributedHovers();
338 ConfigurationElementSorter sorter = new ConfigurationElementSorter() {
340 * @see org.eclipse.ui.texteditor.ConfigurationElementSorter#getConfigurationElement(java.lang.Object)
342 public IConfigurationElement getConfigurationElement(Object object) {
343 return ((JavaEditorTextHoverDescriptor) object).getConfigurationElement();
346 sorter.sort(fJavaEditorTextHoverDescriptors);
348 // The Problem hover has to be the first and the Annotation hover has to
349 // be the last one in the JDT UI's hover list
350 int length = fJavaEditorTextHoverDescriptors.length;
352 int last = length - 1;
353 int problemHoverIndex = -1;
354 int annotationHoverIndex = -1;
355 for (int i = 0; i < length; i++) {
356 if (!fJavaEditorTextHoverDescriptors[i].getId().startsWith(PLUGIN_ID)) {
357 if (problemHoverIndex == -1 || annotationHoverIndex == -1)
367 if (fJavaEditorTextHoverDescriptors[i].getId().equals("net.sourceforge.phpdt.ui.AnnotationHover")) { //$NON-NLS-1$
368 annotationHoverIndex = i;
371 if (fJavaEditorTextHoverDescriptors[i].getId().equals("net.sourceforge.phpdt.ui.ProblemHover")) { //$NON-NLS-1$
372 problemHoverIndex = i;
377 JavaEditorTextHoverDescriptor hoverDescriptor = null;
379 if (first > -1 && problemHoverIndex > -1 && problemHoverIndex != first) {
380 // move problem hover to beginning
381 hoverDescriptor = fJavaEditorTextHoverDescriptors[first];
382 fJavaEditorTextHoverDescriptors[first] = fJavaEditorTextHoverDescriptors[problemHoverIndex];
383 fJavaEditorTextHoverDescriptors[problemHoverIndex] = hoverDescriptor;
385 // update annotation hover index if needed
386 if (annotationHoverIndex == first)
387 annotationHoverIndex = problemHoverIndex;
390 if (annotationHoverIndex > -1 && annotationHoverIndex != last) {
391 // move annotation hover to end
392 hoverDescriptor = fJavaEditorTextHoverDescriptors[last];
393 fJavaEditorTextHoverDescriptors[last] = fJavaEditorTextHoverDescriptors[annotationHoverIndex];
394 fJavaEditorTextHoverDescriptors[annotationHoverIndex] = hoverDescriptor;
397 // Move Best Match hover to front
398 for (int i = 0; i < fJavaEditorTextHoverDescriptors.length - 1; i++) {
399 if (PreferenceConstants.ID_BESTMATCH_HOVER.equals(fJavaEditorTextHoverDescriptors[i].getId())) {
400 hoverDescriptor = fJavaEditorTextHoverDescriptors[i];
401 for (int j = i; j > 0; j--)
402 fJavaEditorTextHoverDescriptors[j] = fJavaEditorTextHoverDescriptors[j - 1];
403 fJavaEditorTextHoverDescriptors[0] = hoverDescriptor;
410 return fJavaEditorTextHoverDescriptors;
414 * Resets the Java editor text hovers contributed to the workbench.
416 * This will force a rebuild of the descriptors the next time a client asks for them.
419 * @return an array of JavaEditorTextHoverDescriptor
422 public void resetJavaEditorTextHoverDescriptors() {
423 fJavaEditorTextHoverDescriptors = null;
427 * Creates the PHP plugin standard groups in a context menu.
429 public static void createStandardGroups(IMenuManager menu) {
432 menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
433 menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
434 menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
435 menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
436 menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
437 menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
438 menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
439 menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
440 menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
441 menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
442 menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
445 public static IWorkbenchPage getActivePage() {
446 return getDefault().internalGetActivePage();
449 public static Shell getActiveWorkbenchShell() {
450 return getActiveWorkbenchWindow().getShell();
454 * Returns an array of all editors that have an unsaved content. If the identical content is presented in more than one editor,
455 * only one of those editor parts is part of the result.
457 * @return an array of all dirty editor parts.
459 public static IEditorPart[] getDirtyEditors() {
460 Set inputs = new HashSet();
461 List result = new ArrayList(0);
462 IWorkbench workbench = getDefault().getWorkbench();
463 IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
464 for (int i = 0; i < windows.length; i++) {
465 IWorkbenchPage[] pages = windows[i].getPages();
466 for (int x = 0; x < pages.length; x++) {
467 IEditorPart[] editors = pages[x].getDirtyEditors();
468 for (int z = 0; z < editors.length; z++) {
469 IEditorPart ep = editors[z];
470 IEditorInput input = ep.getEditorInput();
471 if (!inputs.contains(input)) {
478 return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]);
481 public static IWorkbenchWindow getActiveWorkbenchWindow() {
482 return getDefault().getWorkbench().getActiveWorkbenchWindow();
486 * Returns the shared instance.
488 public static PHPeclipsePlugin getDefault() {
492 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
493 return getDefault().internalGetImageDescriptorRegistry();
496 static IPath getInstallLocation() {
497 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
500 // public static int getJVM() {
504 public static String getPluginId() {
505 return getDefault().getDescriptor().getUniqueIdentifier();
509 * Returns the standard display to be used. The method first checks, if the thread calling this method has an associated display.
510 * If so, this display is returned. Otherwise the method returns the default display.
512 public static Display getStandardDisplay() {
513 Display display = Display.getCurrent();
514 if (display == null) {
515 display = Display.getDefault();
520 // public static ExternalToolsPlugin getExternalTools() {
521 // return externalTools;
524 * Returns the workspace instance.
526 public static IWorkspace getWorkspace() {
527 return ResourcesPlugin.getWorkspace();
530 public static boolean isDebug() {
531 return getDefault().isDebugging();
534 // public static void logErrorMessage(String message) {
535 // log(new Status(IStatus.ERROR, getPluginId(),
536 // JavaStatusConstants.INTERNAL_ERROR, message, null));
539 // public static void logErrorStatus(String message, IStatus status) {
540 // if (status == null) {
541 // logErrorMessage(message);
544 // MultiStatus multi= new MultiStatus(getPluginId(),
545 // JavaStatusConstants.INTERNAL_ERROR, message, null);
546 // multi.add(status);
550 // public static void log(Throwable e) {
551 // log(new Status(IStatus.ERROR, getPluginId(),
552 // JavaStatusConstants.INTERNAL_ERROR,
553 // JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
555 public static void log(int severity, String message) {
556 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
560 public static void log(IStatus status) {
561 getDefault().getLog().log(status);
564 public static void log(Throwable e) {
565 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
568 public static void logErrorMessage(String message) {
569 log(new Status(IStatus.ERROR, getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, null));
572 // private static void setJVM() {
573 // String osName = System.getProperty("os.name");
574 // if (osName.startsWith("Mac OS")) {
575 // String mrjVersion = System.getProperty("mrj.version");
576 // String majorMRJVersion = mrjVersion.substring(0, 3);
579 // double version = Double.valueOf(majorMRJVersion).doubleValue();
580 // if (version == 2) {
582 // } else if (version >= 2.1 && version < 3) {
584 // } else if (version == 3.0) {
586 // } else if (version >= 3.1) {
589 // } catch (NumberFormatException nfe) {
591 // } else if (osName.startsWith("Windows")) {
592 // if (osName.indexOf("9") != -1) {
600 // TODO: refactor this into a better method name !
601 public synchronized ICompilationUnitDocumentProvider getCompilationUnitDocumentProvider() {
602 if (fCompilationUnitDocumentProvider == null)
603 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
604 return fCompilationUnitDocumentProvider;
608 * Get the identifier index manager for the given project
611 * the current project
614 public IdentifierIndexManager getIndexManager(IProject iProject) {
615 IPath path = iProject.getWorkingLocation(PHPeclipsePlugin.PLUGIN_ID);
616 path = path.append("project.index");
617 String indexFilename = path.toString();
619 // IdentDB db = IdentDB.getInstance();
620 // } catch (ClassNotFoundException e) {
621 // e.printStackTrace();
622 // } catch (SQLException e) {
623 // e.printStackTrace();
625 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap.get(indexFilename);
626 if (indexManager == null) {
627 indexManager = new IdentifierIndexManager(indexFilename);
628 fIndexManagerMap.put(indexFilename, indexManager);
633 public synchronized IWorkingCopyManager getWorkingCopyManager() {
634 if (fWorkingCopyManager == null) {
635 ICompilationUnitDocumentProvider provider = getCompilationUnitDocumentProvider();
636 fWorkingCopyManager = new WorkingCopyManager(provider);
638 return fWorkingCopyManager;
641 public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
642 if (fMembersOrderPreferenceCache == null)
643 fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
644 return fMembersOrderPreferenceCache;
648 * Returns the mockup preference store for firing events and registering listeners on project setting changes. Temporary solution.
650 public MockupPreferenceStore getMockupPreferenceStore() {
651 if (fMockupPreferenceStore == null)
652 fMockupPreferenceStore = new MockupPreferenceStore();
654 return fMockupPreferenceStore;
657 public synchronized ProblemMarkerManager getProblemMarkerManager() {
658 if (fProblemMarkerManager == null)
659 fProblemMarkerManager = new ProblemMarkerManager();
660 return fProblemMarkerManager;
663 // public synchronized JavaTextTools getJavaTextTools() {
664 // if (fJavaTextTools == null)
665 // fJavaTextTools = new JavaTextTools(getPreferenceStore());
666 // return fJavaTextTools;
668 public synchronized JavaTextTools getJavaTextTools() {
669 if (fJavaTextTools == null)
670 fJavaTextTools = new JavaTextTools(getPreferenceStore(), JavaCore.getPlugin().getPluginPreferences());
671 return fJavaTextTools;
674 public IFile getLastEditorFile() {
675 return fLastEditorFile;
679 * Returns the string from the plugin's resource bundle, or 'key' if not found.
681 // public static String getResourceString(String key) {
682 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
684 // return bundle.getString(key);
685 // } catch (MissingResourceException e) {
690 * Returns the plugin's resource bundle,
692 // public ResourceBundle getResourceBundle() {
693 // return resourceBundle;
695 protected void initializeDefaultPreferences(IPreferenceStore store) {
696 String operatingSystem = Platform.getOS();
697 // maxosx, linux, solaris, win32,...
699 InputStream is = getDefault().openStream(new Path("prefs/default_" + operatingSystem + ".properties"));
700 PropertyResourceBundle resourceBundle = new PropertyResourceBundle(is);
701 Enumeration enum = resourceBundle.getKeys();
703 while (enum.hasMoreElements()) {
704 key = (String)enum.nextElement();
705 store.setDefault(key, resourceBundle.getString( key ));
707 // store.setDefault(PHP_RUN_PREF, resourceBundle.getString(PHP_RUN_PREF));
708 // store.setDefault(EXTERNAL_PARSER_PREF, resourceBundle.getString(EXTERNAL_PARSER_PREF));
709 // store.setDefault(MYSQL_RUN_PREF, resourceBundle.getString(MYSQL_RUN_PREF));
710 // store.setDefault(APACHE_RUN_PREF, resourceBundle.getString(APACHE_RUN_PREF));
712 // store.setDefault(MYSQL_PREF, resourceBundle.getString(MYSQL_PREF));
713 // store.setDefault(APACHE_START_PREF, resourceBundle.getString(APACHE_START_PREF));
714 // store.setDefault(APACHE_STOP_PREF, resourceBundle.getString(APACHE_STOP_PREF));
715 // store.setDefault(APACHE_RESTART_PREF, resourceBundle.getString(APACHE_RESTART_PREF));
716 // store.setDefault(MYSQL_START_BACKGROUND, resourceBundle.getString(MYSQL_START_BACKGROUND));
717 // store.setDefault(APACHE_START_BACKGROUND, resourceBundle.getString(APACHE_START_BACKGROUND));
718 // store.setDefault(APACHE_STOP_BACKGROUND, resourceBundle.getString(APACHE_STOP_BACKGROUND));
719 // store.setDefault(APACHE_RESTART_BACKGROUND, resourceBundle.getString(APACHE_RESTART_BACKGROUND));
720 } catch (Exception e) {
721 // no default properties found
722 if (operatingSystem.equals(Platform.OS_WIN32)) {
723 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
724 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
725 store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
726 store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
727 store.setDefault(XAMPP_START_PREF, "c:\\xampp\\xampp_start.exe");
728 store.setDefault(XAMPP_STOP_PREF, "c:\\xampp\\xampp_stop.exe");
730 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
731 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
732 store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
733 store.setDefault(APACHE_RUN_PREF, "/apache/apache");
734 store.setDefault(XAMPP_START_PREF, "xamp/xampp_start");
735 store.setDefault(XAMPP_STOP_PREF, "xampp/xampp_stop");
737 store.setDefault(MYSQL_PREF, "--standalone");
738 store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
739 store.setDefault(APACHE_STOP_PREF, "-k shutdown");
740 store.setDefault(APACHE_RESTART_PREF, "-k restart");
741 store.setDefault(MYSQL_START_BACKGROUND, "true");
742 store.setDefault(APACHE_START_BACKGROUND, "true");
743 store.setDefault(APACHE_STOP_BACKGROUND, "true");
744 store.setDefault(APACHE_RESTART_BACKGROUND, "true");
747 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
748 store.setDefault(PHP_OBFUSCATOR_DEFAULT, "c:\\temp");
749 if (operatingSystem.equals(Platform.OS_WIN32)) {
750 // store.setDefault(EXTERNAL_BROWSER_PREF, "rundll32 url.dll,FileProtocolHandler {0}");
751 } else if (operatingSystem.equals(Platform.OS_MACOSX)) {
752 store.setDefault(PHP_OBFUSCATOR_DEFAULT, "/tmp");
753 // TODO How do we start Safari on Mac OS X ?
754 // store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
756 store.setDefault(PHP_OBFUSCATOR_DEFAULT, "/tmp");
757 // store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
760 store.setDefault(PHP_EXTENSION_PREFS, "php,php3,php4,php5,phtml,inc,module,class");
762 // store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
763 // store.setDefault(PHP_INTERNAL_PARSER, "false");
764 // store.setDefault(PHP_EXTERNAL_PARSER, "true");
765 // store.setDefault(PHP_PARSE_ON_SAVE, "true");
766 // show line numbers:
767 // store.setDefault(LINE_NUMBER_RULER, "false");
768 // store.setDefault(FORMATTER_TAB_SIZE, "4");
769 // php syntax highlighting
770 store.setDefault(PHP_USERDEF_XMLFILE, "");
771 //assume there is none chooA
772 PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT, PHPColorProvider.MULTI_LINE_COMMENT);
773 PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT, PHPColorProvider.SINGLE_LINE_COMMENT);
774 PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
775 PreferenceConverter.setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
776 PreferenceConverter.setDefault(store, PHP_VARIABLE, PHPColorProvider.VARIABLE);
777 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME, PHPColorProvider.FUNCTION_NAME);
778 PreferenceConverter.setDefault(store, PHP_CONSTANT, PHPColorProvider.CONSTANT);
779 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
780 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
781 PreferenceConverter.setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
782 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD, PHPColorProvider.PHPDOC_KEYWORD);
783 PreferenceConverter.setDefault(store, PHPDOC_TAG, PHPColorProvider.PHPDOC_TAG);
784 PreferenceConverter.setDefault(store, PHPDOC_LINK, PHPColorProvider.PHPDOC_LINK);
785 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT, PHPColorProvider.PHPDOC_DEFAULT);
787 PreferenceConverter.setDefault(store, EDITOR_PHP_KEYWORD_RETURN_COLOR, new RGB(127, 0, 85));
788 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_BOLD, true);
789 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_ITALIC, false);
791 PreferenceConverter.setDefault(store, EDITOR_PHP_OPERATOR_COLOR, new RGB(0, 0, 0));
792 store.setDefault(EDITOR_PHP_OPERATOR_BOLD, false);
793 store.setDefault(EDITOR_PHP_OPERATOR_ITALIC, false);
795 PreferenceConverter.setDefault(store, EDITOR_PHP_BRACE_OPERATOR_COLOR, new RGB(0, 0, 0));
796 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_BOLD, false);
797 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_ITALIC, false);
798 // PreferenceConverter.setDefault(
800 // PHP_EDITOR_BACKGROUND,
801 // PHPColorProvider.BACKGROUND);
802 // PreferenceConverter.setDefault(
804 // LINKED_POSITION_COLOR,
805 // PHPColorProvider.LINKED_POSITION_COLOR);
806 // PreferenceConverter.setDefault(
808 // LINE_NUMBER_COLOR,
809 // PHPColorProvider.LINE_NUMBER_COLOR);
810 // // set default PHPDoc colors:
811 // PreferenceConverter.setDefault(
814 // PHPColorProvider.PHPDOC_KEYWORD);
815 // PreferenceConverter.setDefault(
818 // PHPColorProvider.PHPDOC_LINK);
819 // PreferenceConverter.setDefault(
822 // PHPColorProvider.PHPDOC_DEFAULT);
823 // PreferenceConverter.setDefault(
826 // PHPColorProvider.PHPDOC_TAG);
827 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
828 // PreferenceConverter.setDefault(
830 // PREFERENCE_COLOR_BACKGROUND,
831 // PHPColorProvider.BACKGROUND_COLOR);
833 // store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
834 // store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
835 // store.setDefault(RESOURCE_BUNDLE_DE, "false");
836 // store.setDefault(RESOURCE_BUNDLE_FR, "false");
837 // store.setDefault(RESOURCE_BUNDLE_ES, "false");
838 // TemplatePreferencePage.initDefaults(store);
839 //this will initialize the static fields in the syntaxrdr class
841 JavaCore.initializeDefaultPluginPreferences();
842 PreferenceConstants.initializeDefaultValues(store);
843 externalTools.initializeDefaultPreferences(store);
844 MarkerAnnotationPreferences.initializeDefaultValues(store);
847 private IWorkbenchPage internalGetActivePage() {
848 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
850 return window.getActivePage();
854 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
855 if (fImageDescriptorRegistry == null)
856 fImageDescriptorRegistry = new ImageDescriptorRegistry();
857 return fImageDescriptorRegistry;
861 * Open a file in the Workbench that may or may not exist in the workspace. Must be run on the UI thread.
864 * @throws CoreException
866 public ITextEditor openFileInTextEditor(String filename) throws CoreException {
867 // reject directories
868 if (new File(filename).isDirectory())
870 IWorkbench workbench = PlatformUI.getWorkbench();
871 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
872 IWorkbenchPage page = window.getActivePage();
873 IPath path = new Path(filename);
874 // If the file exists in the workspace, open it
875 IFile file = getWorkspace().getRoot().getFileForLocation(path);
877 ITextEditor textEditor;
878 if (file != null && file.exists()) {
879 editor = IDE.openEditor(page, file, true);
880 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
882 // Otherwise open the stream directly
885 FileStorage storage = new FileStorage(path);
886 IEditorRegistry registry = getWorkbench().getEditorRegistry();
887 IEditorDescriptor desc = registry.getDefaultEditor(filename);
889 desc = registry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
890 // desc = registry.getDefaultEditor();
892 IEditorInput input = new ExternalEditorInput(storage);
893 editor = page.openEditor(input, desc.getId());
894 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
895 // If the storage provider is not ours, we can't guarantee read/write.
896 if (textEditor != null) {
897 IDocumentProvider documentProvider = textEditor.getDocumentProvider();
898 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
899 storage.setReadOnly();
907 * Open a file in the Workbench that may or may not exist in the workspace. Must be run on the UI thread.
911 * @throws CoreException
913 public void openFileAndGotoLine(String filename, int line) throws CoreException {
914 ITextEditor textEditor = openFileInTextEditor(filename);
915 if (textEditor != null) {
916 // If a line number was given, go to it
919 line--; // document is 0 based
920 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
921 textEditor.selectAndReveal(document.getLineOffset(line), document.getLineLength(line));
922 } catch (BadLocationException e) {
923 // invalid text position -> do nothing
930 * Open a file in the Workbench that may or may not exist in the workspace. Must be run on the UI thread.
934 * @throws CoreException
936 public void openFileAndGotoOffset(String filename, int offset, int length) throws CoreException {
937 ITextEditor textEditor = openFileInTextEditor(filename);
938 if (textEditor != null) {
939 // If a line number was given, go to it
941 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
942 textEditor.selectAndReveal(offset, length);
947 public void openFileAndFindString(String filename, String findString) throws CoreException {
948 ITextEditor textEditor = openFileInTextEditor(filename);
949 if (textEditor != null) {
950 // If a string was given, go to it
951 if (findString != null) {
953 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
954 int offset = document.search(0, findString, true, false, true);
955 textEditor.selectAndReveal(offset, findString.length());
956 } catch (BadLocationException e) {
957 // invalid text position -> do nothing
963 public void setLastEditorFile(IFile textEditor) {
964 this.fLastEditorFile = textEditor;
968 * @see org.eclipse.core.runtime.Plugin#stop
970 public void stop(BundleContext context) throws Exception {
972 // JavaCore.stop(this, context);
973 plugin.savePluginPreferences();
974 IWorkspace workspace = ResourcesPlugin.getWorkspace();
975 workspace.removeResourceChangeListener(JavaModelManager.getJavaModelManager().deltaState);
976 workspace.removeSaveParticipant(plugin);
978 JavaModelManager.getJavaModelManager().shutdown();
980 ColorManager.getDefault().dispose();
981 // save the information from the php index files if necessary
982 Collection collection = fIndexManagerMap.values();
983 Iterator iterator = collection.iterator();
984 IdentifierIndexManager indexManager = null;
985 while (iterator.hasNext()) {
986 indexManager = (IdentifierIndexManager) iterator.next();
987 indexManager.writeFile();
989 if (fImageDescriptorRegistry != null)
990 fImageDescriptorRegistry.dispose();
992 // AllTypesCache.terminate();
994 if (fImageDescriptorRegistry != null)
995 fImageDescriptorRegistry.dispose();
997 unregisterAdapters();
999 // if (fASTProvider != null) {
1000 // fASTProvider.dispose();
1001 // fASTProvider= null;
1004 if (fWorkingCopyManager != null) {
1005 fWorkingCopyManager.shutdown();
1006 fWorkingCopyManager = null;
1009 if (fCompilationUnitDocumentProvider != null) {
1010 fCompilationUnitDocumentProvider.shutdown();
1011 fCompilationUnitDocumentProvider = null;
1014 if (fJavaTextTools != null) {
1015 fJavaTextTools.dispose();
1016 fJavaTextTools = null;
1018 // JavaDocLocations.shutdownJavadocLocations();
1020 uninstallPreferenceStoreBackwardsCompatibility();
1022 // RefactoringCore.getUndoManager().shutdown();
1024 super.stop(context);
1029 * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
1031 // public void shutdown() throws CoreException {
1032 // // moved down (see below):
1033 // // super.shutdown();
1034 // // externalTools.shutDown();
1035 // ColorManager.getDefault().dispose();
1036 // // save the information from the php index files if necessary
1037 // Collection collection = fIndexManagerMap.values();
1038 // Iterator iterator = collection.iterator();
1039 // IdentifierIndexManager indexManager = null;
1040 // while (iterator.hasNext()) {
1041 // indexManager = (IdentifierIndexManager) iterator.next();
1042 // indexManager.writeFile();
1044 // if (fImageDescriptorRegistry != null)
1045 // fImageDescriptorRegistry.dispose();
1046 // // unregisterAdapters();
1047 // super.shutdown();
1048 // if (fWorkingCopyManager != null) {
1049 // fWorkingCopyManager.shutdown();
1050 // fWorkingCopyManager = null;
1052 // if (fCompilationUnitDocumentProvider != null) {
1053 // fCompilationUnitDocumentProvider.shutdown();
1054 // fCompilationUnitDocumentProvider = null;
1056 // if (fJavaTextTools != null) {
1057 // fJavaTextTools.dispose();
1058 // fJavaTextTools = null;
1060 // // JavaDocLocations.shutdownJavadocLocations();
1063 // JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
1064 // // begin JavaCore#shutdown()
1065 // //savePluginPreferences();
1066 // savePluginPreferences();
1067 // IWorkspace workspace = ResourcesPlugin.getWorkspace();
1068 // workspace.removeResourceChangeListener(JavaModelManager.getJavaModelManager().deltaState);
1069 // workspace.removeSaveParticipant(this);
1070 // ((JavaModelManager) JavaModelManager.getJavaModelManager()).shutdown();
1071 // // end JavaCore#shutdown()
1074 * Installs backwards compatibility for the preference store.
1076 private void installPreferenceStoreBackwardsCompatibility() {
1079 * Installs backwards compatibility: propagate the Java editor font from a pre-2.1 plug-in to the Platform UI's preference store
1080 * to preserve the Java editor font from a pre-2.1 workspace. This is done only once.
1082 String fontPropagatedKey = "fontPropagated"; //$NON-NLS-1$
1083 if (getPreferenceStore().contains(JFaceResources.TEXT_FONT) && !getPreferenceStore().isDefault(JFaceResources.TEXT_FONT)) {
1084 if (!getPreferenceStore().getBoolean(fontPropagatedKey))
1085 PreferenceConverter.setValue(PlatformUI.getWorkbench().getPreferenceStore(), PreferenceConstants.EDITOR_TEXT_FONT,
1086 PreferenceConverter.getFontDataArray(getPreferenceStore(), JFaceResources.TEXT_FONT));
1088 getPreferenceStore().setValue(fontPropagatedKey, true);
1091 * Backwards compatibility: set the Java editor font in this plug-in's preference store to let older versions access it. Since
1092 * 2.1 the Java editor font is managed by the workbench font preference page.
1094 PreferenceConverter.putValue(getPreferenceStore(), JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry().getFontData(
1095 PreferenceConstants.EDITOR_TEXT_FONT));
1097 fFontPropertyChangeListener = new IPropertyChangeListener() {
1098 public void propertyChange(PropertyChangeEvent event) {
1099 if (PreferenceConstants.EDITOR_TEXT_FONT.equals(event.getProperty()))
1100 PreferenceConverter.putValue(getPreferenceStore(), JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry()
1101 .getFontData(PreferenceConstants.EDITOR_TEXT_FONT));
1104 JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
1107 * Backwards compatibility: propagate the Java editor tab width from a pre-3.0 plug-in to the new preference key. This is done
1110 // final String oldTabWidthKey = PreferenceConstants.EDITOR_TAB_WIDTH;
1111 // final String newTabWidthKey = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH;
1112 // String tabWidthPropagatedKey = "tabWidthPropagated"; //$NON-NLS-1$
1113 // if (getPreferenceStore().contains(oldTabWidthKey) && !getPreferenceStore().isDefault(oldTabWidthKey)) {
1114 // if (!getPreferenceStore().getBoolean(tabWidthPropagatedKey))
1115 // getPreferenceStore().setValue(newTabWidthKey, getPreferenceStore().getInt(oldTabWidthKey));
1117 // getPreferenceStore().setValue(tabWidthPropagatedKey, true);
1120 // * Backwards compatibility: set the Java editor tab width in this plug-in's preference store with the old key to let older
1121 // * versions access it. Since 3.0 the tab width is managed by the extended texteditor and uses a new key.
1123 // getPreferenceStore().putValue(oldTabWidthKey, getPreferenceStore().getString(newTabWidthKey));
1124 // fPropertyChangeListener = new IPropertyChangeListener() {
1125 // public void propertyChange(PropertyChangeEvent event) {
1126 // if (newTabWidthKey.equals(event.getProperty()))
1127 // getPreferenceStore().putValue(oldTabWidthKey, getPreferenceStore().getString(newTabWidthKey));
1130 // getPreferenceStore().addPropertyChangeListener(fPropertyChangeListener);
1132 * Backward compatibility for the refactoring preference key.
1134 // getPreferenceStore().setValue(
1135 // PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD,
1136 // RefactoringCore.getConditionCheckingFailedSeverity());
1140 * Uninstalls backwards compatibility for the preference store.
1142 private void uninstallPreferenceStoreBackwardsCompatibility() {
1143 JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
1144 // getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
1148 * (non - Javadoc) Method declared in Plugin
1150 public void start(BundleContext context) throws Exception {
1151 super.start(context);
1153 // JavaCore.start(this, context);
1154 final JavaModelManager manager = JavaModelManager.getJavaModelManager();
1156 manager.configurePluginDebugOptions();
1158 // request state folder creation (workaround 19885)
1159 // JavaCore.getPlugin().getStateLocation();
1161 // retrieve variable values
1162 PHPeclipsePlugin.getDefault().getPluginPreferences().addPropertyChangeListener(
1163 new JavaModelManager.PluginPreferencesListener());
1164 // manager.loadVariablesAndContainers();
1166 final IWorkspace workspace = ResourcesPlugin.getWorkspace();
1167 workspace.addResourceChangeListener(manager.deltaState, IResourceChangeEvent.PRE_BUILD | IResourceChangeEvent.POST_BUILD
1168 | IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.PRE_CLOSE);
1171 ISavedState savedState = workspace.addSaveParticipant(PHPeclipsePlugin.this, manager);
1173 // process deltas since last activated in indexer thread so that indexes are up-to-date.
1174 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658
1175 Job processSavedState = new Job(Util.bind("savedState.jobName")) { //$NON-NLS-1$
1176 protected IStatus run(IProgressMonitor monitor) {
1178 // add save participant and process delta atomically
1179 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59937
1180 workspace.run(new IWorkspaceRunnable() {
1181 public void run(IProgressMonitor progress) throws CoreException {
1182 ISavedState savedState = workspace.addSaveParticipant(PHPeclipsePlugin.this, manager);
1183 if (savedState != null) {
1184 // the event type coming from the saved state is always POST_AUTO_BUILD
1185 // force it to be POST_CHANGE so that the delta processor can handle it
1186 manager.deltaState.getDeltaProcessor().overridenEventType = IResourceChangeEvent.POST_CHANGE;
1187 savedState.processResourceChangeEvents(manager.deltaState);
1191 } catch (CoreException e) {
1192 return e.getStatus();
1194 return Status.OK_STATUS;
1197 processSavedState.setSystem(true);
1198 processSavedState.setPriority(Job.SHORT); // process asap
1199 processSavedState.schedule();
1200 } catch (RuntimeException e) {
1207 // if (USE_WORKING_COPY_OWNERS) {
1208 WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
1209 public IBuffer createBuffer(ICompilationUnit workingCopy) {
1210 ICompilationUnit original = workingCopy.getPrimary();
1211 IResource resource = original.getResource();
1212 if (resource instanceof IFile)
1213 return new DocumentAdapter(workingCopy, (IFile) resource);
1214 return DocumentAdapter.NULL;
1219 installPreferenceStoreBackwardsCompatibility();
1223 // registerAdapters();
1225 // // externalTools.startUp();
1226 // getStandardDisplay().asyncExec(new Runnable() {
1227 // public void run() {
1228 // //initialize the variable context manager
1229 // VariableContextManager.getDefault();
1233 // // if (USE_WORKING_COPY_OWNERS) {
1234 // WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
1235 // public IBuffer createBuffer(ICompilationUnit workingCopy) {
1236 // ICompilationUnit original = workingCopy.getPrimary();
1237 // IResource resource = original.getResource();
1238 // if (resource instanceof IFile)
1239 // return new DocumentAdapter(workingCopy, (IFile) resource);
1240 // return DocumentAdapter.NULL;
1245 // installPreferenceStoreBackwardsCompatibility();
1247 // AllTypesCache.initialize();
1249 // Initialize AST provider
1250 // getASTProvider();
1253 // public void startup() throws CoreException {
1255 // // begin JavaCore.startup();
1256 // JavaModelManager manager = JavaModelManager.getJavaModelManager();
1258 // manager.configurePluginDebugOptions();
1259 // // request state folder creation (workaround 19885)
1260 // // JavaCore.getPlugin().getStateLocation();
1261 // getStateLocation();
1262 // // retrieve variable values
1264 // JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new
1265 // // JavaModelManager.PluginPreferencesListener());
1266 // getPluginPreferences().addPropertyChangeListener(
1267 // new JavaModelManager.PluginPreferencesListener());
1269 // // manager.loadVariablesAndContainers();
1270 // final IWorkspace workspace = ResourcesPlugin.getWorkspace();
1271 // workspace.addResourceChangeListener(
1272 // manager.deltaState,
1273 // IResourceChangeEvent.PRE_BUILD
1274 // | IResourceChangeEvent.POST_BUILD
1275 // | IResourceChangeEvent.POST_CHANGE
1276 // | IResourceChangeEvent.PRE_DELETE
1277 // | IResourceChangeEvent.PRE_CLOSE);
1278 // // startIndexing();
1279 // workspace.addSaveParticipant(PHPeclipsePlugin.getDefault(), manager);
1280 // } catch (CoreException e) {
1281 // } catch (RuntimeException e) {
1282 // manager.shutdown();
1285 // // end JavaCore.startup();
1286 // IAdapterManager platformManager = Platform.getAdapterManager();
1287 // platformManager.registerAdapters(new PHPElementAdapterFactory(),
1288 // PHPElement.class);
1289 // platformManager.registerAdapters(new ResourceAdapterFactory(),
1290 // IResource.class);
1291 // // externalTools.startUp();
1292 // getStandardDisplay().asyncExec(new Runnable() {
1293 // public void run() {
1294 // //initialize the variable context manager
1295 // VariableContextManager.getDefault();
1300 private void registerAdapters() {
1301 fJavaElementAdapterFactory = new JavaElementAdapterFactory();
1302 // fMarkerAdapterFactory= new MarkerAdapterFactory();
1303 // fEditorInputAdapterFactory= new EditorInputAdapterFactory();
1304 fResourceAdapterFactory = new ResourceAdapterFactory();
1305 // fLogicalPackageAdapterFactory= new LogicalPackageAdapterFactory();
1307 IAdapterManager manager = Platform.getAdapterManager();
1308 manager.registerAdapters(fJavaElementAdapterFactory, IJavaElement.class);
1309 // manager.registerAdapters(fMarkerAdapterFactory, IMarker.class);
1310 // manager.registerAdapters(fEditorInputAdapterFactory, IEditorInput.class);
1311 manager.registerAdapters(fResourceAdapterFactory, IResource.class);
1312 // manager.registerAdapters(fLogicalPackageAdapterFactory,
1313 // LogicalPackage.class);
1316 private void unregisterAdapters() {
1317 IAdapterManager manager = Platform.getAdapterManager();
1318 manager.unregisterAdapters(fJavaElementAdapterFactory);
1319 // manager.unregisterAdapters(fMarkerAdapterFactory);
1320 // manager.unregisterAdapters(fEditorInputAdapterFactory);
1321 manager.unregisterAdapters(fResourceAdapterFactory);
1322 // manager.unregisterAdapters(fLogicalPackageAdapterFactory);
1326 * Returns a combined preference store, this store is read-only.
1328 * @return the combined preference store
1332 public IPreferenceStore getCombinedPreferenceStore() {
1333 if (fCombinedPreferenceStore == null) {
1334 IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
1335 fCombinedPreferenceStore = new ChainedPreferenceStore(new IPreferenceStore[] {
1336 getPreferenceStore(),
1337 new PreferencesAdapter(PHPeclipsePlugin.getDefault().getPluginPreferences()),
1338 generalTextStore });
1340 return fCombinedPreferenceStore;
1343 public synchronized IBufferFactory getBufferFactory() {
1344 if (fBufferFactory == null)
1345 fBufferFactory = new CustomBufferFactory();
1346 return fBufferFactory;
1350 * Returns the registry of the extensions to the <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code> extension
1353 * @return the registry of contributed <code>IJavaFoldingStructureProvider</code>
1356 public synchronized JavaFoldingStructureProviderRegistry getFoldingStructureProviderRegistry() {
1357 if (fFoldingStructureProviderRegistry == null)
1358 fFoldingStructureProviderRegistry = new JavaFoldingStructureProviderRegistry();
1359 return fFoldingStructureProviderRegistry;
1363 * Runs the given action as an atomic Java model operation.
1365 * After running a method that modifies java elements, registered listeners receive after-the-fact notification of what just
1366 * transpired, in the form of a element changed event. This method allows clients to call a number of methods that modify java
1367 * elements and only have element changed event notifications reported at the end of the entire batch.
1370 * If this method is called outside the dynamic scope of another such call, this method runs the action and then reports a single
1371 * element changed event describing the net effect of all changes done to java elements by the action.
1374 * If this method is called in the dynamic scope of another such call, this method simply runs the action.
1378 * the action to perform
1380 * a progress monitor, or <code>null</code> if progress reporting and cancellation are not desired
1381 * @exception CoreException
1382 * if the operation failed.
1385 public static void run(IWorkspaceRunnable action, IProgressMonitor monitor) throws CoreException {
1386 run(action, ResourcesPlugin.getWorkspace().getRoot(), monitor);
1390 * Runs the given action as an atomic Java model operation.
1392 * After running a method that modifies java elements, registered listeners receive after-the-fact notification of what just
1393 * transpired, in the form of a element changed event. This method allows clients to call a number of methods that modify java
1394 * elements and only have element changed event notifications reported at the end of the entire batch.
1397 * If this method is called outside the dynamic scope of another such call, this method runs the action and then reports a single
1398 * element changed event describing the net effect of all changes done to java elements by the action.
1401 * If this method is called in the dynamic scope of another such call, this method simply runs the action.
1404 * The supplied scheduling rule is used to determine whether this operation can be run simultaneously with workspace changes in
1405 * other threads. See <code>IWorkspace.run(...)</code> for more details.
1409 * the action to perform
1411 * the scheduling rule to use when running this operation, or <code>null</code> if there are no scheduling restrictions
1412 * for this operation.
1414 * a progress monitor, or <code>null</code> if progress reporting and cancellation are not desired
1415 * @exception CoreException
1416 * if the operation failed.
1419 public static void run(IWorkspaceRunnable action, ISchedulingRule rule, IProgressMonitor monitor) throws CoreException {
1420 IWorkspace workspace = ResourcesPlugin.getWorkspace();
1421 if (workspace.isTreeLocked()) {
1422 new BatchOperation(action).run(monitor);
1424 // use IWorkspace.run(...) to ensure that a build will be done in
1426 workspace.run(new BatchOperation(action), rule, IWorkspace.AVOID_UPDATE, monitor);
1431 * Returns the template context type registry for the java plugin.
1433 * @return the template context type registry for the java plugin
1436 public ContextTypeRegistry getTemplateContextRegistry() {
1437 if (fContextTypeRegistry == null) {
1438 fContextTypeRegistry = new ContributionContextTypeRegistry();
1440 fContextTypeRegistry.addContextType(new JavaContextType());
1441 fContextTypeRegistry.addContextType(new JavaDocContextType());
1442 fContextTypeRegistry.addContextType(new HTMLContextType());
1445 return fContextTypeRegistry;
1449 * Returns the template store for the java editor templates.
1451 * @return the template store for the java editor templates
1454 public TemplateStore getTemplateStore() {
1455 if (fTemplateStore == null) {
1456 // boolean alreadyMigrated= getPreferenceStore().getBoolean(TEMPLATES_MIGRATION_KEY);
1457 // if (alreadyMigrated)
1458 fTemplateStore = new ContributionTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), TEMPLATES_KEY);
1460 // fTemplateStore= new CompatibilityTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), TEMPLATES_KEY,
1461 // Templates.getInstance());
1462 // getPreferenceStore().setValue(TEMPLATES_MIGRATION_KEY, true);
1466 fTemplateStore.load();
1467 } catch (IOException e) {
1472 return fTemplateStore;
1476 * Returns the template context type registry for the code generation templates.
1478 * @return the template context type registry for the code generation templates
1481 public ContextTypeRegistry getCodeTemplateContextRegistry() {
1482 if (fCodeTemplateContextTypeRegistry == null) {
1483 fCodeTemplateContextTypeRegistry = new ContributionContextTypeRegistry();
1485 CodeTemplateContextType.registerContextTypes(fCodeTemplateContextTypeRegistry);
1488 return fCodeTemplateContextTypeRegistry;
1492 * Returns the template store for the code generation templates.
1494 * @return the template store for the code generation templates
1497 public TemplateStore getCodeTemplateStore() {
1498 if (fCodeTemplateStore == null) {
1499 // boolean alreadyMigrated= getPreferenceStore().getBoolean(CODE_TEMPLATES_MIGRATION_KEY);
1500 // if (alreadyMigrated)
1501 fCodeTemplateStore = new ContributionTemplateStore(getCodeTemplateContextRegistry(), getPreferenceStore(), CODE_TEMPLATES_KEY);
1503 // fCodeTemplateStore= new CompatibilityTemplateStore(getCodeTemplateContextRegistry(), getPreferenceStore(),
1504 // CODE_TEMPLATES_KEY, CodeTemplates.getInstance());
1505 // getPreferenceStore().setValue(CODE_TEMPLATES_MIGRATION_KEY, true);
1509 fCodeTemplateStore.load();
1510 } catch (IOException e) {
1514 // compatibility / bug fixing code for duplicated templates
1515 // TODO remove for 3.0
1516 // CompatibilityTemplateStore.pruneDuplicates(fCodeTemplateStore, true);
1519 return fCodeTemplateStore;