1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
8 **********************************************************************/
9 package net.sourceforge.phpeclipse;
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Enumeration;
17 import java.util.HashMap;
18 import java.util.HashSet;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.PropertyResourceBundle;
24 import net.sourceforge.phpdt.core.IBuffer;
25 import net.sourceforge.phpdt.core.IBufferFactory;
26 import net.sourceforge.phpdt.core.ICompilationUnit;
27 import net.sourceforge.phpdt.core.IJavaElement;
28 import net.sourceforge.phpdt.core.JavaCore;
29 import net.sourceforge.phpdt.core.WorkingCopyOwner;
30 import net.sourceforge.phpdt.internal.core.BatchOperation;
31 import net.sourceforge.phpdt.internal.core.JavaModelManager;
32 import net.sourceforge.phpdt.internal.core.util.Util;
33 import net.sourceforge.phpdt.internal.corext.template.php.CodeTemplateContextType;
34 import net.sourceforge.phpdt.internal.corext.template.php.HTMLContextType;
35 import net.sourceforge.phpdt.internal.corext.template.php.JavaContextType;
36 import net.sourceforge.phpdt.internal.corext.template.php.JavaDocContextType;
37 import net.sourceforge.phpdt.internal.ui.IJavaStatusConstants;
38 import net.sourceforge.phpdt.internal.ui.JavaElementAdapterFactory;
39 import net.sourceforge.phpdt.internal.ui.ResourceAdapterFactory;
40 import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache;
41 import net.sourceforge.phpdt.internal.ui.preferences.MockupPreferenceStore;
42 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
43 import net.sourceforge.phpdt.internal.ui.text.folding.JavaFoldingStructureProviderRegistry;
44 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
45 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
46 import net.sourceforge.phpdt.internal.ui.viewsupport.ProblemMarkerManager;
47 import net.sourceforge.phpdt.ui.IContextMenuConstants;
48 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
49 import net.sourceforge.phpdt.ui.PreferenceConstants;
50 import net.sourceforge.phpdt.ui.text.JavaTextTools;
51 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
52 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
53 import net.sourceforge.phpeclipse.builder.FileStorage;
54 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
55 import net.sourceforge.phpeclipse.phpeditor.CustomBufferFactory;
56 import net.sourceforge.phpeclipse.phpeditor.DocumentAdapter;
57 import net.sourceforge.phpeclipse.phpeditor.ICompilationUnitDocumentProvider;
58 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
59 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
60 import net.sourceforge.phpeclipse.phpeditor.WorkingCopyManager;
61 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
63 import org.eclipse.core.resources.IFile;
64 import org.eclipse.core.resources.IProject;
65 import org.eclipse.core.resources.IResource;
66 import org.eclipse.core.resources.IResourceChangeEvent;
67 import org.eclipse.core.resources.ISavedState;
68 import org.eclipse.core.resources.IWorkspace;
69 import org.eclipse.core.resources.IWorkspaceRunnable;
70 import org.eclipse.core.resources.ResourcesPlugin;
71 import org.eclipse.core.runtime.CoreException;
72 import org.eclipse.core.runtime.IAdapterManager;
73 import org.eclipse.core.runtime.IConfigurationElement;
74 import org.eclipse.core.runtime.IPath;
75 import org.eclipse.core.runtime.IProgressMonitor;
76 import org.eclipse.core.runtime.IStatus;
77 import org.eclipse.core.runtime.Path;
78 import org.eclipse.core.runtime.Platform;
79 import org.eclipse.core.runtime.Status;
80 import org.eclipse.core.runtime.jobs.ISchedulingRule;
81 import org.eclipse.core.runtime.jobs.Job;
82 import org.eclipse.jface.action.GroupMarker;
83 import org.eclipse.jface.action.IMenuManager;
84 import org.eclipse.jface.action.Separator;
85 import org.eclipse.jface.preference.IPreferenceStore;
86 import org.eclipse.jface.preference.PreferenceConverter;
87 import org.eclipse.jface.resource.JFaceResources;
88 import org.eclipse.jface.text.BadLocationException;
89 import org.eclipse.jface.text.IDocument;
90 import org.eclipse.jface.text.templates.ContextTypeRegistry;
91 import org.eclipse.jface.text.templates.persistence.TemplateStore;
92 import org.eclipse.jface.util.IPropertyChangeListener;
93 import org.eclipse.jface.util.PropertyChangeEvent;
94 import org.eclipse.swt.graphics.RGB;
95 import org.eclipse.swt.widgets.Display;
96 import org.eclipse.swt.widgets.Shell;
97 import org.eclipse.ui.IEditorDescriptor;
98 import org.eclipse.ui.IEditorInput;
99 import org.eclipse.ui.IEditorPart;
100 import org.eclipse.ui.IEditorRegistry;
101 import org.eclipse.ui.IWorkbench;
102 import org.eclipse.ui.IWorkbenchPage;
103 import org.eclipse.ui.IWorkbenchWindow;
104 import org.eclipse.ui.PlatformUI;
105 import org.eclipse.ui.editors.text.EditorsUI;
106 import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
107 import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
108 import org.eclipse.ui.ide.IDE;
109 import org.eclipse.ui.plugin.AbstractUIPlugin;
110 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
111 import org.eclipse.ui.texteditor.ConfigurationElementSorter;
112 import org.eclipse.ui.texteditor.IDocumentProvider;
113 import org.eclipse.ui.texteditor.ITextEditor;
114 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
115 import org.osgi.framework.BundleContext;
118 * The main plugin class to be used in the desktop.
120 public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceConstants {
122 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
124 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
125 public static final String EDITOR_ID = PHPeclipsePlugin.PLUGIN_ID+".PHPUnitEditor";
126 public static final String ID_PERSPECTIVE = "net.sourceforge.phpeclipse.PHPPerspective"; //$NON-NLS-1$
131 * id of builder - matches plugin.xml (concatenate pluginid.builderid)
133 public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
135 //public static final String BUILDER_INDEX_ID = PLUGIN_ID + ".indexbuilder";
136 /** General debug flag */
138 public static final boolean DEBUG = false;
141 * The maximum number of allowed proposals by category
143 public final static int MAX_PROPOSALS = 200;
146 * The key to store customized templates.
150 private static final String TEMPLATES_KEY = "net.sourceforge.phpdt.ui.text.custom_templates"; //$NON-NLS-1$
153 * The key to store customized code templates.
157 private static final String CODE_TEMPLATES_KEY = "net.sourceforge.phpdt.ui.text.custom_code_templates"; //$NON-NLS-1$
160 * The key to store whether the legacy templates have been migrated
164 // private static final String TEMPLATES_MIGRATION_KEY= "net.sourceforge.phpdt.ui.text.templates_migrated"; //$NON-NLS-1$
166 * The key to store whether the legacy code templates have been migrated
170 // private static final String CODE_TEMPLATES_MIGRATION_KEY= "net.sourceforge.phpdt.ui.text.code_templates_migrated";
172 // private static ExternalToolsPlugin externalTools;
175 * The Java virtual machine that we are running on.
177 // private static int jvm;
179 // private static final int MRJ_2_0 = 0;
181 // /** MRJ 2.1 or later */
182 // private static final int MRJ_2_1 = 1;
184 // /** Java on Mac OS X 10.0 (MRJ 3.0) */
185 // private static final int MRJ_3_0 = 3;
188 // private static final int MRJ_3_1 = 4;
190 // /** JVM constant for any other platform */
191 // private static final int OTHER = -1;
192 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID +
193 // ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
194 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID + ".ui.CodingActionSet"; //$NON-NLS-1$
196 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
198 public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
200 public static final String PHPPARSER_NEW = "test.PHPParser";
202 /** Change this if you want to switch PHP Parser. */
203 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
205 //The shared instance.
206 private static PHPeclipsePlugin plugin;
209 * The template context type registry for the java editor.
213 private ContextTypeRegistry fContextTypeRegistry;
216 * The code template context type registry for the java editor.
220 private ContextTypeRegistry fCodeTemplateContextTypeRegistry;
223 * The template store for the java editor.
227 private TemplateStore fTemplateStore;
230 * The coded template store for the java editor.
234 private TemplateStore fCodeTemplateStore;
237 private static final int WINDOWS_9x = 6;
240 private static final int WINDOWS_NT = 5;
242 private ImageDescriptorRegistry fImageDescriptorRegistry;
244 private HashMap fIndexManagerMap = new HashMap();
246 private IWorkingCopyManager fWorkingCopyManager;
248 private IBufferFactory fBufferFactory;
250 private ICompilationUnitDocumentProvider fCompilationUnitDocumentProvider;
252 private JavaTextTools fJavaTextTools;
254 private ProblemMarkerManager fProblemMarkerManager;
256 private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
258 private IFile fLastEditorFile = null;
260 private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
262 private JavaElementAdapterFactory fJavaElementAdapterFactory;
264 // private MarkerAdapterFactory fMarkerAdapterFactory;
265 // private EditorInputAdapterFactory fEditorInputAdapterFactory;
266 private ResourceAdapterFactory fResourceAdapterFactory;
268 // private LogicalPackageAdapterFactory fLogicalPackageAdapterFactory;
269 private IPropertyChangeListener fFontPropertyChangeListener;
272 * Property change listener on this plugin's preference store.
276 // private IPropertyChangeListener fPropertyChangeListener;
278 * The combined preference store.
282 private IPreferenceStore fCombinedPreferenceStore;
285 * The extension point registry for the <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code> extension point.
289 private JavaFoldingStructureProviderRegistry fFoldingStructureProviderRegistry;
292 * Mockup preference store for firing events and registering listeners on project setting changes. FIXME: Temporary solution.
296 private MockupPreferenceStore fMockupPreferenceStore;
301 public PHPeclipsePlugin() {
304 // externalTools = new ExternalToolsPlugin();
308 // ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
309 // } catch (MissingResourceException x) {
310 // resourceBundle = null;
315 // * Returns all Java editor text hovers contributed to the workbench.
317 // * @return an array of JavaEditorTextHoverDescriptor
320 // public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors()
322 // if (fJavaEditorTextHoverDescriptors == null)
323 // fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
324 // .getContributedHovers();
325 // return fJavaEditorTextHoverDescriptors;
328 * Returns all Java editor text hovers contributed to the workbench.
330 * @return an array of JavaEditorTextHoverDescriptor
333 public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
334 if (fJavaEditorTextHoverDescriptors == null) {
335 fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor.getContributedHovers();
336 ConfigurationElementSorter sorter = new ConfigurationElementSorter() {
338 * @see org.eclipse.ui.texteditor.ConfigurationElementSorter#getConfigurationElement(java.lang.Object)
340 public IConfigurationElement getConfigurationElement(Object object) {
341 return ((JavaEditorTextHoverDescriptor) object).getConfigurationElement();
344 sorter.sort(fJavaEditorTextHoverDescriptors);
346 // The Problem hover has to be the first and the Annotation hover has to
347 // be the last one in the JDT UI's hover list
348 int length = fJavaEditorTextHoverDescriptors.length;
350 int last = length - 1;
351 int problemHoverIndex = -1;
352 int annotationHoverIndex = -1;
353 for (int i = 0; i < length; i++) {
354 if (!fJavaEditorTextHoverDescriptors[i].getId().startsWith(PLUGIN_ID)) {
355 if (problemHoverIndex == -1 || annotationHoverIndex == -1)
365 if (fJavaEditorTextHoverDescriptors[i].getId().equals("net.sourceforge.phpdt.ui.AnnotationHover")) { //$NON-NLS-1$
366 annotationHoverIndex = i;
369 if (fJavaEditorTextHoverDescriptors[i].getId().equals("net.sourceforge.phpdt.ui.ProblemHover")) { //$NON-NLS-1$
370 problemHoverIndex = i;
375 JavaEditorTextHoverDescriptor hoverDescriptor = null;
377 if (first > -1 && problemHoverIndex > -1 && problemHoverIndex != first) {
378 // move problem hover to beginning
379 hoverDescriptor = fJavaEditorTextHoverDescriptors[first];
380 fJavaEditorTextHoverDescriptors[first] = fJavaEditorTextHoverDescriptors[problemHoverIndex];
381 fJavaEditorTextHoverDescriptors[problemHoverIndex] = hoverDescriptor;
383 // update annotation hover index if needed
384 if (annotationHoverIndex == first)
385 annotationHoverIndex = problemHoverIndex;
388 if (annotationHoverIndex > -1 && annotationHoverIndex != last) {
389 // move annotation hover to end
390 hoverDescriptor = fJavaEditorTextHoverDescriptors[last];
391 fJavaEditorTextHoverDescriptors[last] = fJavaEditorTextHoverDescriptors[annotationHoverIndex];
392 fJavaEditorTextHoverDescriptors[annotationHoverIndex] = hoverDescriptor;
395 // Move Best Match hover to front
396 for (int i = 0; i < fJavaEditorTextHoverDescriptors.length - 1; i++) {
397 if (PreferenceConstants.ID_BESTMATCH_HOVER.equals(fJavaEditorTextHoverDescriptors[i].getId())) {
398 hoverDescriptor = fJavaEditorTextHoverDescriptors[i];
399 for (int j = i; j > 0; j--)
400 fJavaEditorTextHoverDescriptors[j] = fJavaEditorTextHoverDescriptors[j - 1];
401 fJavaEditorTextHoverDescriptors[0] = hoverDescriptor;
408 return fJavaEditorTextHoverDescriptors;
412 * Resets the Java editor text hovers contributed to the workbench.
414 * This will force a rebuild of the descriptors the next time a client asks for them.
417 * @return an array of JavaEditorTextHoverDescriptor
420 public void resetJavaEditorTextHoverDescriptors() {
421 fJavaEditorTextHoverDescriptors = null;
425 * Creates the PHP plugin standard groups in a context menu.
427 public static void createStandardGroups(IMenuManager menu) {
430 menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
431 menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
432 menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
433 menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
434 menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
435 menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
436 menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
437 menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
438 menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
439 menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
440 menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
443 public static IWorkbenchPage getActivePage() {
444 return getDefault().internalGetActivePage();
447 public static Shell getActiveWorkbenchShell() {
448 return getActiveWorkbenchWindow().getShell();
452 * Returns an array of all editors that have an unsaved content. If the identical content is presented in more than one editor,
453 * only one of those editor parts is part of the result.
455 * @return an array of all dirty editor parts.
457 public static IEditorPart[] getDirtyEditors() {
458 Set inputs = new HashSet();
459 List result = new ArrayList(0);
460 IWorkbench workbench = getDefault().getWorkbench();
461 IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
462 for (int i = 0; i < windows.length; i++) {
463 IWorkbenchPage[] pages = windows[i].getPages();
464 for (int x = 0; x < pages.length; x++) {
465 IEditorPart[] editors = pages[x].getDirtyEditors();
466 for (int z = 0; z < editors.length; z++) {
467 IEditorPart ep = editors[z];
468 IEditorInput input = ep.getEditorInput();
469 if (!inputs.contains(input)) {
476 return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]);
479 public static IWorkbenchWindow getActiveWorkbenchWindow() {
480 return getDefault().getWorkbench().getActiveWorkbenchWindow();
484 * Returns the shared instance.
486 public static PHPeclipsePlugin getDefault() {
490 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
491 return getDefault().internalGetImageDescriptorRegistry();
494 static IPath getInstallLocation() {
495 return new Path(getDefault().getBundle().getEntry("/").getFile());
498 // public static int getJVM() {
502 public static String getPluginId() {
503 return getDefault().getBundle().getSymbolicName() ;
507 * Returns the standard display to be used. The method first checks, if the thread calling this method has an associated display.
508 * If so, this display is returned. Otherwise the method returns the default display.
510 public static Display getStandardDisplay() {
511 Display display = Display.getCurrent();
512 if (display == null) {
513 display = Display.getDefault();
518 // public static ExternalToolsPlugin getExternalTools() {
519 // return externalTools;
522 * Returns the workspace instance.
524 public static IWorkspace getWorkspace() {
525 return ResourcesPlugin.getWorkspace();
528 public static boolean isDebug() {
529 return getDefault().isDebugging();
532 // public static void logErrorMessage(String message) {
533 // log(new Status(IStatus.ERROR, getPluginId(),
534 // JavaStatusConstants.INTERNAL_ERROR, message, null));
537 // public static void logErrorStatus(String message, IStatus status) {
538 // if (status == null) {
539 // logErrorMessage(message);
542 // MultiStatus multi= new MultiStatus(getPluginId(),
543 // JavaStatusConstants.INTERNAL_ERROR, message, null);
544 // multi.add(status);
548 // public static void log(Throwable e) {
549 // log(new Status(IStatus.ERROR, getPluginId(),
550 // JavaStatusConstants.INTERNAL_ERROR,
551 // JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
553 public static void log(int severity, String message) {
554 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
558 public static void log(IStatus status) {
559 getDefault().getLog().log(status);
562 public static void log(Throwable t) {
566 public static void log(String message, Throwable t) {
567 log(error(message, t));
570 public static void logErrorMessage(String message) {
571 log(new Status(IStatus.ERROR, getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, null));
574 public static IStatus error(Throwable t) {
575 return error("PHPeclipsePlugin.internalErrorOccurred", t); //$NON-NLS-1$
578 public static IStatus error(String message, Throwable t) {
579 return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, t);
582 // private static void setJVM() {
583 // String osName = System.getProperty("os.name");
584 // if (osName.startsWith("Mac OS")) {
585 // String mrjVersion = System.getProperty("mrj.version");
586 // String majorMRJVersion = mrjVersion.substring(0, 3);
589 // double version = Double.valueOf(majorMRJVersion).doubleValue();
590 // if (version == 2) {
592 // } else if (version >= 2.1 && version < 3) {
594 // } else if (version == 3.0) {
596 // } else if (version >= 3.1) {
599 // } catch (NumberFormatException nfe) {
601 // } else if (osName.startsWith("Windows")) {
602 // if (osName.indexOf("9") != -1) {
610 // TODO: refactor this into a better method name !
611 public synchronized ICompilationUnitDocumentProvider getCompilationUnitDocumentProvider() {
612 if (fCompilationUnitDocumentProvider == null)
613 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
614 return fCompilationUnitDocumentProvider;
618 * Get the identifier index manager for the given project
621 * the current project
624 public IdentifierIndexManager getIndexManager(IProject iProject) {
625 IPath path = iProject.getWorkingLocation(PHPeclipsePlugin.PLUGIN_ID);
626 path = path.append("project.index");
627 String indexFilename = path.toString();
629 // IdentDB db = IdentDB.getInstance();
630 // } catch (ClassNotFoundException e) {
631 // e.printStackTrace();
632 // } catch (SQLException e) {
633 // e.printStackTrace();
635 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap.get(indexFilename);
636 if (indexManager == null) {
637 indexManager = new IdentifierIndexManager(indexFilename);
638 fIndexManagerMap.put(indexFilename, indexManager);
643 public synchronized IWorkingCopyManager getWorkingCopyManager() {
644 if (fWorkingCopyManager == null) {
645 ICompilationUnitDocumentProvider provider = getCompilationUnitDocumentProvider();
646 fWorkingCopyManager = new WorkingCopyManager(provider);
648 return fWorkingCopyManager;
651 public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
652 if (fMembersOrderPreferenceCache == null)
653 fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
654 return fMembersOrderPreferenceCache;
658 * Returns the mockup preference store for firing events and registering listeners on project setting changes. Temporary solution.
660 public MockupPreferenceStore getMockupPreferenceStore() {
661 if (fMockupPreferenceStore == null)
662 fMockupPreferenceStore = new MockupPreferenceStore();
664 return fMockupPreferenceStore;
667 public synchronized ProblemMarkerManager getProblemMarkerManager() {
668 if (fProblemMarkerManager == null)
669 fProblemMarkerManager = new ProblemMarkerManager();
670 return fProblemMarkerManager;
673 // public synchronized JavaTextTools getJavaTextTools() {
674 // if (fJavaTextTools == null)
675 // fJavaTextTools = new JavaTextTools(getPreferenceStore());
676 // return fJavaTextTools;
678 public synchronized JavaTextTools getJavaTextTools() {
679 if (fJavaTextTools == null)
680 fJavaTextTools = new JavaTextTools(getPreferenceStore(), JavaCore.getPlugin().getPluginPreferences());
681 return fJavaTextTools;
684 public IFile getLastEditorFile() {
685 return fLastEditorFile;
689 * Returns the string from the plugin's resource bundle, or 'key' if not found.
691 // public static String getResourceString(String key) {
692 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
694 // return bundle.getString(key);
695 // } catch (MissingResourceException e) {
700 * Returns the plugin's resource bundle,
702 // public ResourceBundle getResourceBundle() {
703 // return resourceBundle;
705 protected void initializeDefaultPreferences(IPreferenceStore store) {
706 String operatingSystem = Platform.getOS();
707 // maxosx, linux, solaris, win32,...
709 InputStream is = getDefault().openStream(
710 new Path("prefs/default_" + operatingSystem + ".properties"));
711 PropertyResourceBundle resourceBundle = new PropertyResourceBundle(is);
712 Enumeration e = resourceBundle.getKeys();
714 while (e.hasMoreElements()) {
715 key = (String)e.nextElement();
716 store.setDefault(key, resourceBundle.getString( key ));
718 } catch (Exception e) {
719 // no default properties found
720 if (operatingSystem.equals(Platform.OS_WIN32)) {
721 // store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
722 // store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
723 // store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
724 // store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
725 // store.setDefault(XAMPP_START_PREF, "c:\\xampp\\xampp_start.exe");
726 // store.setDefault(XAMPP_STOP_PREF, "c:\\xampp\\xampp_stop.exe");
728 // ETC_HOSTS_PATH_PREF, "c:\\windows\\system32\\drivers\\etc\\hosts");
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_VARIABLE_DOLLAR, PHPColorProvider.VARIABLE);
778 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME, PHPColorProvider.FUNCTION_NAME);
779 PreferenceConverter.setDefault(store, PHP_CONSTANT, PHPColorProvider.CONSTANT);
780 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
781 // PreferenceConverter.setDefault(store, PHP_STRING_DQ, PHPColorProvider.STRING_DQ);
782 // store.setDefault(PHP_STRING_BOLD_DQ, true);
783 // PreferenceConverter.setDefault(store, PHP_STRING_SQ, PHPColorProvider.STRING_SQ);
784 PreferenceConverter.setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
785 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD, PHPColorProvider.PHPDOC_KEYWORD);
786 PreferenceConverter.setDefault(store, PHPDOC_TAG, PHPColorProvider.PHPDOC_TAG);
787 PreferenceConverter.setDefault(store, PHPDOC_LINK, PHPColorProvider.PHPDOC_LINK);
788 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT, PHPColorProvider.PHPDOC_DEFAULT);
790 PreferenceConverter.setDefault(store, EDITOR_PHP_KEYWORD_RETURN_COLOR, new RGB(127, 0, 85));
791 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_BOLD, true);
792 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_ITALIC, false);
794 PreferenceConverter.setDefault(store, EDITOR_PHP_OPERATOR_COLOR, new RGB(0, 0, 0));
795 store.setDefault(EDITOR_PHP_OPERATOR_BOLD, false);
796 store.setDefault(EDITOR_PHP_OPERATOR_ITALIC, false);
798 PreferenceConverter.setDefault(store, EDITOR_PHP_BRACE_OPERATOR_COLOR, new RGB(0, 0, 0));
799 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_BOLD, false);
800 store.setDefault(EDITOR_PHP_BRACE_OPERATOR_ITALIC, false);
801 // PreferenceConverter.setDefault(
803 // PHP_EDITOR_BACKGROUND,
804 // PHPColorProvider.BACKGROUND);
805 // PreferenceConverter.setDefault(
807 // LINKED_POSITION_COLOR,
808 // PHPColorProvider.LINKED_POSITION_COLOR);
809 // PreferenceConverter.setDefault(
811 // LINE_NUMBER_COLOR,
812 // PHPColorProvider.LINE_NUMBER_COLOR);
813 // // set default PHPDoc colors:
814 // PreferenceConverter.setDefault(
817 // PHPColorProvider.PHPDOC_KEYWORD);
818 // PreferenceConverter.setDefault(
821 // PHPColorProvider.PHPDOC_LINK);
822 // PreferenceConverter.setDefault(
825 // PHPColorProvider.PHPDOC_DEFAULT);
826 // PreferenceConverter.setDefault(
829 // PHPColorProvider.PHPDOC_TAG);
830 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
831 // PreferenceConverter.setDefault(
833 // PREFERENCE_COLOR_BACKGROUND,
834 // PHPColorProvider.BACKGROUND_COLOR);
836 // store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
837 // store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
838 // store.setDefault(RESOURCE_BUNDLE_DE, "false");
839 // store.setDefault(RESOURCE_BUNDLE_FR, "false");
840 // store.setDefault(RESOURCE_BUNDLE_ES, "false");
841 // TemplatePreferencePage.initDefaults(store);
842 //this will initialize the static fields in the syntaxrdr class
844 JavaCore.initializeDefaultPluginPreferences();
845 PreferenceConstants.initializeDefaultValues(store);
846 // externalTools.initializeDefaultPreferences(store);
847 MarkerAnnotationPreferences.initializeDefaultValues(store);
850 private IWorkbenchPage internalGetActivePage() {
851 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
853 return window.getActivePage();
857 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
858 if (fImageDescriptorRegistry == null)
859 fImageDescriptorRegistry = new ImageDescriptorRegistry();
860 return fImageDescriptorRegistry;
864 * Open a file in the Workbench that may or may not exist in the workspace. Must be run on the UI thread.
867 * @throws CoreException
869 public ITextEditor openFileInTextEditor(String filename) throws CoreException {
870 // reject directories
871 if (new File(filename).isDirectory())
873 IWorkbench workbench = PlatformUI.getWorkbench();
874 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
875 IWorkbenchPage page = window.getActivePage();
876 IPath path = new Path(filename);
877 // If the file exists in the workspace, open it
878 IFile file = getWorkspace().getRoot().getFileForLocation(path);
880 ITextEditor textEditor;
881 if (file != null && file.exists()) {
882 editor = IDE.openEditor(page, file, true);
883 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
885 // Otherwise open the stream directly
888 FileStorage storage = new FileStorage(path);
889 IEditorRegistry registry = getWorkbench().getEditorRegistry();
890 IEditorDescriptor desc = registry.getDefaultEditor(filename);
892 desc = registry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
893 // desc = registry.getDefaultEditor();
895 IEditorInput input = new ExternalEditorInput(storage);
896 editor = page.openEditor(input, desc.getId());
897 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
898 // If the storage provider is not ours, we can't guarantee read/write.
899 if (textEditor != null) {
900 IDocumentProvider documentProvider = textEditor.getDocumentProvider();
901 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
902 storage.setReadOnly();
910 * Open a file in the Workbench that may or may not exist in the workspace. Must be run on the UI thread.
914 * @throws CoreException
916 public void openFileAndGotoLine(String filename, int line) throws CoreException {
917 ITextEditor textEditor = openFileInTextEditor(filename);
918 if (textEditor != null) {
919 // If a line number was given, go to it
922 line--; // document is 0 based
923 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
924 textEditor.selectAndReveal(document.getLineOffset(line), document.getLineLength(line));
925 } catch (BadLocationException e) {
926 // invalid text position -> do nothing
933 * Open a file in the Workbench that may or may not exist in the workspace. Must be run on the UI thread.
937 * @throws CoreException
939 public void openFileAndGotoOffset(String filename, int offset, int length) throws CoreException {
940 ITextEditor textEditor = openFileInTextEditor(filename);
941 if (textEditor != null) {
942 // If a line number was given, go to it
944 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
945 textEditor.selectAndReveal(offset, length);
950 public void openFileAndFindString(String filename, String findString) throws CoreException {
951 ITextEditor textEditor = openFileInTextEditor(filename);
952 if (textEditor != null) {
953 // If a string was given, go to it
954 if (findString != null) {
956 IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
957 int offset = document.search(0, findString, true, false, true);
958 textEditor.selectAndReveal(offset, findString.length());
959 } catch (BadLocationException e) {
960 // invalid text position -> do nothing
966 public void setLastEditorFile(IFile textEditor) {
967 this.fLastEditorFile = textEditor;
971 * @see org.eclipse.core.runtime.Plugin#stop
973 public void stop(BundleContext context) throws Exception {
975 // JavaCore.stop(this, context);
976 plugin.savePluginPreferences();
977 IWorkspace workspace = ResourcesPlugin.getWorkspace();
978 workspace.removeResourceChangeListener(JavaModelManager.getJavaModelManager().deltaState);
979 workspace.removeSaveParticipant(plugin);
981 JavaModelManager.getJavaModelManager().shutdown();
983 // save the information from the php index files if necessary
984 Collection collection = fIndexManagerMap.values();
985 Iterator iterator = collection.iterator();
986 IdentifierIndexManager indexManager = null;
987 while (iterator.hasNext()) {
988 indexManager = (IdentifierIndexManager) iterator.next();
989 indexManager.writeFile();
991 if (fImageDescriptorRegistry != null)
992 fImageDescriptorRegistry.dispose();
994 // AllTypesCache.terminate();
996 if (fImageDescriptorRegistry != null)
997 fImageDescriptorRegistry.dispose();
999 unregisterAdapters();
1001 // if (fASTProvider != null) {
1002 // fASTProvider.dispose();
1003 // fASTProvider= null;
1006 if (fWorkingCopyManager != null) {
1007 fWorkingCopyManager.shutdown();
1008 fWorkingCopyManager = null;
1011 if (fCompilationUnitDocumentProvider != null) {
1012 fCompilationUnitDocumentProvider.shutdown();
1013 fCompilationUnitDocumentProvider = null;
1016 if (fJavaTextTools != null) {
1017 fJavaTextTools.dispose();
1018 fJavaTextTools = null;
1020 // JavaDocLocations.shutdownJavadocLocations();
1022 uninstallPreferenceStoreBackwardsCompatibility();
1024 // RefactoringCore.getUndoManager().shutdown();
1026 super.stop(context);
1031 * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
1033 // public void shutdown() throws CoreException {
1034 // // moved down (see below):
1035 // // super.shutdown();
1036 // // externalTools.shutDown();
1037 // ColorManager.getDefault().dispose();
1038 // // save the information from the php index files if necessary
1039 // Collection collection = fIndexManagerMap.values();
1040 // Iterator iterator = collection.iterator();
1041 // IdentifierIndexManager indexManager = null;
1042 // while (iterator.hasNext()) {
1043 // indexManager = (IdentifierIndexManager) iterator.next();
1044 // indexManager.writeFile();
1046 // if (fImageDescriptorRegistry != null)
1047 // fImageDescriptorRegistry.dispose();
1048 // // unregisterAdapters();
1049 // super.shutdown();
1050 // if (fWorkingCopyManager != null) {
1051 // fWorkingCopyManager.shutdown();
1052 // fWorkingCopyManager = null;
1054 // if (fCompilationUnitDocumentProvider != null) {
1055 // fCompilationUnitDocumentProvider.shutdown();
1056 // fCompilationUnitDocumentProvider = null;
1058 // if (fJavaTextTools != null) {
1059 // fJavaTextTools.dispose();
1060 // fJavaTextTools = null;
1062 // // JavaDocLocations.shutdownJavadocLocations();
1065 // JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
1066 // // begin JavaCore#shutdown()
1067 // //savePluginPreferences();
1068 // savePluginPreferences();
1069 // IWorkspace workspace = ResourcesPlugin.getWorkspace();
1070 // workspace.removeResourceChangeListener(JavaModelManager.getJavaModelManager().deltaState);
1071 // workspace.removeSaveParticipant(this);
1072 // ((JavaModelManager) JavaModelManager.getJavaModelManager()).shutdown();
1073 // // end JavaCore#shutdown()
1076 * Installs backwards compatibility for the preference store.
1078 private void installPreferenceStoreBackwardsCompatibility() {
1081 * Installs backwards compatibility: propagate the Java editor font from a pre-2.1 plug-in to the Platform UI's preference store
1082 * to preserve the Java editor font from a pre-2.1 workspace. This is done only once.
1084 String fontPropagatedKey = "fontPropagated"; //$NON-NLS-1$
1085 if (getPreferenceStore().contains(JFaceResources.TEXT_FONT) && !getPreferenceStore().isDefault(JFaceResources.TEXT_FONT)) {
1086 if (!getPreferenceStore().getBoolean(fontPropagatedKey))
1087 PreferenceConverter.setValue(PlatformUI.getWorkbench().getPreferenceStore(), PreferenceConstants.EDITOR_TEXT_FONT,
1088 PreferenceConverter.getFontDataArray(getPreferenceStore(), JFaceResources.TEXT_FONT));
1090 getPreferenceStore().setValue(fontPropagatedKey, true);
1093 * Backwards compatibility: set the Java editor font in this plug-in's preference store to let older versions access it. Since
1094 * 2.1 the Java editor font is managed by the workbench font preference page.
1096 PreferenceConverter.putValue(getPreferenceStore(), JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry().getFontData(
1097 PreferenceConstants.EDITOR_TEXT_FONT));
1099 fFontPropertyChangeListener = new IPropertyChangeListener() {
1100 public void propertyChange(PropertyChangeEvent event) {
1101 if (PreferenceConstants.EDITOR_TEXT_FONT.equals(event.getProperty()))
1102 PreferenceConverter.putValue(getPreferenceStore(), JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry()
1103 .getFontData(PreferenceConstants.EDITOR_TEXT_FONT));
1106 JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
1109 * Backwards compatibility: propagate the Java editor tab width from a pre-3.0 plug-in to the new preference key. This is done
1112 // final String oldTabWidthKey = PreferenceConstants.EDITOR_TAB_WIDTH;
1113 // final String newTabWidthKey = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH;
1114 // String tabWidthPropagatedKey = "tabWidthPropagated"; //$NON-NLS-1$
1115 // if (getPreferenceStore().contains(oldTabWidthKey) && !getPreferenceStore().isDefault(oldTabWidthKey)) {
1116 // if (!getPreferenceStore().getBoolean(tabWidthPropagatedKey))
1117 // getPreferenceStore().setValue(newTabWidthKey, getPreferenceStore().getInt(oldTabWidthKey));
1119 // getPreferenceStore().setValue(tabWidthPropagatedKey, true);
1122 // * Backwards compatibility: set the Java editor tab width in this plug-in's preference store with the old key to let older
1123 // * versions access it. Since 3.0 the tab width is managed by the extended texteditor and uses a new key.
1125 // getPreferenceStore().putValue(oldTabWidthKey, getPreferenceStore().getString(newTabWidthKey));
1126 // fPropertyChangeListener = new IPropertyChangeListener() {
1127 // public void propertyChange(PropertyChangeEvent event) {
1128 // if (newTabWidthKey.equals(event.getProperty()))
1129 // getPreferenceStore().putValue(oldTabWidthKey, getPreferenceStore().getString(newTabWidthKey));
1132 // getPreferenceStore().addPropertyChangeListener(fPropertyChangeListener);
1134 * Backward compatibility for the refactoring preference key.
1136 // getPreferenceStore().setValue(
1137 // PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD,
1138 // RefactoringCore.getConditionCheckingFailedSeverity());
1142 * Uninstalls backwards compatibility for the preference store.
1144 private void uninstallPreferenceStoreBackwardsCompatibility() {
1145 JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
1146 // getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
1150 * (non - Javadoc) Method declared in Plugin
1152 public void start(BundleContext context) throws Exception {
1153 super.start(context);
1155 // JavaCore.start(this, context);
1156 final JavaModelManager manager = JavaModelManager.getJavaModelManager();
1158 manager.configurePluginDebugOptions();
1160 // request state folder creation (workaround 19885)
1161 // JavaCore.getPlugin().getStateLocation();
1163 // retrieve variable values
1164 PHPeclipsePlugin.getDefault().getPluginPreferences().addPropertyChangeListener(
1165 new JavaModelManager.PluginPreferencesListener());
1166 // manager.loadVariablesAndContainers();
1168 final IWorkspace workspace = ResourcesPlugin.getWorkspace();
1169 workspace.addResourceChangeListener(manager.deltaState, IResourceChangeEvent.PRE_BUILD | IResourceChangeEvent.POST_BUILD
1170 | IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.PRE_CLOSE);
1173 ISavedState savedState = workspace.addSaveParticipant(PHPeclipsePlugin.this, manager);
1175 // process deltas since last activated in indexer thread so that indexes are up-to-date.
1176 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658
1177 Job processSavedState = new Job(Util.bind("savedState.jobName")) { //$NON-NLS-1$
1178 protected IStatus run(IProgressMonitor monitor) {
1180 // add save participant and process delta atomically
1181 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59937
1182 workspace.run(new IWorkspaceRunnable() {
1183 public void run(IProgressMonitor progress) throws CoreException {
1184 ISavedState savedState = workspace.addSaveParticipant(PHPeclipsePlugin.this, manager);
1185 if (savedState != null) {
1186 // the event type coming from the saved state is always POST_AUTO_BUILD
1187 // force it to be POST_CHANGE so that the delta processor can handle it
1188 manager.deltaState.getDeltaProcessor().overridenEventType = IResourceChangeEvent.POST_CHANGE;
1189 savedState.processResourceChangeEvents(manager.deltaState);
1193 } catch (CoreException e) {
1194 return e.getStatus();
1196 return Status.OK_STATUS;
1199 processSavedState.setSystem(true);
1200 processSavedState.setPriority(Job.SHORT); // process asap
1201 processSavedState.schedule();
1202 } catch (RuntimeException e) {
1209 // if (USE_WORKING_COPY_OWNERS) {
1210 WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
1211 public IBuffer createBuffer(ICompilationUnit workingCopy) {
1212 ICompilationUnit original = workingCopy.getPrimary();
1213 IResource resource = original.getResource();
1214 if (resource instanceof IFile)
1215 return new DocumentAdapter(workingCopy, (IFile) resource);
1216 return DocumentAdapter.NULL;
1221 installPreferenceStoreBackwardsCompatibility();
1225 // registerAdapters();
1227 // // externalTools.startUp();
1228 // getStandardDisplay().asyncExec(new Runnable() {
1229 // public void run() {
1230 // //initialize the variable context manager
1231 // VariableContextManager.getDefault();
1235 // // if (USE_WORKING_COPY_OWNERS) {
1236 // WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
1237 // public IBuffer createBuffer(ICompilationUnit workingCopy) {
1238 // ICompilationUnit original = workingCopy.getPrimary();
1239 // IResource resource = original.getResource();
1240 // if (resource instanceof IFile)
1241 // return new DocumentAdapter(workingCopy, (IFile) resource);
1242 // return DocumentAdapter.NULL;
1247 // installPreferenceStoreBackwardsCompatibility();
1249 // AllTypesCache.initialize();
1251 // Initialize AST provider
1252 // getASTProvider();
1255 // public void startup() throws CoreException {
1257 // // begin JavaCore.startup();
1258 // JavaModelManager manager = JavaModelManager.getJavaModelManager();
1260 // manager.configurePluginDebugOptions();
1261 // // request state folder creation (workaround 19885)
1262 // // JavaCore.getPlugin().getStateLocation();
1263 // getStateLocation();
1264 // // retrieve variable values
1266 // JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new
1267 // // JavaModelManager.PluginPreferencesListener());
1268 // getPluginPreferences().addPropertyChangeListener(
1269 // new JavaModelManager.PluginPreferencesListener());
1271 // // manager.loadVariablesAndContainers();
1272 // final IWorkspace workspace = ResourcesPlugin.getWorkspace();
1273 // workspace.addResourceChangeListener(
1274 // manager.deltaState,
1275 // IResourceChangeEvent.PRE_BUILD
1276 // | IResourceChangeEvent.POST_BUILD
1277 // | IResourceChangeEvent.POST_CHANGE
1278 // | IResourceChangeEvent.PRE_DELETE
1279 // | IResourceChangeEvent.PRE_CLOSE);
1280 // // startIndexing();
1281 // workspace.addSaveParticipant(PHPeclipsePlugin.getDefault(), manager);
1282 // } catch (CoreException e) {
1283 // } catch (RuntimeException e) {
1284 // manager.shutdown();
1287 // // end JavaCore.startup();
1288 // IAdapterManager platformManager = Platform.getAdapterManager();
1289 // platformManager.registerAdapters(new PHPElementAdapterFactory(),
1290 // PHPElement.class);
1291 // platformManager.registerAdapters(new ResourceAdapterFactory(),
1292 // IResource.class);
1293 // // externalTools.startUp();
1294 // getStandardDisplay().asyncExec(new Runnable() {
1295 // public void run() {
1296 // //initialize the variable context manager
1297 // VariableContextManager.getDefault();
1302 private void registerAdapters() {
1303 fJavaElementAdapterFactory = new JavaElementAdapterFactory();
1304 // fMarkerAdapterFactory= new MarkerAdapterFactory();
1305 // fEditorInputAdapterFactory= new EditorInputAdapterFactory();
1306 fResourceAdapterFactory = new ResourceAdapterFactory();
1307 // fLogicalPackageAdapterFactory= new LogicalPackageAdapterFactory();
1309 IAdapterManager manager = Platform.getAdapterManager();
1310 manager.registerAdapters(fJavaElementAdapterFactory, IJavaElement.class);
1311 // manager.registerAdapters(fMarkerAdapterFactory, IMarker.class);
1312 // manager.registerAdapters(fEditorInputAdapterFactory, IEditorInput.class);
1313 manager.registerAdapters(fResourceAdapterFactory, IResource.class);
1314 // manager.registerAdapters(fLogicalPackageAdapterFactory,
1315 // LogicalPackage.class);
1318 private void unregisterAdapters() {
1319 IAdapterManager manager = Platform.getAdapterManager();
1320 manager.unregisterAdapters(fJavaElementAdapterFactory);
1321 // manager.unregisterAdapters(fMarkerAdapterFactory);
1322 // manager.unregisterAdapters(fEditorInputAdapterFactory);
1323 manager.unregisterAdapters(fResourceAdapterFactory);
1324 // manager.unregisterAdapters(fLogicalPackageAdapterFactory);
1328 * Returns a combined preference store, this store is read-only.
1330 * @return the combined preference store
1334 public IPreferenceStore getCombinedPreferenceStore() {
1335 if (fCombinedPreferenceStore == null) {
1336 IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
1337 fCombinedPreferenceStore = new ChainedPreferenceStore(new IPreferenceStore[] {
1338 getPreferenceStore(),
1339 new PreferencesAdapter(PHPeclipsePlugin.getDefault().getPluginPreferences()),
1340 generalTextStore });
1342 return fCombinedPreferenceStore;
1345 public synchronized IBufferFactory getBufferFactory() {
1346 if (fBufferFactory == null)
1347 fBufferFactory = new CustomBufferFactory();
1348 return fBufferFactory;
1352 * Returns the registry of the extensions to the <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code> extension
1355 * @return the registry of contributed <code>IJavaFoldingStructureProvider</code>
1358 public synchronized JavaFoldingStructureProviderRegistry getFoldingStructureProviderRegistry() {
1359 if (fFoldingStructureProviderRegistry == null)
1360 fFoldingStructureProviderRegistry = new JavaFoldingStructureProviderRegistry();
1361 return fFoldingStructureProviderRegistry;
1365 * Runs the given action as an atomic Java model operation.
1367 * After running a method that modifies java elements, registered listeners receive after-the-fact notification of what just
1368 * transpired, in the form of a element changed event. This method allows clients to call a number of methods that modify java
1369 * elements and only have element changed event notifications reported at the end of the entire batch.
1372 * If this method is called outside the dynamic scope of another such call, this method runs the action and then reports a single
1373 * element changed event describing the net effect of all changes done to java elements by the action.
1376 * If this method is called in the dynamic scope of another such call, this method simply runs the action.
1380 * the action to perform
1382 * a progress monitor, or <code>null</code> if progress reporting and cancellation are not desired
1383 * @exception CoreException
1384 * if the operation failed.
1387 public static void run(IWorkspaceRunnable action, IProgressMonitor monitor) throws CoreException {
1388 run(action, ResourcesPlugin.getWorkspace().getRoot(), monitor);
1392 * Runs the given action as an atomic Java model operation.
1394 * After running a method that modifies java elements, registered listeners receive after-the-fact notification of what just
1395 * transpired, in the form of a element changed event. This method allows clients to call a number of methods that modify java
1396 * elements and only have element changed event notifications reported at the end of the entire batch.
1399 * If this method is called outside the dynamic scope of another such call, this method runs the action and then reports a single
1400 * element changed event describing the net effect of all changes done to java elements by the action.
1403 * If this method is called in the dynamic scope of another such call, this method simply runs the action.
1406 * The supplied scheduling rule is used to determine whether this operation can be run simultaneously with workspace changes in
1407 * other threads. See <code>IWorkspace.run(...)</code> for more details.
1411 * the action to perform
1413 * the scheduling rule to use when running this operation, or <code>null</code> if there are no scheduling restrictions
1414 * for this operation.
1416 * a progress monitor, or <code>null</code> if progress reporting and cancellation are not desired
1417 * @exception CoreException
1418 * if the operation failed.
1421 public static void run(IWorkspaceRunnable action, ISchedulingRule rule, IProgressMonitor monitor) throws CoreException {
1422 IWorkspace workspace = ResourcesPlugin.getWorkspace();
1423 if (workspace.isTreeLocked()) {
1424 new BatchOperation(action).run(monitor);
1426 // use IWorkspace.run(...) to ensure that a build will be done in
1428 workspace.run(new BatchOperation(action), rule, IWorkspace.AVOID_UPDATE, monitor);
1433 * Returns the template context type registry for the java plugin.
1435 * @return the template context type registry for the java plugin
1438 public ContextTypeRegistry getTemplateContextRegistry() {
1439 if (fContextTypeRegistry == null) {
1440 fContextTypeRegistry = new ContributionContextTypeRegistry();
1442 fContextTypeRegistry.addContextType(new JavaContextType());
1443 fContextTypeRegistry.addContextType(new JavaDocContextType());
1444 fContextTypeRegistry.addContextType(new HTMLContextType());
1447 return fContextTypeRegistry;
1451 * Returns the template store for the java editor templates.
1453 * @return the template store for the java editor templates
1456 public TemplateStore getTemplateStore() {
1457 if (fTemplateStore == null) {
1458 // boolean alreadyMigrated= getPreferenceStore().getBoolean(TEMPLATES_MIGRATION_KEY);
1459 // if (alreadyMigrated)
1460 fTemplateStore = new ContributionTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), TEMPLATES_KEY);
1462 // fTemplateStore= new CompatibilityTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), TEMPLATES_KEY,
1463 // Templates.getInstance());
1464 // getPreferenceStore().setValue(TEMPLATES_MIGRATION_KEY, true);
1468 fTemplateStore.load();
1469 } catch (IOException e) {
1474 return fTemplateStore;
1478 * Returns the template context type registry for the code generation templates.
1480 * @return the template context type registry for the code generation templates
1483 public ContextTypeRegistry getCodeTemplateContextRegistry() {
1484 if (fCodeTemplateContextTypeRegistry == null) {
1485 fCodeTemplateContextTypeRegistry = new ContributionContextTypeRegistry();
1487 CodeTemplateContextType.registerContextTypes(fCodeTemplateContextTypeRegistry);
1490 return fCodeTemplateContextTypeRegistry;
1494 * Returns the template store for the code generation templates.
1496 * @return the template store for the code generation templates
1499 public TemplateStore getCodeTemplateStore() {
1500 if (fCodeTemplateStore == null) {
1501 // boolean alreadyMigrated= getPreferenceStore().getBoolean(CODE_TEMPLATES_MIGRATION_KEY);
1502 // if (alreadyMigrated)
1503 fCodeTemplateStore = new ContributionTemplateStore(getCodeTemplateContextRegistry(), getPreferenceStore(), CODE_TEMPLATES_KEY);
1505 // fCodeTemplateStore= new CompatibilityTemplateStore(getCodeTemplateContextRegistry(), getPreferenceStore(),
1506 // CODE_TEMPLATES_KEY, CodeTemplates.getInstance());
1507 // getPreferenceStore().setValue(CODE_TEMPLATES_MIGRATION_KEY, true);
1511 fCodeTemplateStore.load();
1512 } catch (IOException e) {
1516 // compatibility / bug fixing code for duplicated templates
1517 // TODO remove for 3.0
1518 // CompatibilityTemplateStore.pruneDuplicates(fCodeTemplateStore, true);
1521 return fCodeTemplateStore;