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.JavaCore;
23 import net.sourceforge.phpdt.externaltools.internal.model.ColorManager;
24 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsPlugin;
25 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
26 import net.sourceforge.phpdt.internal.core.JavaModelManager;
27 import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache;
28 import net.sourceforge.phpdt.internal.ui.preferences.TemplatePreferencePage;
29 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
30 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
31 import net.sourceforge.phpdt.internal.ui.viewsupport.ProblemMarkerManager;
32 import net.sourceforge.phpdt.ui.IContextMenuConstants;
33 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
34 import net.sourceforge.phpdt.ui.PreferenceConstants;
35 import net.sourceforge.phpdt.ui.text.JavaTextTools;
36 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
37 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
38 import net.sourceforge.phpeclipse.builder.FileStorage;
39 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
40 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
41 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
42 import net.sourceforge.phpeclipse.phpeditor.WorkingCopyManager;
43 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
44 import net.sourceforge.phpeclipse.resourcesview.PHPElement;
45 import net.sourceforge.phpeclipse.resourcesview.PHPElementAdapterFactory;
46 import net.sourceforge.phpeclipse.resourcesview.ResourceAdapterFactory;
48 import org.eclipse.core.boot.BootLoader;
49 import org.eclipse.core.resources.IFile;
50 import org.eclipse.core.resources.IProject;
51 import org.eclipse.core.resources.IResource;
52 import org.eclipse.core.resources.IResourceChangeEvent;
53 import org.eclipse.core.resources.IWorkspace;
54 import org.eclipse.core.resources.ResourcesPlugin;
55 import org.eclipse.core.runtime.CoreException;
56 import org.eclipse.core.runtime.IAdapterManager;
57 import org.eclipse.core.runtime.IPath;
58 import org.eclipse.core.runtime.IPluginDescriptor;
59 import org.eclipse.core.runtime.IStatus;
60 import org.eclipse.core.runtime.Path;
61 import org.eclipse.core.runtime.Platform;
62 import org.eclipse.core.runtime.Status;
63 import org.eclipse.jface.action.GroupMarker;
64 import org.eclipse.jface.action.IMenuManager;
65 import org.eclipse.jface.action.Separator;
66 import org.eclipse.jface.preference.IPreferenceStore;
67 import org.eclipse.jface.preference.PreferenceConverter;
68 import org.eclipse.jface.text.BadLocationException;
69 import org.eclipse.jface.text.IDocument;
70 import org.eclipse.swt.widgets.Display;
71 import org.eclipse.swt.widgets.Shell;
72 import org.eclipse.ui.IEditorDescriptor;
73 import org.eclipse.ui.IEditorInput;
74 import org.eclipse.ui.IEditorPart;
75 import org.eclipse.ui.IEditorRegistry;
76 import org.eclipse.ui.IWorkbench;
77 import org.eclipse.ui.IWorkbenchPage;
78 import org.eclipse.ui.IWorkbenchWindow;
79 import org.eclipse.ui.PlatformUI;
80 import org.eclipse.ui.ide.IDE;
81 import org.eclipse.ui.plugin.AbstractUIPlugin;
82 import org.eclipse.ui.texteditor.IDocumentProvider;
83 import org.eclipse.ui.texteditor.ITextEditor;
84 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
86 * The main plugin class to be used in the desktop.
88 public class PHPeclipsePlugin extends AbstractUIPlugin
90 IPreferenceConstants {
92 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
94 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
96 * id of builder - matches plugin.xml (concatenate pluginid.builderid)
98 public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
99 //public static final String BUILDER_INDEX_ID = PLUGIN_ID + ".indexbuilder";
100 /** General debug flag */
101 public static final boolean DEBUG = false;
103 * The maximum number of allowed proposals by category
105 public final static int MAX_PROPOSALS = 200;
106 private static ExternalToolsPlugin externalTools;
108 * The Java virtual machine that we are running on.
110 private static int jvm;
112 private static final int MRJ_2_0 = 0;
113 /** MRJ 2.1 or later */
114 private static final int MRJ_2_1 = 1;
115 /** Java on Mac OS X 10.0 (MRJ 3.0) */
116 private static final int MRJ_3_0 = 3;
118 private static final int MRJ_3_1 = 4;
119 /** JVM constant for any other platform */
120 private static final int OTHER = -1;
121 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID +
122 // ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
123 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID
124 + ".ui.CodingActionSet"; //$NON-NLS-1$
125 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
126 public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
127 public static final String PHPPARSER_NEW = "test.PHPParser";
128 /** Change this if you want to switch PHP Parser. */
129 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
130 //The shared instance.
131 private static PHPeclipsePlugin plugin;
133 private static final int WINDOWS_9x = 6;
135 private static final int WINDOWS_NT = 5;
136 private ImageDescriptorRegistry fImageDescriptorRegistry;
137 private HashMap fIndexManagerMap = new HashMap();
138 private IWorkingCopyManager fWorkingCopyManager;
139 private PHPDocumentProvider fCompilationUnitDocumentProvider;
140 private JavaTextTools fJavaTextTools;
141 private ProblemMarkerManager fProblemMarkerManager;
142 private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
143 private IFile fLastEditorFile = null;
144 private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
148 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
152 externalTools = new ExternalToolsPlugin();
155 // ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
156 // } catch (MissingResourceException x) {
157 // resourceBundle = null;
161 * Returns all Java editor text hovers contributed to the workbench.
163 * @return an array of JavaEditorTextHoverDescriptor
166 public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
167 if (fJavaEditorTextHoverDescriptors == null)
168 fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
169 .getContributedHovers();
170 return fJavaEditorTextHoverDescriptors;
173 * Resets the Java editor text hovers contributed to the workbench.
175 * This will force a rebuild of the descriptors the next time a client asks
179 * @return an array of JavaEditorTextHoverDescriptor
182 public void resetJavaEditorTextHoverDescriptors() {
183 fJavaEditorTextHoverDescriptors = null;
186 * Creates the PHP plugin standard groups in a context menu.
188 public static void createStandardGroups(IMenuManager menu) {
191 menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
192 menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
193 menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
194 menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
195 menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
196 menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
197 menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
198 menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
199 menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
200 menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
201 menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
203 public static IWorkbenchPage getActivePage() {
204 return getDefault().internalGetActivePage();
206 public static Shell getActiveWorkbenchShell() {
207 return getActiveWorkbenchWindow().getShell();
210 * Returns an array of all editors that have an unsaved content. If the
211 * identical content is presented in more than one editor, only one of those
212 * editor parts is part of the result.
214 * @return an array of all dirty editor parts.
216 public static IEditorPart[] getDirtyEditors() {
217 Set inputs = new HashSet();
218 List result = new ArrayList(0);
219 IWorkbench workbench = getDefault().getWorkbench();
220 IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
221 for (int i = 0; i < windows.length; i++) {
222 IWorkbenchPage[] pages = windows[i].getPages();
223 for (int x = 0; x < pages.length; x++) {
224 IEditorPart[] editors = pages[x].getDirtyEditors();
225 for (int z = 0; z < editors.length; z++) {
226 IEditorPart ep = editors[z];
227 IEditorInput input = ep.getEditorInput();
228 if (!inputs.contains(input)) {
235 return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]);
237 public static IWorkbenchWindow getActiveWorkbenchWindow() {
238 return getDefault().getWorkbench().getActiveWorkbenchWindow();
241 * Returns the shared instance.
243 public static PHPeclipsePlugin getDefault() {
246 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
247 return getDefault().internalGetImageDescriptorRegistry();
249 static IPath getInstallLocation() {
250 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
252 public static int getJVM() {
255 public static String getPluginId() {
256 return getDefault().getDescriptor().getUniqueIdentifier();
259 * Returns the standard display to be used. The method first checks, if the
260 * thread calling this method has an associated display. If so, this display
261 * is returned. Otherwise the method returns the default display.
263 public static Display getStandardDisplay() {
264 Display display = Display.getCurrent();
265 if (display == null) {
266 display = Display.getDefault();
270 // public static ExternalToolsPlugin getExternalTools() {
271 // return externalTools;
274 * Returns the workspace instance.
276 public static IWorkspace getWorkspace() {
277 return ResourcesPlugin.getWorkspace();
279 public static boolean isDebug() {
280 return getDefault().isDebugging();
282 // public static void logErrorMessage(String message) {
283 // log(new Status(IStatus.ERROR, getPluginId(),
284 // JavaStatusConstants.INTERNAL_ERROR, message, null));
287 // public static void logErrorStatus(String message, IStatus status) {
288 // if (status == null) {
289 // logErrorMessage(message);
292 // MultiStatus multi= new MultiStatus(getPluginId(),
293 // JavaStatusConstants.INTERNAL_ERROR, message, null);
294 // multi.add(status);
298 // public static void log(Throwable e) {
299 // log(new Status(IStatus.ERROR, getPluginId(),
300 // JavaStatusConstants.INTERNAL_ERROR,
301 // JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
303 public static void log(int severity, String message) {
304 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
307 public static void log(IStatus status) {
308 getDefault().getLog().log(status);
310 public static void log(Throwable e) {
311 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
312 "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
314 private static void setJVM() {
315 String osName = System.getProperty("os.name");
316 if (osName.startsWith("Mac OS")) {
317 String mrjVersion = System.getProperty("mrj.version");
318 String majorMRJVersion = mrjVersion.substring(0, 3);
321 double version = Double.valueOf(majorMRJVersion).doubleValue();
324 } else if (version >= 2.1 && version < 3) {
326 } else if (version == 3.0) {
328 } else if (version >= 3.1) {
331 } catch (NumberFormatException nfe) {
333 } else if (osName.startsWith("Windows")) {
334 if (osName.indexOf("9") != -1) {
341 // TODO: refactor this into a better method name !
342 public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
343 if (fCompilationUnitDocumentProvider == null)
344 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
345 return fCompilationUnitDocumentProvider;
348 * Get the identifier index manager for the given project
351 * the current project
354 public IdentifierIndexManager getIndexManager(IProject iProject) {
355 String indexFilename = iProject.getLocation() + File.separator
357 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap
359 if (indexManager == null) {
360 indexManager = new IdentifierIndexManager(indexFilename);
361 fIndexManagerMap.put(indexFilename, indexManager);
365 public synchronized IWorkingCopyManager getWorkingCopyManager() {
366 if (fWorkingCopyManager == null) {
367 PHPDocumentProvider provider = getCompilationUnitDocumentProvider();
368 fWorkingCopyManager = new WorkingCopyManager(provider);
370 return fWorkingCopyManager;
372 public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
373 if (fMembersOrderPreferenceCache == null)
374 fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
375 return fMembersOrderPreferenceCache;
377 public synchronized ProblemMarkerManager getProblemMarkerManager() {
378 if (fProblemMarkerManager == null)
379 fProblemMarkerManager = new ProblemMarkerManager();
380 return fProblemMarkerManager;
382 public synchronized JavaTextTools getJavaTextTools() {
383 if (fJavaTextTools == null)
384 fJavaTextTools = new JavaTextTools(getPreferenceStore());
385 return fJavaTextTools;
387 public IFile getLastEditorFile() {
388 return fLastEditorFile;
391 * Returns the string from the plugin's resource bundle, or 'key' if not
394 // public static String getResourceString(String key) {
395 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
397 // return bundle.getString(key);
398 // } catch (MissingResourceException e) {
403 * Returns the plugin's resource bundle,
405 // public ResourceBundle getResourceBundle() {
406 // return resourceBundle;
408 protected void initializeDefaultPreferences(IPreferenceStore store) {
409 // windows preferences:
410 store.setDefault(LOCALHOST_PREF, "http://localhost");
411 // store.setDefault(SHOW_EXTERNAL_PREVIEW_PREF, "true");
412 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
413 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
414 store.setDefault(PHP_OBFUSCATOR_DEFAULT, "c:\\temp");
415 store.setDefault(PHP_BOOKMARK_DEFAULT, "");
417 store.setDefault(PHP_AUTO_PREVIEW_DEFAULT, "true");
418 store.setDefault(PHP_BRING_TO_TOP_PREVIEW_DEFAULT, "true");
420 String windowsSystem = BootLoader.getWS();
421 if (jvm == WINDOWS_9x) {
422 store.setDefault(EXTERNAL_BROWSER_PREF,
423 "command.com /c start iexplore {0}");
424 } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
425 store.setDefault(EXTERNAL_BROWSER_PREF,
426 "rundll32 url.dll,FileProtocolHandler {0}");
427 } else if (windowsSystem.equals(BootLoader.WS_CARBON)) {
428 // TODO How do we start Safari on Mac OS X ?
429 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
431 store.setDefault(PHP_OBFUSCATOR_DEFAULT, "/tmp");
432 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
434 store.setDefault(DOCUMENTROOT_PREF, getWorkspace().getRoot().getLocation()
436 // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
438 if (windowsSystem.equals(BootLoader.WS_WIN32)) {
439 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
440 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
441 store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
442 store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
444 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
445 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
446 store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
447 store.setDefault(APACHE_RUN_PREF, "/apache/apache");
449 store.setDefault(MYSQL_PREF, "--standalone");
450 store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
451 store.setDefault(APACHE_STOP_PREF, "-k shutdown");
452 store.setDefault(APACHE_RESTART_PREF, "-k restart");
453 store.setDefault(MYSQL_START_BACKGROUND, "true");
454 store.setDefault(APACHE_START_BACKGROUND, "true");
455 store.setDefault(APACHE_STOP_BACKGROUND, "true");
456 store.setDefault(APACHE_RESTART_BACKGROUND, "true");
457 store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
458 store.setDefault(PHP_INTERNAL_PARSER, "false");
459 store.setDefault(PHP_EXTERNAL_PARSER, "true");
460 // store.setDefault(PHP_PARSE_ON_SAVE, "true");
461 // show line numbers:
462 // store.setDefault(LINE_NUMBER_RULER, "false");
463 // store.setDefault(FORMATTER_TAB_SIZE, "4");
464 // php syntax highlighting
465 store.setDefault(PHP_USERDEF_XMLFILE, "");
466 //assume there is none chooA
467 PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT,
468 PHPColorProvider.MULTI_LINE_COMMENT);
469 PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT,
470 PHPColorProvider.SINGLE_LINE_COMMENT);
471 PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
473 .setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
474 PreferenceConverter.setDefault(store, PHP_VARIABLE,
475 PHPColorProvider.VARIABLE);
476 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME,
477 PHPColorProvider.FUNCTION_NAME);
478 PreferenceConverter.setDefault(store, PHP_CONSTANT,
479 PHPColorProvider.CONSTANT);
480 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
481 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
483 .setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
484 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD,
485 PHPColorProvider.PHPDOC_KEYWORD);
486 PreferenceConverter.setDefault(store, PHPDOC_TAG,
487 PHPColorProvider.PHPDOC_TAG);
488 PreferenceConverter.setDefault(store, PHPDOC_LINK,
489 PHPColorProvider.PHPDOC_LINK);
490 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT,
491 PHPColorProvider.PHPDOC_DEFAULT);
492 // PreferenceConverter.setDefault(
494 // PHP_EDITOR_BACKGROUND,
495 // PHPColorProvider.BACKGROUND);
496 // PreferenceConverter.setDefault(
498 // LINKED_POSITION_COLOR,
499 // PHPColorProvider.LINKED_POSITION_COLOR);
500 // PreferenceConverter.setDefault(
502 // LINE_NUMBER_COLOR,
503 // PHPColorProvider.LINE_NUMBER_COLOR);
504 // // set default PHPDoc colors:
505 // PreferenceConverter.setDefault(
508 // PHPColorProvider.PHPDOC_KEYWORD);
509 // PreferenceConverter.setDefault(
512 // PHPColorProvider.PHPDOC_LINK);
513 // PreferenceConverter.setDefault(
516 // PHPColorProvider.PHPDOC_DEFAULT);
517 // PreferenceConverter.setDefault(
520 // PHPColorProvider.PHPDOC_TAG);
521 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
522 // PreferenceConverter.setDefault(
524 // PREFERENCE_COLOR_BACKGROUND,
525 // PHPColorProvider.BACKGROUND_COLOR);
527 // store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
528 // store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
529 // store.setDefault(RESOURCE_BUNDLE_DE, "false");
530 // store.setDefault(RESOURCE_BUNDLE_FR, "false");
531 // store.setDefault(RESOURCE_BUNDLE_ES, "false");
532 store.setDefault(PHP_OUTLINE_CLASS, "true"); //$NON-NLS-1$
533 store.setDefault(PHP_OUTLINE_FUNC, "true"); //$NON-NLS-1$
534 store.setDefault(PHP_OUTLINE_VAR, "true"); //$NON-NLS-1$
535 TemplatePreferencePage.initDefaults(store);
536 //this will initialize the static fields in the syntaxrdr class
538 JavaCore.initializeDefaultPluginPreferences();
539 PreferenceConstants.initializeDefaultValues(store);
540 externalTools.initializeDefaultPreferences(store);
541 MarkerAnnotationPreferences.initializeDefaultValues(store);
543 private IWorkbenchPage internalGetActivePage() {
544 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
546 return window.getActivePage();
549 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
550 if (fImageDescriptorRegistry == null)
551 fImageDescriptorRegistry = new ImageDescriptorRegistry();
552 return fImageDescriptorRegistry;
555 * Open a file in the Workbench that may or may not exist in the workspace.
556 * Must be run on the UI thread.
559 * @throws CoreException
561 public ITextEditor openFileInTextEditor(String filename) throws CoreException {
562 // reject directories
563 if (new File(filename).isDirectory())
565 IWorkbench workbench = PlatformUI.getWorkbench();
566 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
567 IWorkbenchPage page = window.getActivePage();
568 IPath path = new Path(filename);
569 // If the file exists in the workspace, open it
570 IFile file = getWorkspace().getRoot().getFileForLocation(path);
572 ITextEditor textEditor;
573 if (file != null && file.exists()) {
574 editor = IDE.openEditor(page, file, true);
575 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
577 // Otherwise open the stream directly
580 FileStorage storage = new FileStorage(path);
581 IEditorRegistry registry = getWorkbench().getEditorRegistry();
582 IEditorDescriptor desc = registry.getDefaultEditor(filename);
584 desc = registry.getDefaultEditor();
586 IEditorInput input = new ExternalEditorInput(storage);
587 editor = page.openEditor(input, desc.getId());
588 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
589 // If the storage provider is not ours, we can't guarantee read/write.
590 if (textEditor != null) {
591 IDocumentProvider documentProvider = textEditor.getDocumentProvider();
592 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
593 storage.setReadOnly();
600 * Open a file in the Workbench that may or may not exist in the workspace.
601 * Must be run on the UI thread.
605 * @throws CoreException
607 public void openFileAndGotoLine(String filename, int line)
608 throws CoreException {
609 ITextEditor textEditor = openFileInTextEditor(filename);
610 if (textEditor != null) {
611 // If a line number was given, go to it
614 line--; // document is 0 based
615 IDocument document = textEditor.getDocumentProvider().getDocument(
616 textEditor.getEditorInput());
617 textEditor.selectAndReveal(document.getLineOffset(line), document
618 .getLineLength(line));
619 } catch (BadLocationException e) {
620 // invalid text position -> do nothing
626 * Open a file in the Workbench that may or may not exist in the workspace.
627 * Must be run on the UI thread.
631 * @throws CoreException
633 public void openFileAndGotoOffset(String filename, int offset, int length)
634 throws CoreException {
635 ITextEditor textEditor = openFileInTextEditor(filename);
636 if (textEditor != null) {
637 // If a line number was given, go to it
639 IDocument document = textEditor.getDocumentProvider().getDocument(
640 textEditor.getEditorInput());
641 textEditor.selectAndReveal(offset, length);
645 public void openFileAndFindString(String filename, String findString)
646 throws CoreException {
647 ITextEditor textEditor = openFileInTextEditor(filename);
648 if (textEditor != null) {
649 // If a string was given, go to it
650 if (findString != null) {
652 IDocument document = textEditor.getDocumentProvider().getDocument(
653 textEditor.getEditorInput());
654 int offset = document.search(0, findString, true, false, true);
655 textEditor.selectAndReveal(offset, findString.length());
656 } catch (BadLocationException e) {
657 // invalid text position -> do nothing
662 public void setLastEditorFile(IFile textEditor) {
663 this.fLastEditorFile = textEditor;
666 * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
668 public void shutdown() throws CoreException {
669 // moved down (see below):
671 // externalTools.shutDown();
672 ColorManager.getDefault().dispose();
673 // save the information from the php index files if necessary
674 Collection collection = fIndexManagerMap.values();
675 Iterator iterator = collection.iterator();
676 IdentifierIndexManager indexManager = null;
677 while (iterator.hasNext()) {
678 indexManager = (IdentifierIndexManager) iterator.next();
679 indexManager.writeFile();
681 if (fImageDescriptorRegistry != null)
682 fImageDescriptorRegistry.dispose();
683 // unregisterAdapters();
685 if (fWorkingCopyManager != null) {
686 fWorkingCopyManager.shutdown();
687 fWorkingCopyManager = null;
689 if (fCompilationUnitDocumentProvider != null) {
690 fCompilationUnitDocumentProvider.shutdown();
691 fCompilationUnitDocumentProvider = null;
693 if (fJavaTextTools != null) {
694 fJavaTextTools.dispose();
695 fJavaTextTools = null;
697 // JavaDocLocations.shutdownJavadocLocations();
699 // JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
700 // begin JavaCore#shutdown()
701 //savePluginPreferences();
702 savePluginPreferences();
703 IWorkspace workspace = ResourcesPlugin.getWorkspace();
704 workspace.removeResourceChangeListener(JavaModelManager
705 .getJavaModelManager().deltaProcessor);
706 workspace.removeSaveParticipant(PHPeclipsePlugin.getDefault());
707 ((JavaModelManager) JavaModelManager.getJavaModelManager()).shutdown();
708 // end JavaCore#shutdown()
710 public void startup() throws CoreException {
712 // begin JavaCore.startup();
713 JavaModelManager manager = JavaModelManager.getJavaModelManager();
715 manager.configurePluginDebugOptions();
716 // request state folder creation (workaround 19885)
717 // JavaCore.getPlugin().getStateLocation();
719 // retrieve variable values
720 // JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new
721 // JavaModelManager.PluginPreferencesListener());
722 getPluginPreferences().addPropertyChangeListener(
723 new JavaModelManager.PluginPreferencesListener());
724 // TODO khartlage temp-del
725 // manager.loadVariablesAndContainers();
726 IWorkspace workspace = ResourcesPlugin.getWorkspace();
727 workspace.addResourceChangeListener(manager.deltaProcessor,
728 IResourceChangeEvent.PRE_AUTO_BUILD
729 | IResourceChangeEvent.POST_AUTO_BUILD
730 | IResourceChangeEvent.POST_CHANGE
731 | IResourceChangeEvent.PRE_DELETE
732 | IResourceChangeEvent.PRE_CLOSE);
734 workspace.addSaveParticipant(PHPeclipsePlugin.getDefault(), manager);
735 } catch (CoreException e) {
736 } catch (RuntimeException e) {
740 // end JavaCore.startup();
741 IAdapterManager platformManager = Platform.getAdapterManager();
742 platformManager.registerAdapters(new PHPElementAdapterFactory(),
744 platformManager.registerAdapters(new ResourceAdapterFactory(),
746 // externalTools.startUp();
747 getStandardDisplay().asyncExec(new Runnable() {
749 //initialize the variable context manager
750 VariableContextManager.getDefault();