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.IStatus;
58 import org.eclipse.core.runtime.Path;
59 import org.eclipse.core.runtime.Platform;
60 import org.eclipse.core.runtime.Status;
61 import org.eclipse.jface.action.GroupMarker;
62 import org.eclipse.jface.action.IMenuManager;
63 import org.eclipse.jface.action.Separator;
64 import org.eclipse.jface.preference.IPreferenceStore;
65 import org.eclipse.jface.preference.PreferenceConverter;
66 import org.eclipse.jface.text.BadLocationException;
67 import org.eclipse.jface.text.IDocument;
68 import org.eclipse.swt.widgets.Display;
69 import org.eclipse.swt.widgets.Shell;
70 import org.eclipse.ui.IEditorDescriptor;
71 import org.eclipse.ui.IEditorInput;
72 import org.eclipse.ui.IEditorPart;
73 import org.eclipse.ui.IEditorRegistry;
74 import org.eclipse.ui.IWorkbench;
75 import org.eclipse.ui.IWorkbenchPage;
76 import org.eclipse.ui.IWorkbenchWindow;
77 import org.eclipse.ui.PlatformUI;
78 import org.eclipse.ui.ide.IDE;
79 import org.eclipse.ui.plugin.AbstractUIPlugin;
80 import org.eclipse.ui.texteditor.IDocumentProvider;
81 import org.eclipse.ui.texteditor.ITextEditor;
83 * The main plugin class to be used in the desktop.
85 public class PHPeclipsePlugin extends AbstractUIPlugin
87 IPreferenceConstants {
89 * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
91 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse"; //$NON-NLS-1$
93 * id of builder - matches plugin.xml (concatenate pluginid.builderid)
95 public static final String BUILDER_PARSER_ID = PLUGIN_ID + ".parserbuilder";
96 //public static final String BUILDER_INDEX_ID = PLUGIN_ID + ".indexbuilder";
97 /** General debug flag */
98 public static final boolean DEBUG = false;
100 * The maximum number of allowed proposals by category
102 public final static int MAX_PROPOSALS = 200;
103 private static ExternalToolsPlugin externalTools;
105 * The Java virtual machine that we are running on.
107 private static int jvm;
109 private static final int MRJ_2_0 = 0;
110 /** MRJ 2.1 or later */
111 private static final int MRJ_2_1 = 1;
112 /** Java on Mac OS X 10.0 (MRJ 3.0) */
113 private static final int MRJ_3_0 = 3;
115 private static final int MRJ_3_1 = 4;
116 /** JVM constant for any other platform */
117 private static final int OTHER = -1;
118 // public static final String PHP_RESOURCES_VIEW_ID = PLUGIN_ID +
119 // ".resourcesview.ViewPHPResources"; //$NON-NLS-1$
120 public static final String PHP_CODING_ACTION_SET_ID = PLUGIN_ID
121 + ".ui.CodingActionSet"; //$NON-NLS-1$
122 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
123 public static final String PHPPARSER_ORIGINAL = "net.sourceforge.phpdt.internal.compiler.parser.Parser";
124 public static final String PHPPARSER_NEW = "test.PHPParser";
125 /** Change this if you want to switch PHP Parser. */
126 public static final String PHPPARSER = PHPPARSER_ORIGINAL;
127 //The shared instance.
128 private static PHPeclipsePlugin plugin;
130 private static final int WINDOWS_9x = 6;
132 private static final int WINDOWS_NT = 5;
133 private ImageDescriptorRegistry fImageDescriptorRegistry;
134 private HashMap fIndexManagerMap = new HashMap();
135 private IWorkingCopyManager fWorkingCopyManager;
136 private PHPDocumentProvider fCompilationUnitDocumentProvider;
137 private JavaTextTools fJavaTextTools;
138 private ProblemMarkerManager fProblemMarkerManager;
139 private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
140 private IFile fLastEditorFile = null;
141 private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
145 public PHPeclipsePlugin(IPluginDescriptor descriptor) {
149 externalTools = new ExternalToolsPlugin();
152 // ResourceBundle.getBundle("net.sourceforge.PHPeclipsePluginResources");
153 // } catch (MissingResourceException x) {
154 // resourceBundle = null;
158 * Returns all Java editor text hovers contributed to the workbench.
160 * @return an array of JavaEditorTextHoverDescriptor
163 public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
164 if (fJavaEditorTextHoverDescriptors == null)
165 fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
166 .getContributedHovers();
167 return fJavaEditorTextHoverDescriptors;
170 * Resets the Java editor text hovers contributed to the workbench.
172 * This will force a rebuild of the descriptors the next time a client asks
176 * @return an array of JavaEditorTextHoverDescriptor
179 public void resetJavaEditorTextHoverDescriptors() {
180 fJavaEditorTextHoverDescriptors = null;
183 * Creates the PHP plugin standard groups in a context menu.
185 public static void createStandardGroups(IMenuManager menu) {
188 menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
189 menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
190 menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
191 menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
192 menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
193 menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
194 menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
195 menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
196 menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
197 menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
198 menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
200 public static IWorkbenchPage getActivePage() {
201 return getDefault().internalGetActivePage();
203 public static Shell getActiveWorkbenchShell() {
204 return getActiveWorkbenchWindow().getShell();
207 * Returns an array of all editors that have an unsaved content. If the
208 * identical content is presented in more than one editor, only one of those
209 * editor parts is part of the result.
211 * @return an array of all dirty editor parts.
213 public static IEditorPart[] getDirtyEditors() {
214 Set inputs = new HashSet();
215 List result = new ArrayList(0);
216 IWorkbench workbench = getDefault().getWorkbench();
217 IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
218 for (int i = 0; i < windows.length; i++) {
219 IWorkbenchPage[] pages = windows[i].getPages();
220 for (int x = 0; x < pages.length; x++) {
221 IEditorPart[] editors = pages[x].getDirtyEditors();
222 for (int z = 0; z < editors.length; z++) {
223 IEditorPart ep = editors[z];
224 IEditorInput input = ep.getEditorInput();
225 if (!inputs.contains(input)) {
232 return (IEditorPart[]) result.toArray(new IEditorPart[result.size()]);
234 public static IWorkbenchWindow getActiveWorkbenchWindow() {
235 return getDefault().getWorkbench().getActiveWorkbenchWindow();
238 * Returns the shared instance.
240 public static PHPeclipsePlugin getDefault() {
243 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
244 return getDefault().internalGetImageDescriptorRegistry();
246 static IPath getInstallLocation() {
247 return new Path(getDefault().getDescriptor().getInstallURL().getFile());
249 public static int getJVM() {
252 public static String getPluginId() {
253 return getDefault().getDescriptor().getUniqueIdentifier();
256 * Returns the standard display to be used. The method first checks, if the
257 * thread calling this method has an associated display. If so, this display
258 * is returned. Otherwise the method returns the default display.
260 public static Display getStandardDisplay() {
261 Display display = Display.getCurrent();
262 if (display == null) {
263 display = Display.getDefault();
267 // public static ExternalToolsPlugin getExternalTools() {
268 // return externalTools;
271 * Returns the workspace instance.
273 public static IWorkspace getWorkspace() {
274 return ResourcesPlugin.getWorkspace();
276 public static boolean isDebug() {
277 return getDefault().isDebugging();
279 // public static void logErrorMessage(String message) {
280 // log(new Status(IStatus.ERROR, getPluginId(),
281 // JavaStatusConstants.INTERNAL_ERROR, message, null));
284 // public static void logErrorStatus(String message, IStatus status) {
285 // if (status == null) {
286 // logErrorMessage(message);
289 // MultiStatus multi= new MultiStatus(getPluginId(),
290 // JavaStatusConstants.INTERNAL_ERROR, message, null);
291 // multi.add(status);
295 // public static void log(Throwable e) {
296 // log(new Status(IStatus.ERROR, getPluginId(),
297 // JavaStatusConstants.INTERNAL_ERROR,
298 // JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
300 public static void log(int severity, String message) {
301 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message, null);
304 public static void log(IStatus status) {
305 getDefault().getLog().log(status);
307 public static void log(Throwable e) {
308 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR,
309 "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
311 private static void setJVM() {
312 String osName = System.getProperty("os.name");
313 if (osName.startsWith("Mac OS")) {
314 String mrjVersion = System.getProperty("mrj.version");
315 String majorMRJVersion = mrjVersion.substring(0, 3);
318 double version = Double.valueOf(majorMRJVersion).doubleValue();
321 } else if (version >= 2.1 && version < 3) {
323 } else if (version == 3.0) {
325 } else if (version >= 3.1) {
328 } catch (NumberFormatException nfe) {
330 } else if (osName.startsWith("Windows")) {
331 if (osName.indexOf("9") != -1) {
338 // TODO: refactor this into a better method name !
339 public synchronized PHPDocumentProvider getCompilationUnitDocumentProvider() {
340 if (fCompilationUnitDocumentProvider == null)
341 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
342 return fCompilationUnitDocumentProvider;
345 * Get the identifier index manager for the given project
348 * the current project
351 public IdentifierIndexManager getIndexManager(IProject iProject) {
352 String indexFilename = iProject.getLocation() + File.separator
354 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap
356 if (indexManager == null) {
357 indexManager = new IdentifierIndexManager(indexFilename);
358 fIndexManagerMap.put(indexFilename, indexManager);
362 public synchronized IWorkingCopyManager getWorkingCopyManager() {
363 if (fWorkingCopyManager == null) {
364 PHPDocumentProvider provider = getCompilationUnitDocumentProvider();
365 fWorkingCopyManager = new WorkingCopyManager(provider);
367 return fWorkingCopyManager;
369 public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
370 if (fMembersOrderPreferenceCache == null)
371 fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
372 return fMembersOrderPreferenceCache;
374 public synchronized ProblemMarkerManager getProblemMarkerManager() {
375 if (fProblemMarkerManager == null)
376 fProblemMarkerManager = new ProblemMarkerManager();
377 return fProblemMarkerManager;
379 public synchronized JavaTextTools getJavaTextTools() {
380 if (fJavaTextTools == null)
381 fJavaTextTools = new JavaTextTools(getPreferenceStore());
382 return fJavaTextTools;
384 public IFile getLastEditorFile() {
385 return fLastEditorFile;
388 * Returns the string from the plugin's resource bundle, or 'key' if not
391 // public static String getResourceString(String key) {
392 // ResourceBundle bundle = PHPeclipsePlugin.getDefault().getResourceBundle();
394 // return bundle.getString(key);
395 // } catch (MissingResourceException e) {
400 * Returns the plugin's resource bundle,
402 // public ResourceBundle getResourceBundle() {
403 // return resourceBundle;
405 protected void initializeDefaultPreferences(IPreferenceStore store) {
406 // windows preferences:
407 store.setDefault(LOCALHOST_PREF, "http://localhost");
408 store.setDefault(SHOW_EXTERNAL_PREVIEW_PREF, "true");
409 store.setDefault(USE_EXTERNAL_BROWSER_PREF, "false");
410 store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
411 String windowsSystem = BootLoader.getWS();
412 if (jvm == WINDOWS_9x) {
413 store.setDefault(EXTERNAL_BROWSER_PREF,
414 "command.com /c start iexplore {0}");
415 } else if (windowsSystem.equals(BootLoader.WS_WIN32)) {
416 store.setDefault(EXTERNAL_BROWSER_PREF,
417 "rundll32 url.dll,FileProtocolHandler {0}");
418 } else if (windowsSystem.equals(BootLoader.WS_CARBON)) {
419 // TODO How do we start Safari on Mac OS X ?
420 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
422 store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}");
424 store.setDefault(DOCUMENTROOT_PREF, getWorkspace().getRoot().getLocation()
426 // if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) {
428 if (windowsSystem.equals(BootLoader.WS_WIN32)) {
429 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
430 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
431 store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
432 store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
434 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
435 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
436 store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
437 store.setDefault(APACHE_RUN_PREF, "/apache/apache");
439 store.setDefault(MYSQL_PREF, "--standalone");
440 store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
441 store.setDefault(APACHE_STOP_PREF, "-k shutdown");
442 store.setDefault(APACHE_RESTART_PREF, "-k restart");
443 store.setDefault(MYSQL_START_BACKGROUND, "true");
444 store.setDefault(APACHE_START_BACKGROUND, "true");
445 store.setDefault(APACHE_STOP_BACKGROUND, "true");
446 store.setDefault(APACHE_RESTART_BACKGROUND, "true");
447 store.setDefault(PHP_PARSER_DEFAULT, PHP_EXTERNAL_PARSER);
448 store.setDefault(PHP_INTERNAL_PARSER, "false");
449 store.setDefault(PHP_EXTERNAL_PARSER, "true");
450 // store.setDefault(PHP_PARSE_ON_SAVE, "true");
451 // show line numbers:
452 // store.setDefault(LINE_NUMBER_RULER, "false");
453 // store.setDefault(FORMATTER_TAB_SIZE, "4");
454 // php syntax highlighting
455 store.setDefault(PHP_USERDEF_XMLFILE, "");
456 //assume there is none chooA
457 PreferenceConverter.setDefault(store, PHP_MULTILINE_COMMENT,
458 PHPColorProvider.MULTI_LINE_COMMENT);
459 PreferenceConverter.setDefault(store, PHP_SINGLELINE_COMMENT,
460 PHPColorProvider.SINGLE_LINE_COMMENT);
461 PreferenceConverter.setDefault(store, PHP_TAG, PHPColorProvider.TAG);
463 .setDefault(store, PHP_KEYWORD, PHPColorProvider.KEYWORD);
464 PreferenceConverter.setDefault(store, PHP_VARIABLE,
465 PHPColorProvider.VARIABLE);
466 PreferenceConverter.setDefault(store, PHP_FUNCTIONNAME,
467 PHPColorProvider.FUNCTION_NAME);
468 PreferenceConverter.setDefault(store, PHP_CONSTANT,
469 PHPColorProvider.CONSTANT);
470 PreferenceConverter.setDefault(store, PHP_TYPE, PHPColorProvider.TYPE);
471 PreferenceConverter.setDefault(store, PHP_STRING, PHPColorProvider.STRING);
473 .setDefault(store, PHP_DEFAULT, PHPColorProvider.DEFAULT);
474 PreferenceConverter.setDefault(store, PHPDOC_KEYWORD,
475 PHPColorProvider.PHPDOC_KEYWORD);
476 PreferenceConverter.setDefault(store, PHPDOC_TAG,
477 PHPColorProvider.PHPDOC_TAG);
478 PreferenceConverter.setDefault(store, PHPDOC_LINK,
479 PHPColorProvider.PHPDOC_LINK);
480 PreferenceConverter.setDefault(store, PHPDOC_DEFAULT,
481 PHPColorProvider.PHPDOC_DEFAULT);
482 // PreferenceConverter.setDefault(
484 // PHP_EDITOR_BACKGROUND,
485 // PHPColorProvider.BACKGROUND);
486 // PreferenceConverter.setDefault(
488 // LINKED_POSITION_COLOR,
489 // PHPColorProvider.LINKED_POSITION_COLOR);
490 // PreferenceConverter.setDefault(
492 // LINE_NUMBER_COLOR,
493 // PHPColorProvider.LINE_NUMBER_COLOR);
494 // // set default PHPDoc colors:
495 // PreferenceConverter.setDefault(
498 // PHPColorProvider.PHPDOC_KEYWORD);
499 // PreferenceConverter.setDefault(
502 // PHPColorProvider.PHPDOC_LINK);
503 // PreferenceConverter.setDefault(
506 // PHPColorProvider.PHPDOC_DEFAULT);
507 // PreferenceConverter.setDefault(
510 // PHPColorProvider.PHPDOC_TAG);
511 // store.setDefault(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, "true");
512 // PreferenceConverter.setDefault(
514 // PREFERENCE_COLOR_BACKGROUND,
515 // PHPColorProvider.BACKGROUND_COLOR);
517 // store.setDefault(RESOURCE_BUNDLE, LANGUAGE_DEFAULT);
518 // store.setDefault(RESOURCE_BUNDLE_EN_GB, "true");
519 // store.setDefault(RESOURCE_BUNDLE_DE, "false");
520 // store.setDefault(RESOURCE_BUNDLE_FR, "false");
521 // store.setDefault(RESOURCE_BUNDLE_ES, "false");
522 store.setDefault(PHP_OUTLINE_CLASS, "true"); //$NON-NLS-1$
523 store.setDefault(PHP_OUTLINE_FUNC, "true"); //$NON-NLS-1$
524 store.setDefault(PHP_OUTLINE_VAR, "true"); //$NON-NLS-1$
525 TemplatePreferencePage.initDefaults(store);
526 //this will initialize the static fields in the syntaxrdr class
528 JavaCore.initializeDefaultPluginPreferences();
529 PreferenceConstants.initializeDefaultValues(store);
530 externalTools.initializeDefaultPreferences(store);
532 private IWorkbenchPage internalGetActivePage() {
533 IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
535 return window.getActivePage();
538 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
539 if (fImageDescriptorRegistry == null)
540 fImageDescriptorRegistry = new ImageDescriptorRegistry();
541 return fImageDescriptorRegistry;
544 * Open a file in the Workbench that may or may not exist in the workspace.
545 * Must be run on the UI thread.
548 * @throws CoreException
550 public ITextEditor openFileInTextEditor(String filename) throws CoreException {
551 // reject directories
552 if (new File(filename).isDirectory())
554 IWorkbench workbench = PlatformUI.getWorkbench();
555 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
556 IWorkbenchPage page = window.getActivePage();
557 IPath path = new Path(filename);
558 // If the file exists in the workspace, open it
559 IFile file = getWorkspace().getRoot().getFileForLocation(path);
561 ITextEditor textEditor;
562 if (file != null && file.exists()) {
563 editor = IDE.openEditor(page, file, true);
564 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
566 // Otherwise open the stream directly
569 FileStorage storage = new FileStorage(path);
570 IEditorRegistry registry = getWorkbench().getEditorRegistry();
571 IEditorDescriptor desc = registry.getDefaultEditor(filename);
573 desc = registry.getDefaultEditor();
575 IEditorInput input = new ExternalEditorInput(storage);
576 editor = page.openEditor(input, desc.getId());
577 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
578 // If the storage provider is not ours, we can't guarantee read/write.
579 if (textEditor != null) {
580 IDocumentProvider documentProvider = textEditor.getDocumentProvider();
581 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
582 storage.setReadOnly();
589 * Open a file in the Workbench that may or may not exist in the workspace.
590 * Must be run on the UI thread.
594 * @throws CoreException
596 public void openFileAndGotoLine(String filename, int line)
597 throws CoreException {
598 ITextEditor textEditor = openFileInTextEditor(filename);
599 if (textEditor != null) {
600 // If a line number was given, go to it
603 line--; // document is 0 based
604 IDocument document = textEditor.getDocumentProvider().getDocument(
605 textEditor.getEditorInput());
606 textEditor.selectAndReveal(document.getLineOffset(line), document
607 .getLineLength(line));
608 } catch (BadLocationException e) {
609 // invalid text position -> do nothing
615 * Open a file in the Workbench that may or may not exist in the workspace.
616 * Must be run on the UI thread.
620 * @throws CoreException
622 public void openFileAndGotoOffset(String filename, int offset, int length)
623 throws CoreException {
624 ITextEditor textEditor = openFileInTextEditor(filename);
625 if (textEditor != null) {
626 // If a line number was given, go to it
628 IDocument document = textEditor.getDocumentProvider().getDocument(
629 textEditor.getEditorInput());
630 textEditor.selectAndReveal(offset, length);
634 public void openFileAndFindString(String filename, String findString)
635 throws CoreException {
636 ITextEditor textEditor = openFileInTextEditor(filename);
637 if (textEditor != null) {
638 // If a string was given, go to it
639 if (findString != null) {
641 IDocument document = textEditor.getDocumentProvider().getDocument(
642 textEditor.getEditorInput());
643 int offset = document.search(0, findString, true, false, true);
644 textEditor.selectAndReveal(offset, findString.length());
645 } catch (BadLocationException e) {
646 // invalid text position -> do nothing
651 public void setLastEditorFile(IFile textEditor) {
652 this.fLastEditorFile = textEditor;
655 * @see org.eclipse.ui.plugin.AbstractUIPlugin#shutdown()
657 public void shutdown() throws CoreException {
658 // moved down (see below):
660 // externalTools.shutDown();
661 ColorManager.getDefault().dispose();
662 // save the information from the php index files if necessary
663 Collection collection = fIndexManagerMap.values();
664 Iterator iterator = collection.iterator();
665 IdentifierIndexManager indexManager = null;
666 while (iterator.hasNext()) {
667 indexManager = (IdentifierIndexManager) iterator.next();
668 indexManager.writeFile();
670 if (fImageDescriptorRegistry != null)
671 fImageDescriptorRegistry.dispose();
672 // unregisterAdapters();
674 if (fWorkingCopyManager != null) {
675 fWorkingCopyManager.shutdown();
676 fWorkingCopyManager = null;
678 if (fCompilationUnitDocumentProvider != null) {
679 fCompilationUnitDocumentProvider.shutdown();
680 fCompilationUnitDocumentProvider = null;
682 if (fJavaTextTools != null) {
683 fJavaTextTools.dispose();
684 fJavaTextTools = null;
686 // JavaDocLocations.shutdownJavadocLocations();
688 // JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
689 // begin JavaCore#shutdown()
690 //savePluginPreferences();
691 savePluginPreferences();
692 IWorkspace workspace = ResourcesPlugin.getWorkspace();
693 workspace.removeResourceChangeListener(JavaModelManager
694 .getJavaModelManager().deltaProcessor);
695 workspace.removeSaveParticipant(PHPeclipsePlugin.getDefault());
696 ((JavaModelManager) JavaModelManager.getJavaModelManager()).shutdown();
697 // end JavaCore#shutdown()
699 public void startup() throws CoreException {
701 // begin JavaCore.startup();
702 JavaModelManager manager = JavaModelManager.getJavaModelManager();
704 manager.configurePluginDebugOptions();
705 // request state folder creation (workaround 19885)
706 // JavaCore.getPlugin().getStateLocation();
708 // retrieve variable values
709 // JavaCore.getPlugin().getPluginPreferences().addPropertyChangeListener(new
710 // JavaModelManager.PluginPreferencesListener());
711 getPluginPreferences().addPropertyChangeListener(
712 new JavaModelManager.PluginPreferencesListener());
713 // TODO khartlage temp-del
714 // manager.loadVariablesAndContainers();
715 IWorkspace workspace = ResourcesPlugin.getWorkspace();
716 workspace.addResourceChangeListener(manager.deltaProcessor,
717 IResourceChangeEvent.PRE_AUTO_BUILD
718 | IResourceChangeEvent.POST_AUTO_BUILD
719 | IResourceChangeEvent.POST_CHANGE
720 | IResourceChangeEvent.PRE_DELETE
721 | IResourceChangeEvent.PRE_CLOSE);
723 workspace.addSaveParticipant(PHPeclipsePlugin.getDefault(), manager);
724 } catch (CoreException e) {
725 } catch (RuntimeException e) {
729 // end JavaCore.startup();
730 IAdapterManager platformManager = Platform.getAdapterManager();
731 platformManager.registerAdapters(new PHPElementAdapterFactory(),
733 platformManager.registerAdapters(new ResourceAdapterFactory(),
735 // externalTools.startUp();
736 getStandardDisplay().asyncExec(new Runnable() {
738 //initialize the variable context manager
739 VariableContextManager.getDefault();