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;
21 import net.sourceforge.phpdt.core.JavaCore;
22 import net.sourceforge.phpdt.externaltools.internal.model.ColorManager;
23 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsPlugin;
24 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
25 import net.sourceforge.phpdt.internal.core.JavaModelManager;
26 import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache;
27 import net.sourceforge.phpdt.internal.ui.preferences.TemplatePreferencePage;
28 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
29 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
30 import net.sourceforge.phpdt.internal.ui.viewsupport.ProblemMarkerManager;
31 import net.sourceforge.phpdt.ui.IContextMenuConstants;
32 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
33 import net.sourceforge.phpdt.ui.PreferenceConstants;
34 import net.sourceforge.phpdt.ui.text.JavaTextTools;
35 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
36 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
37 import net.sourceforge.phpeclipse.builder.FileStorage;
38 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
39 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
40 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
41 import net.sourceforge.phpeclipse.phpeditor.WorkingCopyManager;
42 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
43 import net.sourceforge.phpeclipse.resourcesview.PHPElement;
44 import net.sourceforge.phpeclipse.resourcesview.PHPElementAdapterFactory;
45 import net.sourceforge.phpeclipse.resourcesview.ResourceAdapterFactory;
46 import org.eclipse.core.boot.BootLoader;
47 import org.eclipse.core.resources.IFile;
48 import org.eclipse.core.resources.IProject;
49 import org.eclipse.core.resources.IResource;
50 import org.eclipse.core.resources.IResourceChangeEvent;
51 import org.eclipse.core.resources.IWorkspace;
52 import org.eclipse.core.resources.ResourcesPlugin;
53 import org.eclipse.core.runtime.CoreException;
54 import org.eclipse.core.runtime.IAdapterManager;
55 import org.eclipse.core.runtime.IPath;
56 import org.eclipse.core.runtime.IPluginDescriptor;
57 import org.eclipse.core.runtime.IConfigurationElement;
58 import org.eclipse.core.runtime.IStatus;
59 import org.eclipse.core.runtime.Path;
60 import org.eclipse.core.runtime.Platform;
61 import org.eclipse.core.runtime.Status;
62 import org.eclipse.jface.action.GroupMarker;
63 import org.eclipse.jface.action.IMenuManager;
64 import org.eclipse.jface.action.Separator;
65 import org.eclipse.jface.preference.IPreferenceStore;
66 import org.eclipse.jface.preference.PreferenceConverter;
67 import org.eclipse.jface.text.BadLocationException;
68 import org.eclipse.jface.text.IDocument;
69 import org.eclipse.swt.widgets.Display;
70 import org.eclipse.swt.widgets.Shell;
71 import org.eclipse.ui.IEditorDescriptor;
72 import org.eclipse.ui.IEditorInput;
73 import org.eclipse.ui.IEditorPart;
74 import org.eclipse.ui.IEditorRegistry;
75 import org.eclipse.ui.IWorkbench;
76 import org.eclipse.ui.IWorkbenchPage;
77 import org.eclipse.ui.IWorkbenchWindow;
78 import org.eclipse.ui.PlatformUI;
79 import org.eclipse.ui.ide.IDE;
80 import org.eclipse.ui.plugin.AbstractUIPlugin;
81 import org.eclipse.ui.texteditor.IDocumentProvider;
82 import org.eclipse.ui.texteditor.ITextEditor;
83 import org.eclipse.ui.texteditor.ConfigurationElementSorter;
85 * The main plugin class to be used in the desktop.
87 public class PHPeclipsePlugin extends AbstractUIPlugin
89 IPreferenceConstants {
91 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
93 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
95 * id of builder - matches plugin.xml (concatenate pluginid.builderid)
97 public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
98 //public static final String BUILDER_INDEX_ID = PLUGIN_ID + ".indexbuilder";
99 /** General debug flag */
100 public static final boolean DEBUG = false;
102 * The maximum number of allowed proposals by category
104 public final static int MAX_PROPOSALS = 200;
105 private static ExternalToolsPlugin externalTools;
107 * The Java virtual machine that we are running on.
109 private static int jvm;
111 private static final int MRJ_2_0 = 0;
112 /** MRJ 2.1 or later */
113 private static final int MRJ_2_1 = 1;
114 /** Java on Mac OS X 10.0 (MRJ 3.0) */
115 private static final int MRJ_3_0 = 3;
117 private static final int MRJ_3_1 = 4;
118 /** JVM constant for any other platform */
119 private static final int OTHER = -1;
120 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID +
121 // ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
122 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID
123 + ".ui.CodingActionSet"; //$NON-NLS-1$
124 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
125 public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
126 public static final String PHPPARSER_NEW = "test.PHPParser";
127 /** Change this if you want to switch PHP Parser. */
128 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
129 //The shared instance.
130 private static PHPeclipsePlugin plugin;
132 private static final int WINDOWS_9x = 6;
134 private static final int WINDOWS_NT = 5;
135 private ImageDescriptorRegistry fImageDescriptorRegistry;
136 private HashMap fIndexManagerMap = new HashMap();
137 private IWorkingCopyManager fWorkingCopyManager;
138 private PHPDocumentProvider fCompilationUnitDocumentProvider;
139 private JavaTextTools fJavaTextTools;
140 private ProblemMarkerManager fProblemMarkerManager;
141 private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
142 private IFile fLastEditorFile = null;
143 private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
147 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
151 externalTools = new ExternalToolsPlugin();
154 // ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
155 // } catch (MissingResourceException x) {
156 // resourceBundle = null;
160 * Returns all Java editor text hovers contributed to the workbench.
162 * @return an array of JavaEditorTextHoverDescriptor
165 public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
166 if (fJavaEditorTextHoverDescriptors == null)
167 fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor.getContributedHovers();
168 ConfigurationElementSorter sorter= new ConfigurationElementSorter() {
169 public IConfigurationElement getConfigurationElement(Object object) {
170 return ((JavaEditorTextHoverDescriptor)object).getConfigurationElement();
173 sorter.sort(fJavaEditorTextHoverDescriptors);
174 return fJavaEditorTextHoverDescriptors;
177 * Resets the Java editor text hovers contributed to the workbench.
179 * This will force a rebuild of the descriptors the next time a client asks
183 * @return an array of JavaEditorTextHoverDescriptor
186 public void resetJavaEditorTextHoverDescriptors() {
187 fJavaEditorTextHoverDescriptors = null;
190 * Creates the PHP plugin standard groups in a context menu.
192 public static void createStandardGroups(IMenuManager menu) {
195 menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
196 menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
197 menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
198 menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
199 menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
200 menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
201 menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
202 menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
203 menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
204 menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
205 menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
207 public static IWorkbenchPage getActivePage() {
208 return getDefault().internalGetActivePage();
210 public static Shell getActiveWorkbenchShell() {
211 return getActiveWorkbenchWindow().getShell();
214 * Returns an array of all editors that have an unsaved content. If the
215 * identical content is presented in more than one editor, only one of those
216 * editor parts is part of the result.
218 * @return an array of all dirty editor parts.
220 public static IEditorPart[] getDirtyEditors() {
221 Set inputs = new HashSet();
222 List result = new ArrayList(0);
223 IWorkbench workbench = getDefault().getWorkbench();
224 IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
225 for (int i = 0; i < windows.length; i++) {
226 IWorkbenchPage[] pages = windows[i].getPages();
227 for (int x = 0; x < pages.length; x++) {
228 IEditorPart[] editors = pages[x].getDirtyEditors();
229 for (int z = 0; z < editors.length; z++) {
230 IEditorPart ep = editors[z];
231 IEditorInput input = ep.getEditorInput();
232 if (!inputs.contains(input)) {
239 return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]);
241 public static IWorkbenchWindow getActiveWorkbenchWindow() {
242 return getDefault().getWorkbench().getActiveWorkbenchWindow();
245 * Returns the shared instance.
247 public static PHPeclipsePlugin getDefault() {
250 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
251 return getDefault().internalGetImageDescriptorRegistry();
253 static IPath getInstallLocation() {
254 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
256 public static int getJVM() {
259 public static String getPluginId() {
260 return getDefault().getDescriptor().getUniqueIdentifier();
263 * Returns the standard display to be used. The method first checks, if the
264 * thread calling this method has an associated display. If so, this display
265 * is returned. Otherwise the method returns the default display.
267 public static Display getStandardDisplay() {
268 Display display = Display.getCurrent();
269 if (display == null) {
270 display = Display.getDefault();
274 // public static ExternalToolsPlugin getExternalTools() {
275 // return externalTools;
278 * Returns the workspace instance.
280 public static IWorkspace getWorkspace() {
281 return ResourcesPlugin.getWorkspace();
283 public static boolean isDebug() {
284 return getDefault().isDebugging();
286 // public static void logErrorMessage(String message) {
287 // log(new Status(IStatus.ERROR, getPluginId(),
288 // JavaStatusConstants.INTERNAL_ERROR, message, null));
291 // public static void logErrorStatus(String message, IStatus status) {
292 // if (status == null) {
293 // logErrorMessage(message);
296 // MultiStatus multi= new MultiStatus(getPluginId(),
297 // JavaStatusConstants.INTERNAL_ERROR, message, null);
298 // multi.add(status);
302 // public static void log(Throwable e) {
303 // log(new Status(IStatus.ERROR, getPluginId(),
304 // JavaStatusConstants.INTERNAL_ERROR,
305 // JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
307 public static void log(int severity, String message) {
308 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
311 public static void log(IStatus status) {
312 getDefault().getLog().log(status);
314 public static void log(Throwable e) {
315 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
316 "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
318 private static void setJVM() {
319 String osName = System.getProperty("os.name");
320 if (osName.startsWith("Mac OS")) {
321 String mrjVersion = System.getProperty("mrj.version");
322 String majorMRJVersion = mrjVersion.substring(0, 3);
325 double version = Double.valueOf(majorMRJVersion).doubleValue();
328 } else if (version >= 2.1 && version < 3) {
330 } else if (version == 3.0) {
332 } else if (version >= 3.1) {
335 } catch (NumberFormatException nfe) {
337 } else if (osName.startsWith("Windows")) {
338 if (osName.indexOf("9") != -1) {
345 // TODO: refactor this into a better method name !
346 public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
347 if (fCompilationUnitDocumentProvider == null)
348 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
349 return fCompilationUnitDocumentProvider;
352 * Get the identifier index manager for the given project
355 * the current project
358 public IdentifierIndexManager getIndexManager(IProject iProject) {
359 String indexFilename = iProject.getLocation() + File.separator
361 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap
363 if (indexManager == null) {
364 indexManager = new IdentifierIndexManager(indexFilename);
365 fIndexManagerMap.put(indexFilename, indexManager);
369 public synchronized IWorkingCopyManager getWorkingCopyManager() {
370 if (fWorkingCopyManager == null) {
371 PHPDocumentProvider provider = getCompilationUnitDocumentProvider();
372 fWorkingCopyManager = new WorkingCopyManager(provider);
374 return fWorkingCopyManager;
376 public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
377 if (fMembersOrderPreferenceCache == null)
378 fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
379 return fMembersOrderPreferenceCache;
381 public synchronized ProblemMarkerManager getProblemMarkerManager() {
382 if (fProblemMarkerManager == null)
383 fProblemMarkerManager = new ProblemMarkerManager();
384 return fProblemMarkerManager;
386 public synchronized JavaTextTools getJavaTextTools() {
387 if (fJavaTextTools == null)
388 fJavaTextTools = new JavaTextTools(getPreferenceStore());
389 return fJavaTextTools;
391 public IFile getLastEditorFile() {
392 return fLastEditorFile;
395 * Returns the string from the plugin's resource bundle, or 'key' if not
398 // public static String getResourceString(String key) {
399 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
401 // return bundle.getString(key);
402 // } catch (MissingResourceException e) {
407 * Returns the plugin's resource bundle,
409 // public ResourceBundle getResourceBundle() {
410 // return resourceBundle;
412 protected void initializeDefaultPreferences(IPreferenceStore store) {
413 // windows preferences:
414 store.setDefault(LOCALHOST_PREF, "http://localhost");
415 store.setDefault(SHOW_EXTERNAL_PREVIEW_PREF, "true");
416 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
417 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
418 String windowsSystem = BootLoader.getWS();
419 if (jvm == WINDOWS_9x) {
420 store.setDefault(EXTERNAL_BROWSER_PREF,
421 "command.com /c start iexplore {0}");
422 } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
423 store.setDefault(EXTERNAL_BROWSER_PREF,
424 "rundll32 url.dll,FileProtocolHandler {0}");
425 } else if (windowsSystem.equals(BootLoader.WS_CARBON)) {
426 // TODO How do we start Safari on Mac OS X ?
427 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
429 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
431 store.setDefault(DOCUMENTROOT_PREF, getWorkspace().getRoot().getLocation()
433 // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
435 if (windowsSystem.equals(BootLoader.WS_WIN32)) {
436 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
437 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
438 store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
439 store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
441 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
442 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
443 store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
444 store.setDefault(APACHE_RUN_PREF, "/apache/apache");
446 store.setDefault(MYSQL_PREF, "--standalone");
447 store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
448 store.setDefault(APACHE_STOP_PREF, "-k shutdown");
449 store.setDefault(APACHE_RESTART_PREF, "-k restart");
450 store.setDefault(MYSQL_START_BACKGROUND, "true");
451 store.setDefault(APACHE_START_BACKGROUND, "true");
452 store.setDefault(APACHE_STOP_BACKGROUND, "true");
453 store.setDefault(APACHE_RESTART_BACKGROUND, "true");
454 store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
455 store.setDefault(PHP_INTERNAL_PARSER, "false");
456 store.setDefault(PHP_EXTERNAL_PARSER, "true");
457 // store.setDefault(PHP_PARSE_ON_SAVE, "true");
458 // show line numbers:
459 // store.setDefault(LINE_NUMBER_RULER, "false");
460 // store.setDefault(FORMATTER_TAB_SIZE, "4");
461 // php syntax highlighting
462 store.setDefault(PHP_USERDEF_XMLFILE, "");
463 //assume there is none chooA
464 PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT,
465 PHPColorProvider.MULTI_LINE_COMMENT);
466 PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT,
467 PHPColorProvider.SINGLE_LINE_COMMENT);
468 PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
470 .setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
471 PreferenceConverter.setDefault(store, PHP_VARIABLE,
472 PHPColorProvider.VARIABLE);
473 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME,
474 PHPColorProvider.FUNCTION_NAME);
475 PreferenceConverter.setDefault(store, PHP_CONSTANT,
476 PHPColorProvider.CONSTANT);
477 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
478 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
480 .setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
481 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD,
482 PHPColorProvider.PHPDOC_KEYWORD);
483 PreferenceConverter.setDefault(store, PHPDOC_TAG,
484 PHPColorProvider.PHPDOC_TAG);
485 PreferenceConverter.setDefault(store, PHPDOC_LINK,
486 PHPColorProvider.PHPDOC_LINK);
487 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT,
488 PHPColorProvider.PHPDOC_DEFAULT);
489 // PreferenceConverter.setDefault(
491 // PHP_EDITOR_BACKGROUND,
492 // PHPColorProvider.BACKGROUND);
493 // PreferenceConverter.setDefault(
495 // LINKED_POSITION_COLOR,
496 // PHPColorProvider.LINKED_POSITION_COLOR);
497 // PreferenceConverter.setDefault(
499 // LINE_NUMBER_COLOR,
500 // PHPColorProvider.LINE_NUMBER_COLOR);
501 // // set default PHPDoc colors:
502 // PreferenceConverter.setDefault(
505 // PHPColorProvider.PHPDOC_KEYWORD);
506 // PreferenceConverter.setDefault(
509 // PHPColorProvider.PHPDOC_LINK);
510 // PreferenceConverter.setDefault(
513 // PHPColorProvider.PHPDOC_DEFAULT);
514 // PreferenceConverter.setDefault(
517 // PHPColorProvider.PHPDOC_TAG);
518 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
519 // PreferenceConverter.setDefault(
521 // PREFERENCE_COLOR_BACKGROUND,
522 // PHPColorProvider.BACKGROUND_COLOR);
524 // store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
525 // store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
526 // store.setDefault(RESOURCE_BUNDLE_DE, "false");
527 // store.setDefault(RESOURCE_BUNDLE_FR, "false");
528 // store.setDefault(RESOURCE_BUNDLE_ES, "false");
529 store.setDefault(PHP_OUTLINE_CLASS, "true"); //$NON-NLS-1$
530 store.setDefault(PHP_OUTLINE_FUNC, "true"); //$NON-NLS-1$
531 store.setDefault(PHP_OUTLINE_VAR, "true"); //$NON-NLS-1$
532 TemplatePreferencePage.initDefaults(store);
533 //this will initialize the static fields in the syntaxrdr class
535 JavaCore.initializeDefaultPluginPreferences();
536 PreferenceConstants.initializeDefaultValues(store);
537 externalTools.initializeDefaultPreferences(store);
539 private IWorkbenchPage internalGetActivePage() {
540 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
542 return window.getActivePage();
545 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
546 if (fImageDescriptorRegistry == null)
547 fImageDescriptorRegistry = new ImageDescriptorRegistry();
548 return fImageDescriptorRegistry;
551 * Open a file in the Workbench that may or may not exist in the workspace.
552 * Must be run on the UI thread.
555 * @throws CoreException
557 public ITextEditor openFileInTextEditor(String filename) throws CoreException {
558 // reject directories
559 if (new File(filename).isDirectory())
561 IWorkbench workbench = PlatformUI.getWorkbench();
562 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
563 IWorkbenchPage page = window.getActivePage();
564 IPath path = new Path(filename);
565 // If the file exists in the workspace, open it
566 IFile file = getWorkspace().getRoot().getFileForLocation(path);
568 ITextEditor textEditor;
569 if (file != null && file.exists()) {
570 editor = IDE.openEditor(page, file, true);
571 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
573 // Otherwise open the stream directly
576 FileStorage storage = new FileStorage(path);
577 IEditorRegistry registry = getWorkbench().getEditorRegistry();
578 IEditorDescriptor desc = registry.getDefaultEditor(filename);
580 desc = registry.getDefaultEditor();
582 IEditorInput input = new ExternalEditorInput(storage);
583 editor = page.openEditor(input, desc.getId());
584 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
585 // If the storage provider is not ours, we can't guarantee read/write.
586 if (textEditor != null) {
587 IDocumentProvider documentProvider = textEditor.getDocumentProvider();
588 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
589 storage.setReadOnly();
596 * Open a file in the Workbench that may or may not exist in the workspace.
597 * Must be run on the UI thread.
601 * @throws CoreException
603 public void openFileAndGotoLine(String filename, int line)
604 throws CoreException {
605 ITextEditor textEditor = openFileInTextEditor(filename);
606 if (textEditor != null) {
607 // If a line number was given, go to it
610 line--; // document is 0 based
611 IDocument document = textEditor.getDocumentProvider().getDocument(
612 textEditor.getEditorInput());
613 textEditor.selectAndReveal(document.getLineOffset(line), document
614 .getLineLength(line));
615 } catch (BadLocationException e) {
616 // invalid text position -> do nothing
622 * Open a file in the Workbench that may or may not exist in the workspace.
623 * Must be run on the UI thread.
627 * @throws CoreException
629 public void openFileAndGotoOffset(String filename, int offset, int length)
630 throws CoreException {
631 ITextEditor textEditor = openFileInTextEditor(filename);
632 if (textEditor != null) {
633 // If a line number was given, go to it
635 IDocument document = textEditor.getDocumentProvider().getDocument(
636 textEditor.getEditorInput());
637 textEditor.selectAndReveal(offset, length);
641 public void openFileAndFindString(String filename, String findString)
642 throws CoreException {
643 ITextEditor textEditor = openFileInTextEditor(filename);
644 if (textEditor != null) {
645 // If a string was given, go to it
646 if (findString != null) {
648 IDocument document = textEditor.getDocumentProvider().getDocument(
649 textEditor.getEditorInput());
650 int offset = document.search(0, findString, true, false, true);
651 textEditor.selectAndReveal(offset, findString.length());
652 } catch (BadLocationException e) {
653 // invalid text position -> do nothing
658 public void setLastEditorFile(IFile textEditor) {
659 this.fLastEditorFile = textEditor;
662 * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
664 public void shutdown() throws CoreException {
665 // moved down (see below):
667 // externalTools.shutDown();
668 ColorManager.getDefault().dispose();
669 // save the information from the php index files if necessary
670 Collection collection = fIndexManagerMap.values();
671 Iterator iterator = collection.iterator();
672 IdentifierIndexManager indexManager = null;
673 while (iterator.hasNext()) {
674 indexManager = (IdentifierIndexManager) iterator.next();
675 indexManager.writeFile();
677 if (fImageDescriptorRegistry != null)
678 fImageDescriptorRegistry.dispose();
679 // unregisterAdapters();
681 if (fWorkingCopyManager != null) {
682 fWorkingCopyManager.shutdown();
683 fWorkingCopyManager = null;
685 if (fCompilationUnitDocumentProvider != null) {
686 fCompilationUnitDocumentProvider.shutdown();
687 fCompilationUnitDocumentProvider = null;
689 if (fJavaTextTools != null) {
690 fJavaTextTools.dispose();
691 fJavaTextTools = null;
693 // JavaDocLocations.shutdownJavadocLocations();
695 // JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
696 // begin JavaCore#shutdown()
697 //savePluginPreferences();
698 savePluginPreferences();
699 IWorkspace workspace = ResourcesPlugin.getWorkspace();
700 workspace.removeResourceChangeListener(JavaModelManager
701 .getJavaModelManager().deltaProcessor);
702 workspace.removeSaveParticipant(PHPeclipsePlugin.getDefault());
703 ((JavaModelManager) JavaModelManager.getJavaModelManager()).shutdown();
704 // end JavaCore#shutdown()
706 public void startup() throws CoreException {
708 // begin JavaCore.startup();
709 JavaModelManager manager = JavaModelManager.getJavaModelManager();
711 manager.configurePluginDebugOptions();
712 // request state folder creation (workaround 19885)
713 // JavaCore.getPlugin().getStateLocation();
715 // retrieve variable values
716 // JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new
717 // JavaModelManager.PluginPreferencesListener());
718 getPluginPreferences().addPropertyChangeListener(
719 new JavaModelManager.PluginPreferencesListener());
720 // TODO khartlage temp-del
721 // manager.loadVariablesAndContainers();
722 IWorkspace workspace = ResourcesPlugin.getWorkspace();
723 workspace.addResourceChangeListener(manager.deltaProcessor,
724 IResourceChangeEvent.PRE_AUTO_BUILD
725 | IResourceChangeEvent.POST_AUTO_BUILD
726 | IResourceChangeEvent.POST_CHANGE
727 | IResourceChangeEvent.PRE_DELETE
728 | IResourceChangeEvent.PRE_CLOSE);
730 workspace.addSaveParticipant(PHPeclipsePlugin.getDefault(), manager);
731 } catch (CoreException e) {
732 } catch (RuntimeException e) {
736 // end JavaCore.startup();
737 IAdapterManager platformManager = Platform.getAdapterManager();
738 platformManager.registerAdapters(new PHPElementAdapterFactory(),
740 platformManager.registerAdapters(new ResourceAdapterFactory(),
742 // externalTools.startUp();
743 getStandardDisplay().asyncExec(new Runnable() {
745 //initialize the variable context manager
746 VariableContextManager.getDefault();