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 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);
538 MarkerAnnotationPreferences.initializeDefaultValues(store);
540 private IWorkbenchPage internalGetActivePage() {
541 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
543 return window.getActivePage();
546 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
547 if (fImageDescriptorRegistry == null)
548 fImageDescriptorRegistry = new ImageDescriptorRegistry();
549 return fImageDescriptorRegistry;
552 * Open a file in the Workbench that may or may not exist in the workspace.
553 * Must be run on the UI thread.
556 * @throws CoreException
558 public ITextEditor openFileInTextEditor(String filename) throws CoreException {
559 // reject directories
560 if (new File(filename).isDirectory())
562 IWorkbench workbench = PlatformUI.getWorkbench();
563 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
564 IWorkbenchPage page = window.getActivePage();
565 IPath path = new Path(filename);
566 // If the file exists in the workspace, open it
567 IFile file = getWorkspace().getRoot().getFileForLocation(path);
569 ITextEditor textEditor;
570 if (file != null && file.exists()) {
571 editor = IDE.openEditor(page, file, true);
572 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
574 // Otherwise open the stream directly
577 FileStorage storage = new FileStorage(path);
578 IEditorRegistry registry = getWorkbench().getEditorRegistry();
579 IEditorDescriptor desc = registry.getDefaultEditor(filename);
581 desc = registry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
582 // desc = registry.getDefaultEditor();
584 IEditorInput input = new ExternalEditorInput(storage);
585 editor = page.openEditor(input, desc.getId());
586 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
587 // If the storage provider is not ours, we can't guarantee read/write.
588 if (textEditor != null) {
589 IDocumentProvider documentProvider = textEditor.getDocumentProvider();
590 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
591 storage.setReadOnly();
598 * Open a file in the Workbench that may or may not exist in the workspace.
599 * Must be run on the UI thread.
603 * @throws CoreException
605 public void openFileAndGotoLine(String filename, int line)
606 throws CoreException {
607 ITextEditor textEditor = openFileInTextEditor(filename);
608 if (textEditor != null) {
609 // If a line number was given, go to it
612 line--; // document is 0 based
613 IDocument document = textEditor.getDocumentProvider().getDocument(
614 textEditor.getEditorInput());
615 textEditor.selectAndReveal(document.getLineOffset(line), document
616 .getLineLength(line));
617 } catch (BadLocationException e) {
618 // invalid text position -> do nothing
624 * Open a file in the Workbench that may or may not exist in the workspace.
625 * Must be run on the UI thread.
629 * @throws CoreException
631 public void openFileAndGotoOffset(String filename, int offset, int length)
632 throws CoreException {
633 ITextEditor textEditor = openFileInTextEditor(filename);
634 if (textEditor != null) {
635 // If a line number was given, go to it
637 IDocument document = textEditor.getDocumentProvider().getDocument(
638 textEditor.getEditorInput());
639 textEditor.selectAndReveal(offset, length);
643 public void openFileAndFindString(String filename, String findString)
644 throws CoreException {
645 ITextEditor textEditor = openFileInTextEditor(filename);
646 if (textEditor != null) {
647 // If a string was given, go to it
648 if (findString != null) {
650 IDocument document = textEditor.getDocumentProvider().getDocument(
651 textEditor.getEditorInput());
652 int offset = document.search(0, findString, true, false, true);
653 textEditor.selectAndReveal(offset, findString.length());
654 } catch (BadLocationException e) {
655 // invalid text position -> do nothing
660 public void setLastEditorFile(IFile textEditor) {
661 this.fLastEditorFile = textEditor;
664 * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
666 public void shutdown() throws CoreException {
667 // moved down (see below):
669 // externalTools.shutDown();
670 ColorManager.getDefault().dispose();
671 // save the information from the php index files if necessary
672 Collection collection = fIndexManagerMap.values();
673 Iterator iterator = collection.iterator();
674 IdentifierIndexManager indexManager = null;
675 while (iterator.hasNext()) {
676 indexManager = (IdentifierIndexManager) iterator.next();
677 indexManager.writeFile();
679 if (fImageDescriptorRegistry != null)
680 fImageDescriptorRegistry.dispose();
681 // unregisterAdapters();
683 if (fWorkingCopyManager != null) {
684 fWorkingCopyManager.shutdown();
685 fWorkingCopyManager = null;
687 if (fCompilationUnitDocumentProvider != null) {
688 fCompilationUnitDocumentProvider.shutdown();
689 fCompilationUnitDocumentProvider = null;
691 if (fJavaTextTools != null) {
692 fJavaTextTools.dispose();
693 fJavaTextTools = null;
695 // JavaDocLocations.shutdownJavadocLocations();
697 // JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
698 // begin JavaCore#shutdown()
699 //savePluginPreferences();
700 savePluginPreferences();
701 IWorkspace workspace = ResourcesPlugin.getWorkspace();
702 workspace.removeResourceChangeListener(JavaModelManager
703 .getJavaModelManager().deltaProcessor);
704 workspace.removeSaveParticipant(PHPeclipsePlugin.getDefault());
705 ((JavaModelManager) JavaModelManager.getJavaModelManager()).shutdown();
706 // end JavaCore#shutdown()
708 public void startup() throws CoreException {
710 // begin JavaCore.startup();
711 JavaModelManager manager = JavaModelManager.getJavaModelManager();
713 manager.configurePluginDebugOptions();
714 // request state folder creation (workaround 19885)
715 // JavaCore.getPlugin().getStateLocation();
717 // retrieve variable values
718 // JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new
719 // JavaModelManager.PluginPreferencesListener());
720 getPluginPreferences().addPropertyChangeListener(
721 new JavaModelManager.PluginPreferencesListener());
722 // TODO khartlage temp-del
723 // manager.loadVariablesAndContainers();
724 IWorkspace workspace = ResourcesPlugin.getWorkspace();
725 workspace.addResourceChangeListener(manager.deltaProcessor,
726 IResourceChangeEvent.PRE_AUTO_BUILD
727 | IResourceChangeEvent.POST_AUTO_BUILD
728 | IResourceChangeEvent.POST_CHANGE
729 | IResourceChangeEvent.PRE_DELETE
730 | IResourceChangeEvent.PRE_CLOSE);
732 workspace.addSaveParticipant(PHPeclipsePlugin.getDefault(), manager);
733 } catch (CoreException e) {
734 } catch (RuntimeException e) {
738 // end JavaCore.startup();
739 IAdapterManager platformManager = Platform.getAdapterManager();
740 platformManager.registerAdapters(new PHPElementAdapterFactory(),
742 platformManager.registerAdapters(new ResourceAdapterFactory(),
744 // externalTools.startUp();
745 getStandardDisplay().asyncExec(new Runnable() {
747 //initialize the variable context manager
748 VariableContextManager.getDefault();