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
9 IBM Corporation - Initial implementation
10 Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse;
15 import java.io.IOException;
16 import java.util.ArrayList;
17 import java.util.Collection;
18 import java.util.HashMap;
19 import java.util.HashSet;
20 import java.util.Iterator;
21 import java.util.List;
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.corext.template.php.CodeTemplateContextType;
35 import net.sourceforge.phpdt.internal.corext.template.php.HTMLContextType;
36 import net.sourceforge.phpdt.internal.corext.template.php.JavaContextType;
37 import net.sourceforge.phpdt.internal.corext.template.php.JavaDocContextType;
38 import net.sourceforge.phpdt.internal.ui.IJavaStatusConstants;
39 import net.sourceforge.phpdt.internal.ui.JavaElementAdapterFactory;
40 import net.sourceforge.phpdt.internal.ui.ResourceAdapterFactory;
41 import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache;
42 import net.sourceforge.phpdt.internal.ui.preferences.MockupPreferenceStore;
43 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
44 import net.sourceforge.phpdt.internal.ui.text.folding.JavaFoldingStructureProviderRegistry;
45 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
46 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
47 import net.sourceforge.phpdt.internal.ui.viewsupport.ProblemMarkerManager;
48 import net.sourceforge.phpdt.ui.IContextMenuConstants;
49 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
50 import net.sourceforge.phpdt.ui.PreferenceConstants;
51 import net.sourceforge.phpdt.ui.text.JavaTextTools;
52 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
53 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
54 import net.sourceforge.phpeclipse.builder.FileStorage;
55 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
56 import net.sourceforge.phpeclipse.phpeditor.CustomBufferFactory;
57 import net.sourceforge.phpeclipse.phpeditor.DocumentAdapter;
58 import net.sourceforge.phpeclipse.phpeditor.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.IPluginDescriptor;
76 import org.eclipse.core.runtime.IProgressMonitor;
77 import org.eclipse.core.runtime.IStatus;
78 import org.eclipse.core.runtime.Path;
79 import org.eclipse.core.runtime.Platform;
80 import org.eclipse.core.runtime.Status;
81 import org.eclipse.core.runtime.jobs.ISchedulingRule;
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.AbstractDecoratedTextEditorPreferenceConstants;
111 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
112 import org.eclipse.ui.texteditor.ConfigurationElementSorter;
113 import org.eclipse.ui.texteditor.IDocumentProvider;
114 import org.eclipse.ui.texteditor.ITextEditor;
115 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
116 import org.osgi.framework.BundleContext;
119 * The main plugin class to be used in the desktop.
121 public class PHPeclipsePlugin extends AbstractUIPlugin implements
122 IPreferenceConstants {
124 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
126 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
129 * id of builder - matches plugin.xml (concatenate pluginid.builderid)
131 public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
133 //public static final String BUILDER_INDEX_ID = PLUGIN_ID + ".indexbuilder";
134 /** General debug flag */
135 public static final boolean DEBUG = false;
138 * The maximum number of allowed proposals by category
140 public final static int MAX_PROPOSALS = 200;
143 * The key to store customized templates.
146 private static final String TEMPLATES_KEY= "net.sourceforge.phpdt.ui.text.custom_templates"; //$NON-NLS-1$
148 * The key to store customized code templates.
151 private static final String CODE_TEMPLATES_KEY= "net.sourceforge.phpdt.ui.text.custom_code_templates"; //$NON-NLS-1$
153 * The key to store whether the legacy templates have been migrated
156 // private static final String TEMPLATES_MIGRATION_KEY= "net.sourceforge.phpdt.ui.text.templates_migrated"; //$NON-NLS-1$
158 * The key to store whether the legacy code templates have been migrated
161 // private static final String CODE_TEMPLATES_MIGRATION_KEY= "net.sourceforge.phpdt.ui.text.code_templates_migrated"; //$NON-NLS-1$
164 private static ExternalToolsPlugin externalTools;
167 * The Java virtual machine that we are running on.
169 private static int jvm;
172 private static final int MRJ_2_0 = 0;
174 /** MRJ 2.1 or later */
175 private static final int MRJ_2_1 = 1;
177 /** Java on Mac OS X 10.0 (MRJ 3.0) */
178 private static final int MRJ_3_0 = 3;
181 private static final int MRJ_3_1 = 4;
183 /** JVM constant for any other platform */
184 private static final int OTHER = -1;
186 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID +
187 // ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
188 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID
189 + ".ui.CodingActionSet"; //$NON-NLS-1$
191 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
193 public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
195 public static final String PHPPARSER_NEW = "test.PHPParser";
197 /** Change this if you want to switch PHP Parser. */
198 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
200 //The shared instance.
201 private static PHPeclipsePlugin plugin;
204 * The template context type registry for the java editor.
207 private ContextTypeRegistry fContextTypeRegistry;
209 * The code template context type registry for the java editor.
212 private ContextTypeRegistry fCodeTemplateContextTypeRegistry;
215 * The template store for the java editor.
218 private TemplateStore fTemplateStore;
220 * The coded template store for the java editor.
223 private TemplateStore fCodeTemplateStore;
226 private static final int WINDOWS_9x = 6;
229 private static final int WINDOWS_NT = 5;
231 private ImageDescriptorRegistry fImageDescriptorRegistry;
233 private HashMap fIndexManagerMap = new HashMap();
235 private IWorkingCopyManager fWorkingCopyManager;
237 private IBufferFactory fBufferFactory;
239 private PHPDocumentProvider fCompilationUnitDocumentProvider;
241 private JavaTextTools fJavaTextTools;
243 private ProblemMarkerManager fProblemMarkerManager;
245 private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
247 private IFile fLastEditorFile = null;
249 private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
251 private JavaElementAdapterFactory fJavaElementAdapterFactory;
253 // private MarkerAdapterFactory fMarkerAdapterFactory;
254 // private EditorInputAdapterFactory fEditorInputAdapterFactory;
255 private ResourceAdapterFactory fResourceAdapterFactory;
257 // private LogicalPackageAdapterFactory fLogicalPackageAdapterFactory;
258 private IPropertyChangeListener fFontPropertyChangeListener;
261 * Property change listener on this plugin's preference store.
265 private IPropertyChangeListener fPropertyChangeListener;
268 * The combined preference store.
272 private IPreferenceStore fCombinedPreferenceStore;
275 * The extension point registry for the
276 * <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code> extension
281 private JavaFoldingStructureProviderRegistry fFoldingStructureProviderRegistry;
284 * Mockup preference store for firing events and registering listeners on
285 * project setting changes. FIXME: Temporary solution.
289 private MockupPreferenceStore fMockupPreferenceStore;
294 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
298 externalTools = new ExternalToolsPlugin();
301 // ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
302 // } catch (MissingResourceException x) {
303 // resourceBundle = null;
308 // * Returns all Java editor text hovers contributed to the workbench.
310 // * @return an array of JavaEditorTextHoverDescriptor
313 // public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors()
315 // if (fJavaEditorTextHoverDescriptors == null)
316 // fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
317 // .getContributedHovers();
318 // return fJavaEditorTextHoverDescriptors;
321 * Returns all Java editor text hovers contributed to the workbench.
323 * @return an array of JavaEditorTextHoverDescriptor
326 public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
327 if (fJavaEditorTextHoverDescriptors == null) {
328 fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
329 .getContributedHovers();
330 ConfigurationElementSorter sorter = new ConfigurationElementSorter() {
332 * @see org.eclipse.ui.texteditor.ConfigurationElementSorter#getConfigurationElement(java.lang.Object)
334 public IConfigurationElement getConfigurationElement(Object object) {
335 return ((JavaEditorTextHoverDescriptor) object)
336 .getConfigurationElement();
339 sorter.sort(fJavaEditorTextHoverDescriptors);
341 // The Problem hover has to be the first and the Annotation hover has to
342 // be the last one in the JDT UI's hover list
343 int length = fJavaEditorTextHoverDescriptors.length;
345 int last = length - 1;
346 int problemHoverIndex = -1;
347 int annotationHoverIndex = -1;
348 for (int i = 0; i < length; i++) {
349 if (!fJavaEditorTextHoverDescriptors[i].getId().startsWith(PLUGIN_ID)) {
350 if (problemHoverIndex == -1 || annotationHoverIndex == -1)
360 if (fJavaEditorTextHoverDescriptors[i].getId().equals(
361 "net.sourceforge.phpdt.ui.AnnotationHover")) { //$NON-NLS-1$
362 annotationHoverIndex = i;
365 if (fJavaEditorTextHoverDescriptors[i].getId().equals(
366 "net.sourceforge.phpdt.ui.ProblemHover")) { //$NON-NLS-1$
367 problemHoverIndex = i;
372 JavaEditorTextHoverDescriptor hoverDescriptor = null;
374 if (first > -1 && problemHoverIndex > -1 && problemHoverIndex != first) {
375 // move problem hover to beginning
376 hoverDescriptor = fJavaEditorTextHoverDescriptors[first];
377 fJavaEditorTextHoverDescriptors[first] = fJavaEditorTextHoverDescriptors[problemHoverIndex];
378 fJavaEditorTextHoverDescriptors[problemHoverIndex] = hoverDescriptor;
380 // update annotation hover index if needed
381 if (annotationHoverIndex == first)
382 annotationHoverIndex = problemHoverIndex;
385 if (annotationHoverIndex > -1 && annotationHoverIndex != last) {
386 // move annotation hover to end
387 hoverDescriptor = fJavaEditorTextHoverDescriptors[last];
388 fJavaEditorTextHoverDescriptors[last] = fJavaEditorTextHoverDescriptors[annotationHoverIndex];
389 fJavaEditorTextHoverDescriptors[annotationHoverIndex] = hoverDescriptor;
392 // Move Best Match hover to front
393 for (int i = 0; i < fJavaEditorTextHoverDescriptors.length - 1; i++) {
394 if (PreferenceConstants.ID_BESTMATCH_HOVER
395 .equals(fJavaEditorTextHoverDescriptors[i].getId())) {
396 hoverDescriptor = fJavaEditorTextHoverDescriptors[i];
397 for (int j = i; j > 0; j--)
398 fJavaEditorTextHoverDescriptors[j] = fJavaEditorTextHoverDescriptors[j - 1];
399 fJavaEditorTextHoverDescriptors[0] = hoverDescriptor;
406 return fJavaEditorTextHoverDescriptors;
410 * Resets the Java editor text hovers contributed to the workbench.
412 * This will force a rebuild of the descriptors the next time a client asks
416 * @return an array of JavaEditorTextHoverDescriptor
419 public void resetJavaEditorTextHoverDescriptors() {
420 fJavaEditorTextHoverDescriptors = null;
424 * Creates the PHP plugin standard groups in a context menu.
426 public static void createStandardGroups(IMenuManager menu) {
429 menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
430 menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
431 menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
432 menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
433 menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
434 menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
435 menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
436 menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
437 menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
438 menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
439 menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
442 public static IWorkbenchPage getActivePage() {
443 return getDefault().internalGetActivePage();
446 public static Shell getActiveWorkbenchShell() {
447 return getActiveWorkbenchWindow().getShell();
451 * Returns an array of all editors that have an unsaved content. If the
452 * identical content is presented in more than one editor, only one of those
453 * 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().getDescriptor().getInstallURL().getFile());
498 public static int getJVM() {
502 public static String getPluginId() {
503 return getDefault().getDescriptor().getUniqueIdentifier();
507 * Returns the standard display to be used. The method first checks, if the
508 * thread calling this method has an associated display. If so, this display
509 * is returned. Otherwise the method returns the default display.
511 public static Display getStandardDisplay() {
512 Display display = Display.getCurrent();
513 if (display == null) {
514 display = Display.getDefault();
519 // public static ExternalToolsPlugin getExternalTools() {
520 // return externalTools;
523 * Returns the workspace instance.
525 public static IWorkspace getWorkspace() {
526 return ResourcesPlugin.getWorkspace();
529 public static boolean isDebug() {
530 return getDefault().isDebugging();
533 // public static void logErrorMessage(String message) {
534 // log(new Status(IStatus.ERROR, getPluginId(),
535 // JavaStatusConstants.INTERNAL_ERROR, message, null));
538 // public static void logErrorStatus(String message, IStatus status) {
539 // if (status == null) {
540 // logErrorMessage(message);
543 // MultiStatus multi= new MultiStatus(getPluginId(),
544 // JavaStatusConstants.INTERNAL_ERROR, message, null);
545 // multi.add(status);
549 // public static void log(Throwable e) {
550 // log(new Status(IStatus.ERROR, getPluginId(),
551 // JavaStatusConstants.INTERNAL_ERROR,
552 // JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
554 public static void log(int severity, String message) {
555 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
559 public static void log(IStatus status) {
560 getDefault().getLog().log(status);
563 public static void log(Throwable e) {
564 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
565 "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
568 public static void logErrorMessage(String message) {
569 log(new Status(IStatus.ERROR, getPluginId(),
570 IJavaStatusConstants.INTERNAL_ERROR, message, null));
573 private static void setJVM() {
574 String osName = System.getProperty("os.name");
575 if (osName.startsWith("Mac OS")) {
576 String mrjVersion = System.getProperty("mrj.version");
577 String majorMRJVersion = mrjVersion.substring(0, 3);
580 double version = Double.valueOf(majorMRJVersion).doubleValue();
583 } else if (version >= 2.1 && version < 3) {
585 } else if (version == 3.0) {
587 } else if (version >= 3.1) {
590 } catch (NumberFormatException nfe) {
592 } else if (osName.startsWith("Windows")) {
593 if (osName.indexOf("9") != -1) {
601 // TODO: refactor this into a better method name !
602 public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
603 if (fCompilationUnitDocumentProvider == null)
604 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
605 return fCompilationUnitDocumentProvider;
609 * Get the identifier index manager for the given project
612 * the current project
615 public IdentifierIndexManager getIndexManager(IProject iProject) {
616 String indexFilename = iProject.getLocation() + File.separator
618 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap
620 if (indexManager == null) {
621 indexManager = new IdentifierIndexManager(indexFilename);
622 fIndexManagerMap.put(indexFilename, indexManager);
627 public synchronized IWorkingCopyManager getWorkingCopyManager() {
628 if (fWorkingCopyManager == null) {
629 PHPDocumentProvider provider = getCompilationUnitDocumentProvider();
630 fWorkingCopyManager = new WorkingCopyManager(provider);
632 return fWorkingCopyManager;
635 public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
636 if (fMembersOrderPreferenceCache == null)
637 fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
638 return fMembersOrderPreferenceCache;
642 * Returns the mockup preference store for firing events and registering
643 * listeners on project setting changes. Temporary solution.
645 public MockupPreferenceStore getMockupPreferenceStore() {
646 if (fMockupPreferenceStore == null)
647 fMockupPreferenceStore = new MockupPreferenceStore();
649 return fMockupPreferenceStore;
652 public synchronized ProblemMarkerManager getProblemMarkerManager() {
653 if (fProblemMarkerManager == null)
654 fProblemMarkerManager = new ProblemMarkerManager();
655 return fProblemMarkerManager;
658 // public synchronized JavaTextTools getJavaTextTools() {
659 // if (fJavaTextTools == null)
660 // fJavaTextTools = new JavaTextTools(getPreferenceStore());
661 // return fJavaTextTools;
663 public synchronized JavaTextTools getJavaTextTools() {
664 if (fJavaTextTools == null)
665 fJavaTextTools = new JavaTextTools(getPreferenceStore(), JavaCore
666 .getPlugin().getPluginPreferences());
667 return fJavaTextTools;
670 public IFile getLastEditorFile() {
671 return fLastEditorFile;
675 * Returns the string from the plugin's resource bundle, or 'key' if not
678 // public static String getResourceString(String key) {
679 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
681 // return bundle.getString(key);
682 // } catch (MissingResourceException e) {
687 * Returns the plugin's resource bundle,
689 // public ResourceBundle getResourceBundle() {
690 // return resourceBundle;
692 protected void initializeDefaultPreferences(IPreferenceStore store) {
693 // windows preferences:
694 // store.setDefault(LOCALHOST_PREF, "http://localhost");
695 // store.setDefault(DOCUMENTROOT_PREF,
696 // getWorkspace().getRoot().getLocation().toString());
697 // store.setDefault(PHP_LOCALHOST_PREF, "http://localhost");
698 // store.setDefault(PHP_DOCUMENTROOT_PREF, getWorkspace().getRoot()
699 // .getLocation().toString());
701 // store.setDefault(SHOW_EXTERNAL_PREVIEW_PREF, "true");
702 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
703 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
704 store.setDefault(PHP_OBFUSCATOR_DEFAULT, "c:\\temp");
705 // store.setDefault(PHP_BOOKMARK_DEFAULT, "");
707 // store.setDefault(PHP_AUTO_PREVIEW_DEFAULT, "true");
708 // store.setDefault(PHP_BRING_TO_TOP_PREVIEW_DEFAULT, "true");
709 // store.setDefault(PHP_SHOW_HTML_FILES_LOCAL, "true");
711 String windowsSystem = Platform.getWS();
712 if (jvm == WINDOWS_9x) {
713 store.setDefault(EXTERNAL_BROWSER_PREF,
714 "command.com /c start iexplore {0}");
715 } else if (windowsSystem.equals(Platform.WS_WIN32)) {
716 store.setDefault(EXTERNAL_BROWSER_PREF,
717 "rundll32 url.dll,FileProtocolHandler {0}");
718 } else if (windowsSystem.equals(Platform.WS_CARBON)) {
719 // TODO How do we start Safari on Mac OS X ?
720 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
722 store.setDefault(PHP_OBFUSCATOR_DEFAULT, "/tmp");
723 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
725 // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
727 if (windowsSystem.equals(Platform.WS_WIN32)) {
728 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
729 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
730 store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
731 store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
733 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
734 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
735 store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
736 store.setDefault(APACHE_RUN_PREF, "/apache/apache");
738 store.setDefault(MYSQL_PREF, "--standalone");
739 store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
740 store.setDefault(APACHE_STOP_PREF, "-k shutdown");
741 store.setDefault(APACHE_RESTART_PREF, "-k restart");
742 store.setDefault(MYSQL_START_BACKGROUND, "true");
743 store.setDefault(APACHE_START_BACKGROUND, "true");
744 store.setDefault(APACHE_STOP_BACKGROUND, "true");
745 store.setDefault(APACHE_RESTART_BACKGROUND, "true");
746 // store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
747 // store.setDefault(PHP_INTERNAL_PARSER, "false");
748 // store.setDefault(PHP_EXTERNAL_PARSER, "true");
749 // store.setDefault(PHP_PARSE_ON_SAVE, "true");
750 // show line numbers:
751 // store.setDefault(LINE_NUMBER_RULER, "false");
752 // store.setDefault(FORMATTER_TAB_SIZE, "4");
753 // php syntax highlighting
754 store.setDefault(PHP_USERDEF_XMLFILE, "");
755 //assume there is none chooA
756 PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT,
757 PHPColorProvider.MULTI_LINE_COMMENT);
758 PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT,
759 PHPColorProvider.SINGLE_LINE_COMMENT);
760 PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
762 .setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
763 PreferenceConverter.setDefault(store, PHP_VARIABLE,
764 PHPColorProvider.VARIABLE);
765 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME,
766 PHPColorProvider.FUNCTION_NAME);
767 PreferenceConverter.setDefault(store, PHP_CONSTANT,
768 PHPColorProvider.CONSTANT);
769 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
770 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
772 .setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
773 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD,
774 PHPColorProvider.PHPDOC_KEYWORD);
775 PreferenceConverter.setDefault(store, PHPDOC_TAG,
776 PHPColorProvider.PHPDOC_TAG);
777 PreferenceConverter.setDefault(store, PHPDOC_LINK,
778 PHPColorProvider.PHPDOC_LINK);
779 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT,
780 PHPColorProvider.PHPDOC_DEFAULT);
782 PreferenceConverter.setDefault(store, EDITOR_PHP_KEYWORD_RETURN_COLOR,
783 new RGB(127, 0, 85));
784 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_BOLD, true);
785 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_ITALIC, false);
787 PreferenceConverter.setDefault(store, EDITOR_PHP_OPERATOR_COLOR, new RGB(0,
789 store.setDefault(EDITOR_PHP_OPERATOR_BOLD, false);
790 store.setDefault(EDITOR_PHP_OPERATOR_ITALIC, false);
792 // PreferenceConverter.setDefault(
794 // PHP_EDITOR_BACKGROUND,
795 // PHPColorProvider.BACKGROUND);
796 // PreferenceConverter.setDefault(
798 // LINKED_POSITION_COLOR,
799 // PHPColorProvider.LINKED_POSITION_COLOR);
800 // PreferenceConverter.setDefault(
802 // LINE_NUMBER_COLOR,
803 // PHPColorProvider.LINE_NUMBER_COLOR);
804 // // set default PHPDoc colors:
805 // PreferenceConverter.setDefault(
808 // PHPColorProvider.PHPDOC_KEYWORD);
809 // PreferenceConverter.setDefault(
812 // PHPColorProvider.PHPDOC_LINK);
813 // PreferenceConverter.setDefault(
816 // PHPColorProvider.PHPDOC_DEFAULT);
817 // PreferenceConverter.setDefault(
820 // PHPColorProvider.PHPDOC_TAG);
821 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
822 // PreferenceConverter.setDefault(
824 // PREFERENCE_COLOR_BACKGROUND,
825 // PHPColorProvider.BACKGROUND_COLOR);
827 // store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
828 // store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
829 // store.setDefault(RESOURCE_BUNDLE_DE, "false");
830 // store.setDefault(RESOURCE_BUNDLE_FR, "false");
831 // store.setDefault(RESOURCE_BUNDLE_ES, "false");
832 // TemplatePreferencePage.initDefaults(store);
833 //this will initialize the static fields in the syntaxrdr class
835 JavaCore.initializeDefaultPluginPreferences();
836 PreferenceConstants.initializeDefaultValues(store);
837 externalTools.initializeDefaultPreferences(store);
838 MarkerAnnotationPreferences.initializeDefaultValues(store);
841 private IWorkbenchPage internalGetActivePage() {
842 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
844 return window.getActivePage();
848 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
849 if (fImageDescriptorRegistry == null)
850 fImageDescriptorRegistry = new ImageDescriptorRegistry();
851 return fImageDescriptorRegistry;
855 * Open a file in the Workbench that may or may not exist in the workspace.
856 * Must be run on the UI thread.
859 * @throws CoreException
861 public ITextEditor openFileInTextEditor(String filename) throws CoreException {
862 // reject directories
863 if (new File(filename).isDirectory())
865 IWorkbench workbench = PlatformUI.getWorkbench();
866 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
867 IWorkbenchPage page = window.getActivePage();
868 IPath path = new Path(filename);
869 // If the file exists in the workspace, open it
870 IFile file = getWorkspace().getRoot().getFileForLocation(path);
872 ITextEditor textEditor;
873 if (file != null && file.exists()) {
874 editor = IDE.openEditor(page, file, true);
875 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
877 // Otherwise open the stream directly
880 FileStorage storage = new FileStorage(path);
881 IEditorRegistry registry = getWorkbench().getEditorRegistry();
882 IEditorDescriptor desc = registry.getDefaultEditor(filename);
884 desc = registry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
885 // desc = registry.getDefaultEditor();
887 IEditorInput input = new ExternalEditorInput(storage);
888 editor = page.openEditor(input, desc.getId());
889 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
890 // If the storage provider is not ours, we can't guarantee read/write.
891 if (textEditor != null) {
892 IDocumentProvider documentProvider = textEditor.getDocumentProvider();
893 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
894 storage.setReadOnly();
902 * Open a file in the Workbench that may or may not exist in the workspace.
903 * Must be run on the UI thread.
907 * @throws CoreException
909 public void openFileAndGotoLine(String filename, int line)
910 throws CoreException {
911 ITextEditor textEditor = openFileInTextEditor(filename);
912 if (textEditor != null) {
913 // If a line number was given, go to it
916 line--; // document is 0 based
917 IDocument document = textEditor.getDocumentProvider().getDocument(
918 textEditor.getEditorInput());
919 textEditor.selectAndReveal(document.getLineOffset(line), document
920 .getLineLength(line));
921 } catch (BadLocationException e) {
922 // invalid text position -> do nothing
929 * Open a file in the Workbench that may or may not exist in the workspace.
930 * Must be run on the UI thread.
934 * @throws CoreException
936 public void openFileAndGotoOffset(String filename, int offset, int length)
937 throws CoreException {
938 ITextEditor textEditor = openFileInTextEditor(filename);
939 if (textEditor != null) {
940 // If a line number was given, go to it
942 IDocument document = textEditor.getDocumentProvider().getDocument(
943 textEditor.getEditorInput());
944 textEditor.selectAndReveal(offset, length);
949 public void openFileAndFindString(String filename, String findString)
950 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(
957 textEditor.getEditorInput());
958 int offset = document.search(0, findString, true, false, true);
959 textEditor.selectAndReveal(offset, findString.length());
960 } catch (BadLocationException e) {
961 // invalid text position -> do nothing
967 public void setLastEditorFile(IFile textEditor) {
968 this.fLastEditorFile = textEditor;
972 * @see org.eclipse.core.runtime.Plugin#stop
974 public void stop(BundleContext context) throws Exception {
976 // JavaCore.stop(this, context);
977 plugin.savePluginPreferences();
978 IWorkspace workspace = ResourcesPlugin.getWorkspace();
979 workspace.removeResourceChangeListener(JavaModelManager
980 .getJavaModelManager().deltaState);
981 workspace.removeSaveParticipant(plugin);
983 JavaModelManager.getJavaModelManager().shutdown();
985 ColorManager.getDefault().dispose();
986 // save the information from the php index files if necessary
987 Collection collection = fIndexManagerMap.values();
988 Iterator iterator = collection.iterator();
989 IdentifierIndexManager indexManager = null;
990 while (iterator.hasNext()) {
991 indexManager = (IdentifierIndexManager) iterator.next();
992 indexManager.writeFile();
994 if (fImageDescriptorRegistry != null)
995 fImageDescriptorRegistry.dispose();
997 // AllTypesCache.terminate();
999 if (fImageDescriptorRegistry != null)
1000 fImageDescriptorRegistry.dispose();
1002 unregisterAdapters();
1004 // if (fASTProvider != null) {
1005 // fASTProvider.dispose();
1006 // fASTProvider= null;
1009 if (fWorkingCopyManager != null) {
1010 fWorkingCopyManager.shutdown();
1011 fWorkingCopyManager = null;
1014 if (fCompilationUnitDocumentProvider != null) {
1015 fCompilationUnitDocumentProvider.shutdown();
1016 fCompilationUnitDocumentProvider = null;
1019 if (fJavaTextTools != null) {
1020 fJavaTextTools.dispose();
1021 fJavaTextTools = null;
1023 // JavaDocLocations.shutdownJavadocLocations();
1025 uninstallPreferenceStoreBackwardsCompatibility();
1027 // RefactoringCore.getUndoManager().shutdown();
1029 super.stop(context);
1034 * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
1036 // public void shutdown() throws CoreException {
1037 // // moved down (see below):
1038 // // super.shutdown();
1039 // // externalTools.shutDown();
1040 // ColorManager.getDefault().dispose();
1041 // // save the information from the php index files if necessary
1042 // Collection collection = fIndexManagerMap.values();
1043 // Iterator iterator = collection.iterator();
1044 // IdentifierIndexManager indexManager = null;
1045 // while (iterator.hasNext()) {
1046 // indexManager = (IdentifierIndexManager) iterator.next();
1047 // indexManager.writeFile();
1049 // if (fImageDescriptorRegistry != null)
1050 // fImageDescriptorRegistry.dispose();
1051 // // unregisterAdapters();
1052 // super.shutdown();
1053 // if (fWorkingCopyManager != null) {
1054 // fWorkingCopyManager.shutdown();
1055 // fWorkingCopyManager = null;
1057 // if (fCompilationUnitDocumentProvider != null) {
1058 // fCompilationUnitDocumentProvider.shutdown();
1059 // fCompilationUnitDocumentProvider = null;
1061 // if (fJavaTextTools != null) {
1062 // fJavaTextTools.dispose();
1063 // fJavaTextTools = null;
1065 // // JavaDocLocations.shutdownJavadocLocations();
1068 // JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
1069 // // begin JavaCore#shutdown()
1070 // //savePluginPreferences();
1071 // savePluginPreferences();
1072 // IWorkspace workspace = ResourcesPlugin.getWorkspace();
1073 // workspace.removeResourceChangeListener(JavaModelManager.getJavaModelManager().deltaState);
1074 // workspace.removeSaveParticipant(this);
1075 // ((JavaModelManager) JavaModelManager.getJavaModelManager()).shutdown();
1076 // // end JavaCore#shutdown()
1079 * Installs backwards compatibility for the preference store.
1081 private void installPreferenceStoreBackwardsCompatibility() {
1084 * Installs backwards compatibility: propagate the Java editor font from a
1085 * pre-2.1 plug-in to the Platform UI's preference store to preserve the
1086 * Java editor font from a pre-2.1 workspace. This is done only once.
1088 String fontPropagatedKey = "fontPropagated"; //$NON-NLS-1$
1089 if (getPreferenceStore().contains(JFaceResources.TEXT_FONT)
1090 && !getPreferenceStore().isDefault(JFaceResources.TEXT_FONT)) {
1091 if (!getPreferenceStore().getBoolean(fontPropagatedKey))
1092 PreferenceConverter.setValue(PlatformUI.getWorkbench()
1093 .getPreferenceStore(), PreferenceConstants.EDITOR_TEXT_FONT,
1094 PreferenceConverter.getFontDataArray(getPreferenceStore(),
1095 JFaceResources.TEXT_FONT));
1097 getPreferenceStore().setValue(fontPropagatedKey, true);
1100 * Backwards compatibility: set the Java editor font in this plug-in's
1101 * preference store to let older versions access it. Since 2.1 the Java
1102 * editor font is managed by the workbench font preference page.
1104 PreferenceConverter.putValue(getPreferenceStore(),
1105 JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry().getFontData(
1106 PreferenceConstants.EDITOR_TEXT_FONT));
1108 fFontPropertyChangeListener = new IPropertyChangeListener() {
1109 public void propertyChange(PropertyChangeEvent event) {
1110 if (PreferenceConstants.EDITOR_TEXT_FONT.equals(event.getProperty()))
1111 PreferenceConverter.putValue(getPreferenceStore(),
1112 JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry()
1113 .getFontData(PreferenceConstants.EDITOR_TEXT_FONT));
1116 JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
1119 * Backwards compatibility: propagate the Java editor tab width from a
1120 * pre-3.0 plug-in to the new preference key. This is done only once.
1122 final String oldTabWidthKey = PreferenceConstants.EDITOR_TAB_WIDTH;
1123 final String newTabWidthKey = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH;
1124 String tabWidthPropagatedKey = "tabWidthPropagated"; //$NON-NLS-1$
1125 if (getPreferenceStore().contains(oldTabWidthKey)
1126 && !getPreferenceStore().isDefault(oldTabWidthKey)) {
1127 if (!getPreferenceStore().getBoolean(tabWidthPropagatedKey))
1128 getPreferenceStore().setValue(newTabWidthKey,
1129 getPreferenceStore().getInt(oldTabWidthKey));
1131 getPreferenceStore().setValue(tabWidthPropagatedKey, true);
1134 * Backwards compatibility: set the Java editor tab width in this plug-in's
1135 * preference store with the old key to let older versions access it. Since
1136 * 3.0 the tab width is managed by the extended texteditor and uses a new
1139 getPreferenceStore().putValue(oldTabWidthKey,
1140 getPreferenceStore().getString(newTabWidthKey));
1142 fPropertyChangeListener = new IPropertyChangeListener() {
1143 public void propertyChange(PropertyChangeEvent event) {
1144 if (newTabWidthKey.equals(event.getProperty()))
1145 getPreferenceStore().putValue(oldTabWidthKey,
1146 getPreferenceStore().getString(newTabWidthKey));
1149 getPreferenceStore().addPropertyChangeListener(fPropertyChangeListener);
1152 * Backward compatibility for the refactoring preference key.
1154 // getPreferenceStore().setValue(
1155 // PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD,
1156 // RefactoringCore.getConditionCheckingFailedSeverity());
1160 * Uninstalls backwards compatibility for the preference store.
1162 private void uninstallPreferenceStoreBackwardsCompatibility() {
1163 JFaceResources.getFontRegistry()
1164 .removeListener(fFontPropertyChangeListener);
1165 getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
1169 * (non - Javadoc) Method declared in Plugin
1171 public void start(BundleContext context) throws Exception {
1172 super.start(context);
1174 // JavaCore.start(this, context);
1175 final JavaModelManager manager = JavaModelManager.getJavaModelManager();
1177 manager.configurePluginDebugOptions();
1179 // request state folder creation (workaround 19885)
1180 // JavaCore.getPlugin().getStateLocation();
1182 // retrieve variable values
1183 //JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new
1184 // JavaModelManager.PluginPreferencesListener());
1185 // manager.loadVariablesAndContainers();
1187 final IWorkspace workspace = ResourcesPlugin.getWorkspace();
1188 workspace.addResourceChangeListener(
1190 IResourceChangeEvent.PRE_BUILD
1191 | IResourceChangeEvent.POST_BUILD
1192 | IResourceChangeEvent.POST_CHANGE
1193 | IResourceChangeEvent.PRE_DELETE
1194 | IResourceChangeEvent.PRE_CLOSE);
1197 ISavedState savedState = workspace.addSaveParticipant(PHPeclipsePlugin.this, manager);
1199 // process deltas since last activated in indexer thread so that indexes are up-to-date.
1200 // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658
1201 // Job processSavedState = new Job(Util.bind("savedState.jobName")) { //$NON-NLS-1$
1202 // protected IStatus run(IProgressMonitor monitor) {
1204 // // add save participant and process delta atomically
1205 // // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59937
1207 // new IWorkspaceRunnable() {
1208 // public void run(IProgressMonitor progress) throws CoreException {
1209 // ISavedState savedState = workspace.addSaveParticipant(PHPeclipsePlugin.this, manager);
1210 // if (savedState != null) {
1211 // // the event type coming from the saved state is always POST_AUTO_BUILD
1212 // // force it to be POST_CHANGE so that the delta processor can handle it
1213 // manager.deltaState.getDeltaProcessor().overridenEventType = IResourceChangeEvent.POST_CHANGE;
1214 // savedState.processResourceChangeEvents(manager.deltaState);
1219 // } catch (CoreException e) {
1220 // return e.getStatus();
1222 // return Status.OK_STATUS;
1225 // processSavedState.setSystem(true);
1226 // processSavedState.setPriority(Job.SHORT); // process asap
1227 // processSavedState.schedule();
1228 } catch (RuntimeException e) {
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();
1251 // registerAdapters();
1253 // // externalTools.startUp();
1254 // getStandardDisplay().asyncExec(new Runnable() {
1255 // public void run() {
1256 // //initialize the variable context manager
1257 // VariableContextManager.getDefault();
1261 // // if (USE_WORKING_COPY_OWNERS) {
1262 // WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
1263 // public IBuffer createBuffer(ICompilationUnit workingCopy) {
1264 // ICompilationUnit original = workingCopy.getPrimary();
1265 // IResource resource = original.getResource();
1266 // if (resource instanceof IFile)
1267 // return new DocumentAdapter(workingCopy, (IFile) resource);
1268 // return DocumentAdapter.NULL;
1273 // installPreferenceStoreBackwardsCompatibility();
1275 // AllTypesCache.initialize();
1277 // Initialize AST provider
1278 // getASTProvider();
1281 // public void startup() throws CoreException {
1283 // // begin JavaCore.startup();
1284 // JavaModelManager manager = JavaModelManager.getJavaModelManager();
1286 // manager.configurePluginDebugOptions();
1287 // // request state folder creation (workaround 19885)
1288 // // JavaCore.getPlugin().getStateLocation();
1289 // getStateLocation();
1290 // // retrieve variable values
1292 // JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new
1293 // // JavaModelManager.PluginPreferencesListener());
1294 // getPluginPreferences().addPropertyChangeListener(
1295 // new JavaModelManager.PluginPreferencesListener());
1296 // // TODO khartlage temp-del
1297 // // manager.loadVariablesAndContainers();
1298 // final IWorkspace workspace = ResourcesPlugin.getWorkspace();
1299 // workspace.addResourceChangeListener(
1300 // manager.deltaState,
1301 // IResourceChangeEvent.PRE_BUILD
1302 // | IResourceChangeEvent.POST_BUILD
1303 // | IResourceChangeEvent.POST_CHANGE
1304 // | IResourceChangeEvent.PRE_DELETE
1305 // | IResourceChangeEvent.PRE_CLOSE);
1306 // // startIndexing();
1307 // workspace.addSaveParticipant(PHPeclipsePlugin.getDefault(), manager);
1308 // } catch (CoreException e) {
1309 // } catch (RuntimeException e) {
1310 // manager.shutdown();
1313 // // end JavaCore.startup();
1314 // IAdapterManager platformManager = Platform.getAdapterManager();
1315 // platformManager.registerAdapters(new PHPElementAdapterFactory(),
1316 // PHPElement.class);
1317 // platformManager.registerAdapters(new ResourceAdapterFactory(),
1318 // IResource.class);
1319 // // externalTools.startUp();
1320 // getStandardDisplay().asyncExec(new Runnable() {
1321 // public void run() {
1322 // //initialize the variable context manager
1323 // VariableContextManager.getDefault();
1328 private void registerAdapters() {
1329 fJavaElementAdapterFactory = new JavaElementAdapterFactory();
1330 // fMarkerAdapterFactory= new MarkerAdapterFactory();
1331 // fEditorInputAdapterFactory= new EditorInputAdapterFactory();
1332 fResourceAdapterFactory = new ResourceAdapterFactory();
1333 // fLogicalPackageAdapterFactory= new LogicalPackageAdapterFactory();
1335 IAdapterManager manager = Platform.getAdapterManager();
1336 manager.registerAdapters(fJavaElementAdapterFactory, IJavaElement.class);
1337 // manager.registerAdapters(fMarkerAdapterFactory, IMarker.class);
1338 // manager.registerAdapters(fEditorInputAdapterFactory, IEditorInput.class);
1339 manager.registerAdapters(fResourceAdapterFactory, IResource.class);
1340 // manager.registerAdapters(fLogicalPackageAdapterFactory,
1341 // LogicalPackage.class);
1344 private void unregisterAdapters() {
1345 IAdapterManager manager = Platform.getAdapterManager();
1346 manager.unregisterAdapters(fJavaElementAdapterFactory);
1347 // manager.unregisterAdapters(fMarkerAdapterFactory);
1348 // manager.unregisterAdapters(fEditorInputAdapterFactory);
1349 manager.unregisterAdapters(fResourceAdapterFactory);
1350 // manager.unregisterAdapters(fLogicalPackageAdapterFactory);
1354 * Returns a combined preference store, this store is read-only.
1356 * @return the combined preference store
1360 public IPreferenceStore getCombinedPreferenceStore() {
1361 if (fCombinedPreferenceStore == null) {
1362 IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
1363 fCombinedPreferenceStore = new ChainedPreferenceStore(
1364 new IPreferenceStore[] {
1365 getPreferenceStore(),
1366 new PreferencesAdapter(PHPeclipsePlugin.getDefault()
1367 .getPluginPreferences()), generalTextStore });
1369 return fCombinedPreferenceStore;
1372 public synchronized IBufferFactory getBufferFactory() {
1373 if (fBufferFactory == null)
1374 fBufferFactory = new CustomBufferFactory();
1375 return fBufferFactory;
1379 * Returns the registry of the extensions to the
1380 * <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code> extension
1383 * @return the registry of contributed
1384 * <code>IJavaFoldingStructureProvider</code>
1387 public synchronized JavaFoldingStructureProviderRegistry getFoldingStructureProviderRegistry() {
1388 if (fFoldingStructureProviderRegistry == null)
1389 fFoldingStructureProviderRegistry = new JavaFoldingStructureProviderRegistry();
1390 return fFoldingStructureProviderRegistry;
1394 * Runs the given action as an atomic Java model operation.
1396 * After running a method that modifies java elements, registered listeners
1397 * receive after-the-fact notification of what just transpired, in the form of
1398 * a element changed event. This method allows clients to call a number of
1399 * methods that modify java elements and only have element changed event
1400 * notifications reported at the end of the entire batch.
1403 * If this method is called outside the dynamic scope of another such call,
1404 * this method runs the action and then reports a single element changed event
1405 * describing the net effect of all changes done to java elements by the
1409 * If this method is called in the dynamic scope of another such call, this
1410 * method simply runs the action.
1414 * the action to perform
1416 * a progress monitor, or <code>null</code> if progress reporting
1417 * and cancellation are not desired
1418 * @exception CoreException
1419 * if the operation failed.
1422 public static void run(IWorkspaceRunnable action, IProgressMonitor monitor)
1423 throws CoreException {
1424 run(action, ResourcesPlugin.getWorkspace().getRoot(), monitor);
1428 * Runs the given action as an atomic Java model operation.
1430 * After running a method that modifies java elements, registered listeners
1431 * receive after-the-fact notification of what just transpired, in the form of
1432 * a element changed event. This method allows clients to call a number of
1433 * methods that modify java elements and only have element changed event
1434 * notifications reported at the end of the entire batch.
1437 * If this method is called outside the dynamic scope of another such call,
1438 * this method runs the action and then reports a single element changed event
1439 * describing the net effect of all changes done to java elements by the
1443 * If this method is called in the dynamic scope of another such call, this
1444 * method simply runs the action.
1447 * The supplied scheduling rule is used to determine whether this operation
1448 * can be run simultaneously with workspace changes in other threads. See
1449 * <code>IWorkspace.run(...)</code> for more details.
1453 * the action to perform
1455 * the scheduling rule to use when running this operation, or
1456 * <code>null</code> if there are no scheduling restrictions for
1459 * a progress monitor, or <code>null</code> if progress reporting
1460 * and cancellation are not desired
1461 * @exception CoreException
1462 * if the operation failed.
1465 public static void run(IWorkspaceRunnable action, ISchedulingRule rule,
1466 IProgressMonitor monitor) throws CoreException {
1467 IWorkspace workspace = ResourcesPlugin.getWorkspace();
1468 if (workspace.isTreeLocked()) {
1469 new BatchOperation(action).run(monitor);
1471 // use IWorkspace.run(...) to ensure that a build will be done in
1473 workspace.run(new BatchOperation(action), rule, IWorkspace.AVOID_UPDATE,
1479 * Returns the template context type registry for the java plugin.
1481 * @return the template context type registry for the java plugin
1484 public ContextTypeRegistry getTemplateContextRegistry() {
1485 if (fContextTypeRegistry == null) {
1486 fContextTypeRegistry= new ContributionContextTypeRegistry();
1488 fContextTypeRegistry.addContextType(new JavaContextType());
1489 fContextTypeRegistry.addContextType(new JavaDocContextType());
1490 fContextTypeRegistry.addContextType(new HTMLContextType());
1493 return fContextTypeRegistry;
1497 * Returns the template store for the java editor templates.
1499 * @return the template store for the java editor templates
1502 public TemplateStore getTemplateStore() {
1503 if (fTemplateStore == null) {
1504 // boolean alreadyMigrated= getPreferenceStore().getBoolean(TEMPLATES_MIGRATION_KEY);
1505 // if (alreadyMigrated)
1506 fTemplateStore= new ContributionTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), TEMPLATES_KEY);
1508 // fTemplateStore= new CompatibilityTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), TEMPLATES_KEY, Templates.getInstance());
1509 // getPreferenceStore().setValue(TEMPLATES_MIGRATION_KEY, true);
1513 fTemplateStore.load();
1514 } catch (IOException e) {
1519 return fTemplateStore;
1523 * Returns the template context type registry for the code generation
1526 * @return the template context type registry for the code generation
1530 public ContextTypeRegistry getCodeTemplateContextRegistry() {
1531 if (fCodeTemplateContextTypeRegistry == null) {
1532 fCodeTemplateContextTypeRegistry= new ContributionContextTypeRegistry();
1534 CodeTemplateContextType.registerContextTypes(fCodeTemplateContextTypeRegistry);
1537 return fCodeTemplateContextTypeRegistry;
1541 * Returns the template store for the code generation templates.
1543 * @return the template store for the code generation templates
1546 public TemplateStore getCodeTemplateStore() {
1547 if (fCodeTemplateStore == null) {
1548 // boolean alreadyMigrated= getPreferenceStore().getBoolean(CODE_TEMPLATES_MIGRATION_KEY);
1549 // if (alreadyMigrated)
1550 fCodeTemplateStore= new ContributionTemplateStore(getCodeTemplateContextRegistry(), getPreferenceStore(), CODE_TEMPLATES_KEY);
1552 // fCodeTemplateStore= new CompatibilityTemplateStore(getCodeTemplateContextRegistry(), getPreferenceStore(), CODE_TEMPLATES_KEY, CodeTemplates.getInstance());
1553 // getPreferenceStore().setValue(CODE_TEMPLATES_MIGRATION_KEY, true);
1557 fCodeTemplateStore.load();
1558 } catch (IOException e) {
1562 // compatibility / bug fixing code for duplicated templates
1563 // TODO remove for 3.0
1564 // CompatibilityTemplateStore.pruneDuplicates(fCodeTemplateStore, true);
1567 return fCodeTemplateStore;