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;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.HashMap;
17 import java.util.HashSet;
18 import java.util.Iterator;
19 import java.util.List;
22 import net.sourceforge.phpdt.core.IBuffer;
23 import net.sourceforge.phpdt.core.IBufferFactory;
24 import net.sourceforge.phpdt.core.ICompilationUnit;
25 import net.sourceforge.phpdt.core.IJavaElement;
26 import net.sourceforge.phpdt.core.JavaCore;
27 import net.sourceforge.phpdt.core.WorkingCopyOwner;
28 import net.sourceforge.phpdt.externaltools.internal.model.ColorManager;
29 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsPlugin;
30 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
31 import net.sourceforge.phpdt.internal.ui.JavaElementAdapterFactory;
32 import net.sourceforge.phpdt.internal.ui.ResourceAdapterFactory;
33 import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache;
34 import net.sourceforge.phpdt.internal.ui.preferences.TemplatePreferencePage;
35 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
36 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
37 import net.sourceforge.phpdt.internal.ui.viewsupport.ProblemMarkerManager;
38 import net.sourceforge.phpdt.ui.IContextMenuConstants;
39 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
40 import net.sourceforge.phpdt.ui.PreferenceConstants;
41 import net.sourceforge.phpdt.ui.text.JavaTextTools;
42 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
43 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
44 import net.sourceforge.phpeclipse.builder.FileStorage;
45 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
46 import net.sourceforge.phpeclipse.phpeditor.CustomBufferFactory;
47 import net.sourceforge.phpeclipse.phpeditor.DocumentAdapter;
48 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
49 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
50 import net.sourceforge.phpeclipse.phpeditor.WorkingCopyManager;
51 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
53 import org.eclipse.core.boot.BootLoader;
54 import org.eclipse.core.resources.IFile;
55 import org.eclipse.core.resources.IProject;
56 import org.eclipse.core.resources.IResource;
57 import org.eclipse.core.resources.IWorkspace;
58 import org.eclipse.core.resources.ResourcesPlugin;
59 import org.eclipse.core.runtime.CoreException;
60 import org.eclipse.core.runtime.IAdapterManager;
61 import org.eclipse.core.runtime.IPath;
62 import org.eclipse.core.runtime.IPluginDescriptor;
63 import org.eclipse.core.runtime.IStatus;
64 import org.eclipse.core.runtime.Path;
65 import org.eclipse.core.runtime.Platform;
66 import org.eclipse.core.runtime.Status;
67 import net.sourceforge.phpdt.internal.ui.text.folding.JavaFoldingStructureProviderRegistry;
69 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
70 import org.eclipse.jface.action.GroupMarker;
71 import org.eclipse.jface.action.IMenuManager;
72 import org.eclipse.jface.action.Separator;
73 import org.eclipse.jface.preference.IPreferenceStore;
74 import org.eclipse.jface.preference.PreferenceConverter;
75 import org.eclipse.jface.resource.JFaceResources;
76 import org.eclipse.jface.text.BadLocationException;
77 import org.eclipse.jface.text.IDocument;
78 import org.eclipse.jface.util.IPropertyChangeListener;
79 import org.eclipse.jface.util.PropertyChangeEvent;
80 import org.eclipse.swt.graphics.RGB;
81 import org.eclipse.swt.widgets.Display;
82 import org.eclipse.swt.widgets.Shell;
83 import org.eclipse.ui.IEditorDescriptor;
84 import org.eclipse.ui.IEditorInput;
85 import org.eclipse.ui.IEditorPart;
86 import org.eclipse.ui.IEditorRegistry;
87 import org.eclipse.ui.IWorkbench;
88 import org.eclipse.ui.IWorkbenchPage;
89 import org.eclipse.ui.IWorkbenchWindow;
90 import org.eclipse.ui.PlatformUI;
91 import org.eclipse.ui.editors.text.EditorsUI;
92 import org.eclipse.ui.ide.IDE;
93 import org.eclipse.ui.plugin.AbstractUIPlugin;
94 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
95 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
96 import org.eclipse.ui.texteditor.IDocumentProvider;
97 import org.eclipse.ui.texteditor.ITextEditor;
98 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
99 import org.osgi.framework.BundleContext;
101 * The main plugin class to be used in the desktop.
103 public class PHPeclipsePlugin extends AbstractUIPlugin
105 IPreferenceConstants {
107 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
109 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
111 * id of builder - matches plugin.xml (concatenate pluginid.builderid)
113 public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
114 //public static final String BUILDER_INDEX_ID = PLUGIN_ID + ".indexbuilder";
115 /** General debug flag */
116 public static final boolean DEBUG = false;
118 * The maximum number of allowed proposals by category
120 public final static int MAX_PROPOSALS = 200;
121 private static ExternalToolsPlugin externalTools;
123 * The Java virtual machine that we are running on.
125 private static int jvm;
127 private static final int MRJ_2_0 = 0;
128 /** MRJ 2.1 or later */
129 private static final int MRJ_2_1 = 1;
130 /** Java on Mac OS X 10.0 (MRJ 3.0) */
131 private static final int MRJ_3_0 = 3;
133 private static final int MRJ_3_1 = 4;
134 /** JVM constant for any other platform */
135 private static final int OTHER = -1;
136 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID +
137 // ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
138 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID
139 + ".ui.CodingActionSet"; //$NON-NLS-1$
140 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
141 public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
142 public static final String PHPPARSER_NEW = "test.PHPParser";
143 /** Change this if you want to switch PHP Parser. */
144 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
145 //The shared instance.
146 private static PHPeclipsePlugin plugin;
148 private static final int WINDOWS_9x = 6;
150 private static final int WINDOWS_NT = 5;
151 private ImageDescriptorRegistry fImageDescriptorRegistry;
152 private HashMap fIndexManagerMap = new HashMap();
153 private IWorkingCopyManager fWorkingCopyManager;
154 private IBufferFactory fBufferFactory;
155 private PHPDocumentProvider fCompilationUnitDocumentProvider;
156 private JavaTextTools fJavaTextTools;
157 private ProblemMarkerManager fProblemMarkerManager;
158 private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
159 private IFile fLastEditorFile = null;
160 private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
162 private JavaElementAdapterFactory fJavaElementAdapterFactory;
163 // private MarkerAdapterFactory fMarkerAdapterFactory;
164 // private EditorInputAdapterFactory fEditorInputAdapterFactory;
165 private ResourceAdapterFactory fResourceAdapterFactory;
166 // private LogicalPackageAdapterFactory fLogicalPackageAdapterFactory;
167 private IPropertyChangeListener fFontPropertyChangeListener;
169 * Property change listener on this plugin's preference store.
173 private IPropertyChangeListener fPropertyChangeListener;
176 * The combined preference store.
179 private IPreferenceStore fCombinedPreferenceStore;
181 * The extension point registry for the <code>org.eclipse.jdt.ui.javaFoldingStructureProvider</code>
186 private JavaFoldingStructureProviderRegistry fFoldingStructureProviderRegistry;
190 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
194 externalTools = new ExternalToolsPlugin();
197 // ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
198 // } catch (MissingResourceException x) {
199 // resourceBundle = null;
203 * Returns all Java editor text hovers contributed to the workbench.
205 * @return an array of JavaEditorTextHoverDescriptor
208 public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
209 if (fJavaEditorTextHoverDescriptors == null)
210 fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
211 .getContributedHovers();
212 return fJavaEditorTextHoverDescriptors;
215 * Resets the Java editor text hovers contributed to the workbench.
217 * This will force a rebuild of the descriptors the next time a client asks
221 * @return an array of JavaEditorTextHoverDescriptor
224 public void resetJavaEditorTextHoverDescriptors() {
225 fJavaEditorTextHoverDescriptors = null;
228 * Creates the PHP plugin standard groups in a context menu.
230 public static void createStandardGroups(IMenuManager menu) {
233 menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
234 menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
235 menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
236 menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
237 menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
238 menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
239 menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
240 menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
241 menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
242 menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
243 menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
245 public static IWorkbenchPage getActivePage() {
246 return getDefault().internalGetActivePage();
248 public static Shell getActiveWorkbenchShell() {
249 return getActiveWorkbenchWindow().getShell();
252 * Returns an array of all editors that have an unsaved content. If the
253 * identical content is presented in more than one editor, only one of those
254 * editor parts is part of the result.
256 * @return an array of all dirty editor parts.
258 public static IEditorPart[] getDirtyEditors() {
259 Set inputs = new HashSet();
260 List result = new ArrayList(0);
261 IWorkbench workbench = getDefault().getWorkbench();
262 IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
263 for (int i = 0; i < windows.length; i++) {
264 IWorkbenchPage[] pages = windows[i].getPages();
265 for (int x = 0; x < pages.length; x++) {
266 IEditorPart[] editors = pages[x].getDirtyEditors();
267 for (int z = 0; z < editors.length; z++) {
268 IEditorPart ep = editors[z];
269 IEditorInput input = ep.getEditorInput();
270 if (!inputs.contains(input)) {
277 return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]);
279 public static IWorkbenchWindow getActiveWorkbenchWindow() {
280 return getDefault().getWorkbench().getActiveWorkbenchWindow();
283 * Returns the shared instance.
285 public static PHPeclipsePlugin getDefault() {
288 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
289 return getDefault().internalGetImageDescriptorRegistry();
291 static IPath getInstallLocation() {
292 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
294 public static int getJVM() {
297 public static String getPluginId() {
298 return getDefault().getDescriptor().getUniqueIdentifier();
301 * Returns the standard display to be used. The method first checks, if the
302 * thread calling this method has an associated display. If so, this display
303 * is returned. Otherwise the method returns the default display.
305 public static Display getStandardDisplay() {
306 Display display = Display.getCurrent();
307 if (display == null) {
308 display = Display.getDefault();
312 // public static ExternalToolsPlugin getExternalTools() {
313 // return externalTools;
316 * Returns the workspace instance.
318 public static IWorkspace getWorkspace() {
319 return ResourcesPlugin.getWorkspace();
321 public static boolean isDebug() {
322 return getDefault().isDebugging();
324 // public static void logErrorMessage(String message) {
325 // log(new Status(IStatus.ERROR, getPluginId(),
326 // JavaStatusConstants.INTERNAL_ERROR, message, null));
329 // public static void logErrorStatus(String message, IStatus status) {
330 // if (status == null) {
331 // logErrorMessage(message);
334 // MultiStatus multi= new MultiStatus(getPluginId(),
335 // JavaStatusConstants.INTERNAL_ERROR, message, null);
336 // multi.add(status);
340 // public static void log(Throwable e) {
341 // log(new Status(IStatus.ERROR, getPluginId(),
342 // JavaStatusConstants.INTERNAL_ERROR,
343 // JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
345 public static void log(int severity, String message) {
346 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
349 public static void log(IStatus status) {
350 getDefault().getLog().log(status);
352 public static void log(Throwable e) {
353 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
354 "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
356 private static void setJVM() {
357 String osName = System.getProperty("os.name");
358 if (osName.startsWith("Mac OS")) {
359 String mrjVersion = System.getProperty("mrj.version");
360 String majorMRJVersion = mrjVersion.substring(0, 3);
363 double version = Double.valueOf(majorMRJVersion).doubleValue();
366 } else if (version >= 2.1 && version < 3) {
368 } else if (version == 3.0) {
370 } else if (version >= 3.1) {
373 } catch (NumberFormatException nfe) {
375 } else if (osName.startsWith("Windows")) {
376 if (osName.indexOf("9") != -1) {
383 // TODO: refactor this into a better method name !
384 public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
385 if (fCompilationUnitDocumentProvider == null)
386 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
387 return fCompilationUnitDocumentProvider;
391 * Get the identifier index manager for the given project
394 * the current project
397 public IdentifierIndexManager getIndexManager(IProject iProject) {
398 String indexFilename = iProject.getLocation() + File.separator
400 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap
402 if (indexManager == null) {
403 indexManager = new IdentifierIndexManager(indexFilename);
404 fIndexManagerMap.put(indexFilename, indexManager);
408 public synchronized IWorkingCopyManager getWorkingCopyManager() {
409 if (fWorkingCopyManager == null) {
410 PHPDocumentProvider provider = getCompilationUnitDocumentProvider();
411 fWorkingCopyManager = new WorkingCopyManager(provider);
413 return fWorkingCopyManager;
415 public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
416 if (fMembersOrderPreferenceCache == null)
417 fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
418 return fMembersOrderPreferenceCache;
420 public synchronized ProblemMarkerManager getProblemMarkerManager() {
421 if (fProblemMarkerManager == null)
422 fProblemMarkerManager = new ProblemMarkerManager();
423 return fProblemMarkerManager;
426 public synchronized JavaTextTools getJavaTextTools() {
427 if (fJavaTextTools == null)
428 fJavaTextTools = new JavaTextTools(getPreferenceStore());
429 return fJavaTextTools;
431 public IFile getLastEditorFile() {
432 return fLastEditorFile;
435 * Returns the string from the plugin's resource bundle, or 'key' if not
438 // public static String getResourceString(String key) {
439 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
441 // return bundle.getString(key);
442 // } catch (MissingResourceException e) {
447 * Returns the plugin's resource bundle,
449 // public ResourceBundle getResourceBundle() {
450 // return resourceBundle;
452 protected void initializeDefaultPreferences(IPreferenceStore store) {
453 // windows preferences:
454 store.setDefault(LOCALHOST_PREF, "http://localhost");
455 // store.setDefault(SHOW_EXTERNAL_PREVIEW_PREF, "true");
456 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
457 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
458 store.setDefault(PHP_OBFUSCATOR_DEFAULT, "c:\\temp");
459 store.setDefault(PHP_BOOKMARK_DEFAULT, "");
461 store.setDefault(PHP_AUTO_PREVIEW_DEFAULT, "true");
462 store.setDefault(PHP_BRING_TO_TOP_PREVIEW_DEFAULT, "true");
464 String windowsSystem = BootLoader.getWS();
465 if (jvm == WINDOWS_9x) {
466 store.setDefault(EXTERNAL_BROWSER_PREF,
467 "command.com /c start iexplore {0}");
468 } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
469 store.setDefault(EXTERNAL_BROWSER_PREF,
470 "rundll32 url.dll,FileProtocolHandler {0}");
471 } else if (windowsSystem.equals(BootLoader.WS_CARBON)) {
472 // TODO How do we start Safari on Mac OS X ?
473 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
475 store.setDefault(PHP_OBFUSCATOR_DEFAULT, "/tmp");
476 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
478 store.setDefault(DOCUMENTROOT_PREF, getWorkspace().getRoot().getLocation()
480 // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
482 if (windowsSystem.equals(BootLoader.WS_WIN32)) {
483 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
484 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
485 store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
486 store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
488 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
489 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
490 store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
491 store.setDefault(APACHE_RUN_PREF, "/apache/apache");
493 store.setDefault(MYSQL_PREF, "--standalone");
494 store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
495 store.setDefault(APACHE_STOP_PREF, "-k shutdown");
496 store.setDefault(APACHE_RESTART_PREF, "-k restart");
497 store.setDefault(MYSQL_START_BACKGROUND, "true");
498 store.setDefault(APACHE_START_BACKGROUND, "true");
499 store.setDefault(APACHE_STOP_BACKGROUND, "true");
500 store.setDefault(APACHE_RESTART_BACKGROUND, "true");
501 store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
502 store.setDefault(PHP_INTERNAL_PARSER, "false");
503 store.setDefault(PHP_EXTERNAL_PARSER, "true");
504 // store.setDefault(PHP_PARSE_ON_SAVE, "true");
505 // show line numbers:
506 // store.setDefault(LINE_NUMBER_RULER, "false");
507 // store.setDefault(FORMATTER_TAB_SIZE, "4");
508 // php syntax highlighting
509 store.setDefault(PHP_USERDEF_XMLFILE, "");
510 //assume there is none chooA
511 PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT,
512 PHPColorProvider.MULTI_LINE_COMMENT);
513 PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT,
514 PHPColorProvider.SINGLE_LINE_COMMENT);
515 PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
517 .setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
518 PreferenceConverter.setDefault(store, PHP_VARIABLE,
519 PHPColorProvider.VARIABLE);
520 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME,
521 PHPColorProvider.FUNCTION_NAME);
522 PreferenceConverter.setDefault(store, PHP_CONSTANT,
523 PHPColorProvider.CONSTANT);
524 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
525 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
527 .setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
528 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD,
529 PHPColorProvider.PHPDOC_KEYWORD);
530 PreferenceConverter.setDefault(store, PHPDOC_TAG,
531 PHPColorProvider.PHPDOC_TAG);
532 PreferenceConverter.setDefault(store, PHPDOC_LINK,
533 PHPColorProvider.PHPDOC_LINK);
534 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT,
535 PHPColorProvider.PHPDOC_DEFAULT);
537 PreferenceConverter.setDefault(store, EDITOR_PHP_KEYWORD_RETURN_COLOR, new RGB(127, 0, 85));
538 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_BOLD, true);
539 store.setDefault(EDITOR_PHP_KEYWORD_RETURN_ITALIC, false);
541 PreferenceConverter.setDefault(store, EDITOR_PHP_OPERATOR_COLOR, new RGB(0, 0, 0));
542 store.setDefault(EDITOR_PHP_OPERATOR_BOLD, false);
543 store.setDefault(EDITOR_PHP_OPERATOR_ITALIC, false);
545 // PreferenceConverter.setDefault(
547 // PHP_EDITOR_BACKGROUND,
548 // PHPColorProvider.BACKGROUND);
549 // PreferenceConverter.setDefault(
551 // LINKED_POSITION_COLOR,
552 // PHPColorProvider.LINKED_POSITION_COLOR);
553 // PreferenceConverter.setDefault(
555 // LINE_NUMBER_COLOR,
556 // PHPColorProvider.LINE_NUMBER_COLOR);
557 // // set default PHPDoc colors:
558 // PreferenceConverter.setDefault(
561 // PHPColorProvider.PHPDOC_KEYWORD);
562 // PreferenceConverter.setDefault(
565 // PHPColorProvider.PHPDOC_LINK);
566 // PreferenceConverter.setDefault(
569 // PHPColorProvider.PHPDOC_DEFAULT);
570 // PreferenceConverter.setDefault(
573 // PHPColorProvider.PHPDOC_TAG);
574 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
575 // PreferenceConverter.setDefault(
577 // PREFERENCE_COLOR_BACKGROUND,
578 // PHPColorProvider.BACKGROUND_COLOR);
580 // store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
581 // store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
582 // store.setDefault(RESOURCE_BUNDLE_DE, "false");
583 // store.setDefault(RESOURCE_BUNDLE_FR, "false");
584 // store.setDefault(RESOURCE_BUNDLE_ES, "false");
585 TemplatePreferencePage.initDefaults(store);
586 //this will initialize the static fields in the syntaxrdr class
588 JavaCore.initializeDefaultPluginPreferences();
589 PreferenceConstants.initializeDefaultValues(store);
590 externalTools.initializeDefaultPreferences(store);
591 MarkerAnnotationPreferences.initializeDefaultValues(store);
593 private IWorkbenchPage internalGetActivePage() {
594 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
596 return window.getActivePage();
599 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
600 if (fImageDescriptorRegistry == null)
601 fImageDescriptorRegistry = new ImageDescriptorRegistry();
602 return fImageDescriptorRegistry;
605 * Open a file in the Workbench that may or may not exist in the workspace.
606 * Must be run on the UI thread.
609 * @throws CoreException
611 public ITextEditor openFileInTextEditor(String filename) throws CoreException {
612 // reject directories
613 if (new File(filename).isDirectory())
615 IWorkbench workbench = PlatformUI.getWorkbench();
616 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
617 IWorkbenchPage page = window.getActivePage();
618 IPath path = new Path(filename);
619 // If the file exists in the workspace, open it
620 IFile file = getWorkspace().getRoot().getFileForLocation(path);
622 ITextEditor textEditor;
623 if (file != null && file.exists()) {
624 editor = IDE.openEditor(page, file, true);
625 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
627 // Otherwise open the stream directly
630 FileStorage storage = new FileStorage(path);
631 IEditorRegistry registry = getWorkbench().getEditorRegistry();
632 IEditorDescriptor desc = registry.getDefaultEditor(filename);
634 desc = registry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
635 // desc = registry.getDefaultEditor();
637 IEditorInput input = new ExternalEditorInput(storage);
638 editor = page.openEditor(input, desc.getId());
639 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
640 // If the storage provider is not ours, we can't guarantee read/write.
641 if (textEditor != null) {
642 IDocumentProvider documentProvider = textEditor.getDocumentProvider();
643 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
644 storage.setReadOnly();
651 * Open a file in the Workbench that may or may not exist in the workspace.
652 * Must be run on the UI thread.
656 * @throws CoreException
658 public void openFileAndGotoLine(String filename, int line)
659 throws CoreException {
660 ITextEditor textEditor = openFileInTextEditor(filename);
661 if (textEditor != null) {
662 // If a line number was given, go to it
665 line--; // document is 0 based
666 IDocument document = textEditor.getDocumentProvider().getDocument(
667 textEditor.getEditorInput());
668 textEditor.selectAndReveal(document.getLineOffset(line), document
669 .getLineLength(line));
670 } catch (BadLocationException e) {
671 // invalid text position -> do nothing
677 * Open a file in the Workbench that may or may not exist in the workspace.
678 * Must be run on the UI thread.
682 * @throws CoreException
684 public void openFileAndGotoOffset(String filename, int offset, int length)
685 throws CoreException {
686 ITextEditor textEditor = openFileInTextEditor(filename);
687 if (textEditor != null) {
688 // If a line number was given, go to it
690 IDocument document = textEditor.getDocumentProvider().getDocument(
691 textEditor.getEditorInput());
692 textEditor.selectAndReveal(offset, length);
696 public void openFileAndFindString(String filename, String findString)
697 throws CoreException {
698 ITextEditor textEditor = openFileInTextEditor(filename);
699 if (textEditor != null) {
700 // If a string was given, go to it
701 if (findString != null) {
703 IDocument document = textEditor.getDocumentProvider().getDocument(
704 textEditor.getEditorInput());
705 int offset = document.search(0, findString, true, false, true);
706 textEditor.selectAndReveal(offset, findString.length());
707 } catch (BadLocationException e) {
708 // invalid text position -> do nothing
713 public void setLastEditorFile(IFile textEditor) {
714 this.fLastEditorFile = textEditor;
717 * @see org.eclipse.core.runtime.Plugin#stop
719 public void stop(BundleContext context) throws Exception {
721 JavaCore.stop(this, context);
723 ColorManager.getDefault().dispose();
724 // save the information from the php index files if necessary
725 Collection collection = fIndexManagerMap.values();
726 Iterator iterator = collection.iterator();
727 IdentifierIndexManager indexManager = null;
728 while (iterator.hasNext()) {
729 indexManager = (IdentifierIndexManager) iterator.next();
730 indexManager.writeFile();
732 if (fImageDescriptorRegistry != null)
733 fImageDescriptorRegistry.dispose();
735 // AllTypesCache.terminate();
737 if (fImageDescriptorRegistry != null)
738 fImageDescriptorRegistry.dispose();
740 unregisterAdapters();
742 // if (fASTProvider != null) {
743 // fASTProvider.dispose();
744 // fASTProvider= null;
747 if (fWorkingCopyManager != null) {
748 fWorkingCopyManager.shutdown();
749 fWorkingCopyManager= null;
752 if (fCompilationUnitDocumentProvider != null) {
753 fCompilationUnitDocumentProvider.shutdown();
754 fCompilationUnitDocumentProvider= null;
757 if (fJavaTextTools != null) {
758 fJavaTextTools.dispose();
759 fJavaTextTools= null;
761 // JavaDocLocations.shutdownJavadocLocations();
763 uninstallPreferenceStoreBackwardsCompatibility();
765 // RefactoringCore.getUndoManager().shutdown();
771 * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
773 // public void shutdown() throws CoreException {
774 // // moved down (see below):
775 // // super.shutdown();
776 // // externalTools.shutDown();
777 // ColorManager.getDefault().dispose();
778 // // save the information from the php index files if necessary
779 // Collection collection = fIndexManagerMap.values();
780 // Iterator iterator = collection.iterator();
781 // IdentifierIndexManager indexManager = null;
782 // while (iterator.hasNext()) {
783 // indexManager = (IdentifierIndexManager) iterator.next();
784 // indexManager.writeFile();
786 // if (fImageDescriptorRegistry != null)
787 // fImageDescriptorRegistry.dispose();
788 // // unregisterAdapters();
790 // if (fWorkingCopyManager != null) {
791 // fWorkingCopyManager.shutdown();
792 // fWorkingCopyManager = null;
794 // if (fCompilationUnitDocumentProvider != null) {
795 // fCompilationUnitDocumentProvider.shutdown();
796 // fCompilationUnitDocumentProvider = null;
798 // if (fJavaTextTools != null) {
799 // fJavaTextTools.dispose();
800 // fJavaTextTools = null;
802 // // JavaDocLocations.shutdownJavadocLocations();
804 // // JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
805 // // begin JavaCore#shutdown()
806 // //savePluginPreferences();
807 // savePluginPreferences();
808 // IWorkspace workspace = ResourcesPlugin.getWorkspace();
809 // workspace.removeResourceChangeListener(JavaModelManager.getJavaModelManager().deltaState);
810 // workspace.removeSaveParticipant(this);
811 // ((JavaModelManager) JavaModelManager.getJavaModelManager()).shutdown();
812 // // end JavaCore#shutdown()
815 * Installs backwards compatibility for the preference store.
817 private void installPreferenceStoreBackwardsCompatibility() {
820 * Installs backwards compatibility: propagate the Java editor font from a
821 * pre-2.1 plug-in to the Platform UI's preference store to preserve
822 * the Java editor font from a pre-2.1 workspace. This is done only
825 String fontPropagatedKey= "fontPropagated"; //$NON-NLS-1$
826 if (getPreferenceStore().contains(JFaceResources.TEXT_FONT) && !getPreferenceStore().isDefault(JFaceResources.TEXT_FONT)) {
827 if (!getPreferenceStore().getBoolean(fontPropagatedKey))
828 PreferenceConverter.setValue(PlatformUI.getWorkbench().getPreferenceStore(), PreferenceConstants.EDITOR_TEXT_FONT, PreferenceConverter.getFontDataArray(getPreferenceStore(), JFaceResources.TEXT_FONT));
830 getPreferenceStore().setValue(fontPropagatedKey, true);
833 * Backwards compatibility: set the Java editor font in this plug-in's
834 * preference store to let older versions access it. Since 2.1 the
835 * Java editor font is managed by the workbench font preference page.
837 PreferenceConverter.putValue(getPreferenceStore(), JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry().getFontData(PreferenceConstants.EDITOR_TEXT_FONT));
839 fFontPropertyChangeListener= new IPropertyChangeListener() {
840 public void propertyChange(PropertyChangeEvent event) {
841 if (PreferenceConstants.EDITOR_TEXT_FONT.equals(event.getProperty()))
842 PreferenceConverter.putValue(getPreferenceStore(), JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry().getFontData(PreferenceConstants.EDITOR_TEXT_FONT));
845 JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
848 * Backwards compatibility: propagate the Java editor tab width from a
849 * pre-3.0 plug-in to the new preference key. This is done only once.
851 final String oldTabWidthKey= PreferenceConstants.EDITOR_TAB_WIDTH;
852 final String newTabWidthKey= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH;
853 String tabWidthPropagatedKey= "tabWidthPropagated"; //$NON-NLS-1$
854 if (getPreferenceStore().contains(oldTabWidthKey) && !getPreferenceStore().isDefault(oldTabWidthKey)) {
855 if (!getPreferenceStore().getBoolean(tabWidthPropagatedKey))
856 getPreferenceStore().setValue(newTabWidthKey, getPreferenceStore().getInt(oldTabWidthKey));
858 getPreferenceStore().setValue(tabWidthPropagatedKey, true);
861 * Backwards compatibility: set the Java editor tab width in this plug-in's
862 * preference store with the old key to let older versions access it.
863 * Since 3.0 the tab width is managed by the extended texteditor and
866 getPreferenceStore().putValue(oldTabWidthKey, getPreferenceStore().getString(newTabWidthKey));
868 fPropertyChangeListener= new IPropertyChangeListener() {
869 public void propertyChange(PropertyChangeEvent event) {
870 if (newTabWidthKey.equals(event.getProperty()))
871 getPreferenceStore().putValue(oldTabWidthKey, getPreferenceStore().getString(newTabWidthKey));
874 getPreferenceStore().addPropertyChangeListener(fPropertyChangeListener);
877 * Backward compatibility for the refactoring preference key.
879 // getPreferenceStore().setValue(
880 // PreferenceConstants.REFACTOR_ERROR_PAGE_SEVERITY_THRESHOLD,
881 // RefactoringCore.getConditionCheckingFailedSeverity());
885 * Uninstalls backwards compatibility for the preference store.
887 private void uninstallPreferenceStoreBackwardsCompatibility() {
888 JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
889 getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener);
892 * Method declared in Plugin
894 public void start(BundleContext context) throws Exception {
895 super.start(context);
897 JavaCore.start(this, context);
901 // externalTools.startUp();
902 getStandardDisplay().asyncExec(new Runnable() {
904 //initialize the variable context manager
905 VariableContextManager.getDefault();
909 // if (USE_WORKING_COPY_OWNERS) {
910 WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
911 public IBuffer createBuffer(ICompilationUnit workingCopy) {
912 ICompilationUnit original= workingCopy.getPrimary();
913 IResource resource= original.getResource();
914 if (resource instanceof IFile)
915 return new DocumentAdapter(workingCopy, (IFile) resource);
916 return DocumentAdapter.NULL;
921 installPreferenceStoreBackwardsCompatibility();
923 // AllTypesCache.initialize();
925 // Initialize AST provider
928 // public void startup() throws CoreException {
930 // // begin JavaCore.startup();
931 // JavaModelManager manager = JavaModelManager.getJavaModelManager();
933 // manager.configurePluginDebugOptions();
934 // // request state folder creation (workaround 19885)
935 // // JavaCore.getPlugin().getStateLocation();
936 // getStateLocation();
937 // // retrieve variable values
938 // // JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new
939 // // JavaModelManager.PluginPreferencesListener());
940 // getPluginPreferences().addPropertyChangeListener(
941 // new JavaModelManager.PluginPreferencesListener());
942 // // TODO khartlage temp-del
943 // // manager.loadVariablesAndContainers();
944 // final IWorkspace workspace = ResourcesPlugin.getWorkspace();
945 // workspace.addResourceChangeListener(
946 // manager.deltaState,
947 // IResourceChangeEvent.PRE_BUILD
948 // | IResourceChangeEvent.POST_BUILD
949 // | IResourceChangeEvent.POST_CHANGE
950 // | IResourceChangeEvent.PRE_DELETE
951 // | IResourceChangeEvent.PRE_CLOSE);
952 // // startIndexing();
953 // workspace.addSaveParticipant(PHPeclipsePlugin.getDefault(), manager);
954 // } catch (CoreException e) {
955 // } catch (RuntimeException e) {
956 // manager.shutdown();
959 // // end JavaCore.startup();
960 // IAdapterManager platformManager = Platform.getAdapterManager();
961 // platformManager.registerAdapters(new PHPElementAdapterFactory(),
962 // PHPElement.class);
963 // platformManager.registerAdapters(new ResourceAdapterFactory(),
965 // // externalTools.startUp();
966 // getStandardDisplay().asyncExec(new Runnable() {
967 // public void run() {
968 // //initialize the variable context manager
969 // VariableContextManager.getDefault();
975 private void registerAdapters() {
976 fJavaElementAdapterFactory= new JavaElementAdapterFactory();
977 // fMarkerAdapterFactory= new MarkerAdapterFactory();
978 // fEditorInputAdapterFactory= new EditorInputAdapterFactory();
979 fResourceAdapterFactory= new ResourceAdapterFactory();
980 // fLogicalPackageAdapterFactory= new LogicalPackageAdapterFactory();
982 IAdapterManager manager= Platform.getAdapterManager();
983 manager.registerAdapters(fJavaElementAdapterFactory, IJavaElement.class);
984 // manager.registerAdapters(fMarkerAdapterFactory, IMarker.class);
985 // manager.registerAdapters(fEditorInputAdapterFactory, IEditorInput.class);
986 manager.registerAdapters(fResourceAdapterFactory, IResource.class);
987 // manager.registerAdapters(fLogicalPackageAdapterFactory, LogicalPackage.class);
990 private void unregisterAdapters() {
991 IAdapterManager manager= Platform.getAdapterManager();
992 manager.unregisterAdapters(fJavaElementAdapterFactory);
993 // manager.unregisterAdapters(fMarkerAdapterFactory);
994 // manager.unregisterAdapters(fEditorInputAdapterFactory);
995 manager.unregisterAdapters(fResourceAdapterFactory);
996 // manager.unregisterAdapters(fLogicalPackageAdapterFactory);
1000 * Returns a combined preference store, this store is read-only.
1002 * @return the combined preference store
1006 public IPreferenceStore getCombinedPreferenceStore() {
1007 if (fCombinedPreferenceStore == null) {
1008 IPreferenceStore generalTextStore= EditorsUI.getPreferenceStore();
1009 fCombinedPreferenceStore= new ChainedPreferenceStore(new IPreferenceStore[] { getPreferenceStore(), new PreferencesAdapter(JavaCore.getPlugin().getPluginPreferences()), generalTextStore });
1011 return fCombinedPreferenceStore;
1014 public synchronized IBufferFactory getBufferFactory() {
1015 if (fBufferFactory == null)
1016 fBufferFactory= new CustomBufferFactory();
1017 return fBufferFactory;
1020 * Returns the registry of the extensions to the <code>org.eclipse.jdt.ui.javaFoldingStructureProvider</code>
1023 * @return the registry of contributed <code>IJavaFoldingStructureProvider</code>
1026 public synchronized JavaFoldingStructureProviderRegistry getFoldingStructureProviderRegistry() {
1027 if (fFoldingStructureProviderRegistry == null)
1028 fFoldingStructureProviderRegistry= new JavaFoldingStructureProviderRegistry();
1029 return fFoldingStructureProviderRegistry;