2 * Copyright (c) 2004 Christopher Lenz 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 * Christopher Lenz - initial implementation
11 * $Id: WebUI.java,v 1.11 2007-11-08 01:37:06 scorphus Exp $
14 package net.sourceforge.phpeclipse.ui;
16 import org.eclipse.jface.resource.JFaceResources;
18 import java.io.IOException;
19 //import java.io.InputStream;
21 //import java.util.Enumeration;
22 import java.util.HashMap;
23 //import java.util.PropertyResourceBundle;
25 //import net.sourceforge.phpdt.core.JavaCore;
26 import net.sourceforge.phpdt.core.IBuffer;
27 import net.sourceforge.phpdt.core.ICompilationUnit;
28 import net.sourceforge.phpdt.core.IJavaElement;
29 import net.sourceforge.phpdt.core.WorkingCopyOwner;
30 import net.sourceforge.phpdt.internal.core.JavaModelManager;
31 import net.sourceforge.phpdt.internal.core.util.Util;
32 import net.sourceforge.phpdt.internal.corext.template.php.CodeTemplateContextType;
33 import net.sourceforge.phpdt.internal.corext.template.php.HTMLContextType;
34 import net.sourceforge.phpdt.internal.corext.template.php.JavaContextType;
35 import net.sourceforge.phpdt.internal.corext.template.php.JavaDocContextType;
36 import net.sourceforge.phpdt.internal.ui.IJavaStatusConstants;
37 import net.sourceforge.phpdt.internal.ui.JavaElementAdapterFactory;
38 import net.sourceforge.phpdt.internal.ui.ResourceAdapterFactory;
39 import net.sourceforge.phpdt.internal.ui.preferences.MembersOrderPreferenceCache;
40 import net.sourceforge.phpdt.internal.ui.preferences.MockupPreferenceStore;
41 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
42 import net.sourceforge.phpdt.internal.ui.text.folding.JavaFoldingStructureProviderRegistry;
43 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
44 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
45 import net.sourceforge.phpdt.internal.ui.viewsupport.ProblemMarkerManager;
46 import net.sourceforge.phpdt.ui.IContextMenuConstants;
47 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
48 import net.sourceforge.phpdt.ui.text.JavaTextTools;
49 import net.sourceforge.phpdt.ui.PreferenceConstants;
50 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
51 import net.sourceforge.phpeclipse.builder.ExternalEditorInput;
52 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
53 import net.sourceforge.phpeclipse.builder.FileStorage;
54 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
55 import net.sourceforge.phpeclipse.phpeditor.DocumentAdapter;
56 import net.sourceforge.phpeclipse.phpeditor.ICompilationUnitDocumentProvider;
57 import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
58 //import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
59 import net.sourceforge.phpeclipse.phpeditor.WorkingCopyManager;
60 //import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
63 import net.sourceforge.phpeclipse.ui.templates.template.HTMLTemplateContextType;
64 //import net.sourceforge.phpdt.internal.corext.template.php.HTMLContextType;
66 import net.sourceforge.phpeclipse.ui.templates.template.JSTemplateContextType;
67 import net.sourceforge.phpeclipse.ui.templates.template.SmartyTemplateContextType;
68 import net.sourceforge.phpeclipse.ui.templates.template.XMLTemplateContextType;
70 import org.eclipse.core.resources.IFile;
71 import org.eclipse.core.resources.IProject;
72 import org.eclipse.core.resources.IResource;
73 import org.eclipse.core.resources.IResourceChangeEvent;
74 import org.eclipse.core.resources.ISavedState;
75 import org.eclipse.core.resources.IWorkspace;
76 import org.eclipse.core.resources.ResourcesPlugin;
77 import org.eclipse.core.resources.WorkspaceJob;
78 import org.eclipse.core.runtime.CoreException;
79 import org.eclipse.core.runtime.IAdapterManager;
80 import org.eclipse.core.runtime.IConfigurationElement;
81 import org.eclipse.core.runtime.IPath;
82 import org.eclipse.core.runtime.IProgressMonitor;
83 import org.eclipse.core.runtime.IStatus;
84 import org.eclipse.core.runtime.Path;
85 import org.eclipse.core.runtime.Platform;
86 //import org.eclipse.core.runtime.Platform;
87 import org.eclipse.core.runtime.Status;
88 import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
89 import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
90 import org.eclipse.core.runtime.jobs.Job;
91 import org.eclipse.jface.action.GroupMarker;
92 import org.eclipse.jface.action.IMenuManager;
93 import org.eclipse.jface.action.Separator;
94 import org.eclipse.jface.preference.IPreferenceStore;
95 import org.eclipse.jface.preference.PreferenceConverter;
96 //import org.eclipse.jface.preference.PreferenceConverter;
97 import org.eclipse.jface.resource.ImageDescriptor;
98 import org.eclipse.jface.resource.ImageRegistry;
99 //import org.eclipse.jface.resource.JFaceResources;
100 import org.eclipse.jface.text.BadLocationException;
101 import org.eclipse.jface.text.IDocument;
102 import org.eclipse.jface.text.templates.ContextTypeRegistry;
103 import org.eclipse.jface.text.templates.persistence.TemplateStore;
104 //import org.eclipse.swt.graphics.RGB;
105 import org.eclipse.swt.widgets.Shell;
106 import org.eclipse.ui.IEditorDescriptor;
107 import org.eclipse.ui.IEditorInput;
108 import org.eclipse.ui.IEditorPart;
109 import org.eclipse.ui.IEditorRegistry;
110 import org.eclipse.ui.IWorkbench;
111 import org.eclipse.ui.IWorkbenchPage;
112 import org.eclipse.ui.IWorkbenchWindow;
113 import org.eclipse.ui.PlatformUI;
114 import org.eclipse.ui.editors.text.EditorsUI;
115 import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
116 import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
117 import org.eclipse.ui.ide.IDE;
118 import org.eclipse.ui.plugin.AbstractUIPlugin;
119 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
120 import org.eclipse.ui.texteditor.ConfigurationElementSorter;
121 import org.eclipse.ui.texteditor.IDocumentProvider;
122 import org.eclipse.ui.texteditor.ITextEditor;
123 import org.osgi.framework.BundleContext;
126 * The web development tools UI plugin.
128 public class WebUI extends AbstractUIPlugin implements IPreferenceConstants {
130 public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.ui";
132 public static final String EDITOR_ID = WebUI.PLUGIN_ID + ".PHPUnitEditor";
134 private static final String CUSTOM_TEMPLATES_KEY = "net.sourceforge.phpeclipse.ui.templates"; //$NON-NLS-1$
137 * The key to store customized code templates.
141 private static final String CODE_TEMPLATES_KEY = "net.sourceforge.phpdt.ui.text.custom_code_templates"; //$NON-NLS-1$
143 * The maximum number of allowed proposals by category
145 public final static int MAX_PROPOSALS = 200;
147 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
149 // Constants ---------------------------------------------------------------
151 public static final String ICON_OVERLAY_ERROR = "full/ovr16/error_co.gif"; //$NON-NLS-1$
153 public static final String ICON_OVERLAY_WARNING = "full/ovr16/warning_co.gif"; //$NON-NLS-1$
155 // Instance Variables ------------------------------------------------------
157 /** The shared instance. */
158 private static WebUI plugin;
161 * The combined preference store.
165 private IPreferenceStore fCombinedPreferenceStore;
168 * The coded template store for the java editor.
172 private TemplateStore fCodeTemplateStore;
175 * The code template context type registry for the java editor.
179 private ContextTypeRegistry fCodeTemplateContextTypeRegistry;
182 * The template context type registry for the java editor.
186 private ContextTypeRegistry fContextTypeRegistry;
188 private ResourceAdapterFactory fResourceAdapterFactory;
190 private JavaElementAdapterFactory fJavaElementAdapterFactory;
192 private ICompilationUnitDocumentProvider fCompilationUnitDocumentProvider;
194 private JavaTextTools fJavaTextTools;
196 private IWorkingCopyManager fWorkingCopyManager;
198 private IPropertyChangeListener fFontPropertyChangeListener;
200 private ProblemMarkerManager fProblemMarkerManager;
202 private MockupPreferenceStore fMockupPreferenceStore;
204 private ImageDescriptorRegistry fImageDescriptorRegistry;
206 private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
208 private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
210 private HashMap fIndexManagerMap = new HashMap();
213 * The extension point registry for the
214 * <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code>
219 private JavaFoldingStructureProviderRegistry fFoldingStructureProviderRegistry;
221 public static IWorkbenchPage getActivePage() {
222 return getDefault().internalGetActivePage();
225 private IWorkbenchPage internalGetActivePage() {
226 return getWorkbench().getActiveWorkbenchWindow().getActivePage();
229 public static Shell getActiveWorkbenchShell() {
230 return getActiveWorkbenchWindow().getShell();
233 public static IWorkbenchWindow getActiveWorkbenchWindow() {
234 return getDefault().getWorkbench().getActiveWorkbenchWindow();
237 // Public Methods ----------------------------------------------------------
240 * Returns the shared instance.
242 public static WebUI getDefault() {
247 * Returns the workspace instance.
249 public static IWorkspace getWorkspace() {
250 return ResourcesPlugin.getWorkspace();
253 /** The context type registry. */
254 private ContributionContextTypeRegistry fRegistry;
256 /** The template store. */
257 private TemplateStore fStore;
259 // Constructors ------------------------------------------------------------
269 * Returns this plug-in's context type registry.
271 * @return the context type registry for this plug-in instance
273 public ContextTypeRegistry getContextTypeRegistry() {
274 if (fRegistry == null) {
275 // create an configure the contexts available in the editor
276 fRegistry = new ContributionContextTypeRegistry();
277 fRegistry.addContextType(XMLTemplateContextType.XML_CONTEXT_TYPE);
278 fRegistry.addContextType(HTMLTemplateContextType.HTML_CONTEXT_TYPE);
279 fRegistry.addContextType(SmartyTemplateContextType.SMARTY_CONTEXT_TYPE);
280 fRegistry.addContextType(JSTemplateContextType.JS_CONTEXT_TYPE);
285 // Private Methods ---------------------------------------------------------
288 * Returns an image descriptor for the image corresponding to the specified
289 * key (which is the name of the image file).
292 * The key of the image
293 * @return The descriptor for the requested image, or <code>null</code> if
294 * the image could not be found
296 private ImageDescriptor getImageDescriptor(String key) {
298 URL url = getBundle().getEntry("/icons/" + key); //$NON-NLS-1$
299 return ImageDescriptor.createFromURL(url);
300 } catch (IllegalStateException e) {
306 * Returns this plug-in's template store.
308 * @return the template store of this plug-in instance
310 public TemplateStore getTemplateStore() {
311 if (fStore == null) {
312 fStore = new ContributionTemplateStore(getContextTypeRegistry(),
313 getDefault().getPreferenceStore(), CUSTOM_TEMPLATES_KEY);
316 } catch (IOException e) {
323 "net.sourceforge.phpeclipse.ui", IStatus.OK, "", e)); //$NON-NLS-1$ //$NON-NLS-2$
330 * @see AbstractUIPlugin#initializeImageRegistry(ImageRegistry)
332 protected void initializeImageRegistry(ImageRegistry reg) {
333 reg.put(ICON_OVERLAY_ERROR, getImageDescriptor(ICON_OVERLAY_ERROR));
334 reg.put(ICON_OVERLAY_WARNING, getImageDescriptor(ICON_OVERLAY_WARNING));
337 // private IWorkbenchPage internalGetActivePage() {
338 // IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
339 // if (window != null)
340 // return window.getActivePage();
344 public static void log(IStatus status) {
345 getDefault().getLog().log(status);
348 public static void log(Throwable e) {
349 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, ""
350 + e.getLocalizedMessage(), e));
353 public static String getPluginId() {
354 return getDefault().getBundle().getSymbolicName();
358 * Returns a combined preference store, this store is read-only.
360 * @return the combined preference store
364 public IPreferenceStore getCombinedPreferenceStore() {
365 if (fCombinedPreferenceStore == null) {
366 IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
367 fCombinedPreferenceStore = new ChainedPreferenceStore(
368 new IPreferenceStore[] {
369 getPreferenceStore(),
370 new PreferencesAdapter(WebUI
371 .getDefault().getPluginPreferences()),
374 return fCombinedPreferenceStore;
377 // TODO: refactor this into a better method name !
378 public synchronized ICompilationUnitDocumentProvider getCompilationUnitDocumentProvider() {
379 if (fCompilationUnitDocumentProvider == null)
380 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
381 return fCompilationUnitDocumentProvider;
384 public synchronized JavaTextTools getJavaTextTools() {
385 if (fJavaTextTools == null)
386 fJavaTextTools = new JavaTextTools(getPreferenceStore(), /*JavaCore
387 .getPlugin().*/getPluginPreferences());
388 return fJavaTextTools;
391 public synchronized IWorkingCopyManager getWorkingCopyManager() {
392 if (fWorkingCopyManager == null) {
393 ICompilationUnitDocumentProvider provider = getCompilationUnitDocumentProvider();
394 fWorkingCopyManager = new WorkingCopyManager(provider);
396 return fWorkingCopyManager;
399 public synchronized ProblemMarkerManager getProblemMarkerManager() {
400 if (fProblemMarkerManager == null)
401 fProblemMarkerManager = new ProblemMarkerManager();
402 return fProblemMarkerManager;
406 * Returns the mockup preference store for firing events and registering
407 * listeners on project setting changes. Temporary solution.
409 public MockupPreferenceStore getMockupPreferenceStore() {
410 if (fMockupPreferenceStore == null)
411 fMockupPreferenceStore = new MockupPreferenceStore();
413 return fMockupPreferenceStore;
416 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
417 return getDefault().internalGetImageDescriptorRegistry();
420 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
421 if (fImageDescriptorRegistry == null)
422 fImageDescriptorRegistry = new ImageDescriptorRegistry();
423 return fImageDescriptorRegistry;
427 * Returns the registry of the extensions to the
428 * <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code>
431 * @return the registry of contributed
432 * <code>IJavaFoldingStructureProvider</code>
435 public synchronized JavaFoldingStructureProviderRegistry getFoldingStructureProviderRegistry() {
436 if (fFoldingStructureProviderRegistry == null)
437 fFoldingStructureProviderRegistry = new JavaFoldingStructureProviderRegistry();
438 return fFoldingStructureProviderRegistry;
441 * Returns all Java editor text hovers contributed to the workbench.
443 * @return an array of JavaEditorTextHoverDescriptor
446 public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
447 if (fJavaEditorTextHoverDescriptors == null) {
448 fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
449 .getContributedHovers();
450 ConfigurationElementSorter sorter = new ConfigurationElementSorter() {
452 * @see org.eclipse.ui.texteditor.ConfigurationElementSorter#getConfigurationElement(java.lang.Object)
454 public IConfigurationElement getConfigurationElement(
456 return ((JavaEditorTextHoverDescriptor) object)
457 .getConfigurationElement();
460 sorter.sort(fJavaEditorTextHoverDescriptors);
462 // The Problem hover has to be the first and the Annotation hover
464 // be the last one in the JDT UI's hover list
465 int length = fJavaEditorTextHoverDescriptors.length;
467 int last = length - 1;
468 int problemHoverIndex = -1;
469 int annotationHoverIndex = -1;
470 for (int i = 0; i < length; i++) {
471 if (!fJavaEditorTextHoverDescriptors[i].getId().startsWith(
473 if (problemHoverIndex == -1 || annotationHoverIndex == -1)
483 if (fJavaEditorTextHoverDescriptors[i].getId().equals(
484 "net.sourceforge.phpdt.ui.AnnotationHover")) { //$NON-NLS-1$
485 annotationHoverIndex = i;
488 if (fJavaEditorTextHoverDescriptors[i].getId().equals(
489 "net.sourceforge.phpdt.ui.ProblemHover")) { //$NON-NLS-1$
490 problemHoverIndex = i;
495 JavaEditorTextHoverDescriptor hoverDescriptor = null;
497 if (first > -1 && problemHoverIndex > -1
498 && problemHoverIndex != first) {
499 // move problem hover to beginning
500 hoverDescriptor = fJavaEditorTextHoverDescriptors[first];
501 fJavaEditorTextHoverDescriptors[first] = fJavaEditorTextHoverDescriptors[problemHoverIndex];
502 fJavaEditorTextHoverDescriptors[problemHoverIndex] = hoverDescriptor;
504 // update annotation hover index if needed
505 if (annotationHoverIndex == first)
506 annotationHoverIndex = problemHoverIndex;
509 if (annotationHoverIndex > -1 && annotationHoverIndex != last) {
510 // move annotation hover to end
511 hoverDescriptor = fJavaEditorTextHoverDescriptors[last];
512 fJavaEditorTextHoverDescriptors[last] = fJavaEditorTextHoverDescriptors[annotationHoverIndex];
513 fJavaEditorTextHoverDescriptors[annotationHoverIndex] = hoverDescriptor;
516 // Move Best Match hover to front
517 for (int i = 0; i < fJavaEditorTextHoverDescriptors.length - 1; i++) {
518 if (PreferenceConstants.ID_BESTMATCH_HOVER
519 .equals(fJavaEditorTextHoverDescriptors[i].getId())) {
520 hoverDescriptor = fJavaEditorTextHoverDescriptors[i];
521 for (int j = i; j > 0; j--)
522 fJavaEditorTextHoverDescriptors[j] = fJavaEditorTextHoverDescriptors[j - 1];
523 fJavaEditorTextHoverDescriptors[0] = hoverDescriptor;
530 return fJavaEditorTextHoverDescriptors;
533 public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
534 if (fMembersOrderPreferenceCache == null)
535 fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
536 return fMembersOrderPreferenceCache;
539 * Open a file in the Workbench that may or may not exist in the workspace.
540 * Must be run on the UI thread.
543 * @throws CoreException
545 public ITextEditor openFileInTextEditor(String filename)
546 throws CoreException {
547 // reject directories
548 if (new File(filename).isDirectory())
550 IWorkbench workbench = PlatformUI.getWorkbench();
551 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
552 IWorkbenchPage page = window.getActivePage();
553 IPath path = new Path(filename);
554 // If the file exists in the workspace, open it
555 IFile file = getWorkspace().getRoot().getFile(path);
557 ITextEditor textEditor;
558 if (file != null && file.exists()) {
559 editor = IDE.openEditor(page, file, true);
560 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
562 // Otherwise open the stream directly
565 FileStorage storage = new FileStorage(path);
566 IEditorRegistry registry = getWorkbench().getEditorRegistry();
567 IEditorDescriptor desc = registry.getDefaultEditor(filename);
570 .findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
571 // desc = registry.getDefaultEditor();
573 IEditorInput input = new ExternalEditorInput(storage);
574 editor = page.openEditor(input, desc.getId());
575 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
576 // If the storage provider is not ours, we can't guarantee
578 if (textEditor != null) {
579 IDocumentProvider documentProvider = textEditor
580 .getDocumentProvider();
581 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
582 storage.setReadOnly();
589 * Creates the PHP plugin standard groups in a context menu.
591 public static void createStandardGroups(IMenuManager menu) {
594 menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
595 menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
596 menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
597 menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
598 menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
599 menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
600 menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
601 menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
602 menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
603 menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
604 menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
607 public IdentifierIndexManager getIndexManager(IProject iProject) {
608 IPath path = iProject.getWorkingLocation(/*WebUI*/PHPeclipsePlugin.PLUGIN_ID);
609 path = path.append("project.index");
610 String indexFilename = path.toString();
612 // IdentDB db = IdentDB.getInstance();
613 // } catch (ClassNotFoundException e) {
614 // e.printStackTrace();
615 // } catch (SQLException e) {
616 // e.printStackTrace();
618 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap
620 if (indexManager == null) {
621 indexManager = new IdentifierIndexManager(indexFilename);
622 fIndexManagerMap.put(indexFilename, indexManager);
628 * Returns the template store for the code generation templates.
630 * @return the template store for the code generation templates
633 public TemplateStore getCodeTemplateStore() {
634 if (fCodeTemplateStore == null) {
635 fCodeTemplateStore = new ContributionTemplateStore(
636 getCodeTemplateContextRegistry(), getPreferenceStore(),
639 fCodeTemplateStore.load();
640 } catch (IOException e) {
645 return fCodeTemplateStore;
648 * Returns the template context type registry for the code generation
651 * @return the template context type registry for the code generation
655 public ContextTypeRegistry getCodeTemplateContextRegistry() {
656 if (fCodeTemplateContextTypeRegistry == null) {
657 fCodeTemplateContextTypeRegistry = new ContributionContextTypeRegistry();
659 CodeTemplateContextType
660 .registerContextTypes(fCodeTemplateContextTypeRegistry);
663 return fCodeTemplateContextTypeRegistry;
666 public void openFileAndGotoOffset(String filename, int offset, int length)
667 throws CoreException {
668 ITextEditor textEditor = openFileInTextEditor(filename);
669 if (textEditor != null) {
670 // If a line number was given, go to it
672 IDocument document = textEditor.getDocumentProvider()
673 .getDocument(textEditor.getEditorInput());
674 textEditor.selectAndReveal(offset, length);
679 public void openFileAndFindString(String filename, String findString)
680 throws CoreException {
681 ITextEditor textEditor = openFileInTextEditor(filename);
682 if (textEditor != null) {
683 // If a string was given, go to it
684 if (findString != null) {
686 IDocument document = textEditor.getDocumentProvider()
687 .getDocument(textEditor.getEditorInput());
688 int offset = document.search(0, findString, true, false,
690 textEditor.selectAndReveal(offset, findString.length());
691 } catch (BadLocationException e) {
692 // invalid text position -> do nothing
698 public static void logErrorMessage(String message) {
699 log(new Status(IStatus.ERROR, getPluginId(),IJavaStatusConstants.INTERNAL_ERROR, message, null));
701 public static void log(int severity, String message) {
702 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message,
707 public static void log(String message, Throwable t) {
708 log(error(message, t));
710 public static IStatus error(Throwable t) {
711 return error("PHPeclipsePlugin.internalErrorOccurred", t); //$NON-NLS-1$
714 public static IStatus error(String message, Throwable t) {
715 return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, t);
719 * Resets the Java editor text hovers contributed to the workbench.
721 * This will force a rebuild of the descriptors the next time a client asks
725 * @return an array of JavaEditorTextHoverDescriptor
728 public void resetJavaEditorTextHoverDescriptors() {
729 fJavaEditorTextHoverDescriptors = null;
733 * Returns the template context type registry for the java plugin.
735 * @return the template context type registry for the java plugin
738 public ContextTypeRegistry getTemplateContextRegistry() {
739 if (fContextTypeRegistry == null) {
740 fContextTypeRegistry = new ContributionContextTypeRegistry();
742 fContextTypeRegistry.addContextType(new JavaContextType());
743 fContextTypeRegistry.addContextType(new JavaDocContextType());
744 fContextTypeRegistry.addContextType(new HTMLContextType());
747 return fContextTypeRegistry;
749 // public static void logErrorMessage(String message) {
750 // log(new Status(IStatus.ERROR, getPluginId(),
751 // JavaStatusConstants.INTERNAL_ERROR, message, null));
757 * (non - Javadoc) Method declared in Plugin
759 public void start(BundleContext context) throws Exception {
760 super.start(context);
762 // JavaCore.start(this, context);
763 final JavaModelManager modelManager = JavaModelManager
764 .getJavaModelManager();
766 modelManager.configurePluginDebugOptions();
768 // request state folder creation (workaround 19885)
770 // retrieve variable values
771 PHPeclipsePlugin.getDefault().getPluginPreferences()
772 .addPropertyChangeListener(
773 new JavaModelManager.PluginPreferencesListener());
774 // manager.loadVariablesAndContainers();
776 final IWorkspace workspace = ResourcesPlugin.getWorkspace();
777 workspace.addResourceChangeListener(modelManager.deltaState,
778 IResourceChangeEvent.PRE_BUILD
779 | IResourceChangeEvent.POST_BUILD
780 | IResourceChangeEvent.POST_CHANGE
781 | IResourceChangeEvent.PRE_DELETE
782 | IResourceChangeEvent.PRE_CLOSE);
784 ISavedState savedState = workspace.addSaveParticipant(
785 /*PHPeclipsePlugin*/WebUI.this, modelManager);
787 WorkspaceJob processSavedState = new WorkspaceJob(
788 Util.bind("savedState.jobName")) { //$NON-NLS-1$
789 public IStatus runInWorkspace(IProgressMonitor monitor)
790 throws CoreException {
791 ISavedState savedState = workspace.addSaveParticipant(
792 /*PHPeclipsePlugin*/WebUI.this, modelManager);
793 if (savedState != null) {
794 modelManager.deltaState.getDeltaProcessor().overridenEventType
795 = IResourceChangeEvent.POST_CHANGE;
796 savedState.processResourceChangeEvents(modelManager.deltaState);
798 return Status.OK_STATUS;
801 processSavedState.setSystem(true);
802 processSavedState.setPriority(Job.SHORT); // process asap
803 processSavedState.schedule();
804 } catch (RuntimeException e) {
805 modelManager.shutdown();
811 // if (USE_WORKING_COPY_OWNERS) {
812 WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
813 public IBuffer createBuffer(ICompilationUnit workingCopy) {
814 ICompilationUnit original = workingCopy.getPrimary();
815 IResource resource = original.getResource();
816 if (resource instanceof IFile)
817 return new DocumentAdapter(workingCopy, (IFile) resource);
818 return DocumentAdapter.NULL;
823 installPreferenceStoreBackwardsCompatibility();
828 private void registerAdapters() {
829 fJavaElementAdapterFactory = new JavaElementAdapterFactory();
830 fResourceAdapterFactory = new ResourceAdapterFactory();
832 IAdapterManager manager = Platform.getAdapterManager();
834 .registerAdapters(fJavaElementAdapterFactory,
836 manager.registerAdapters(fResourceAdapterFactory, IResource.class);
842 * Installs backwards compatibility for the preference store.
844 private void installPreferenceStoreBackwardsCompatibility() {
847 * Installs backwards compatibility: propagate the Java editor font from
848 * a pre-2.1 plug-in to the Platform UI's preference store to preserve
849 * the Java editor font from a pre-2.1 workspace. This is done only
852 String fontPropagatedKey = "fontPropagated"; //$NON-NLS-1$
853 if (getPreferenceStore().contains(JFaceResources.TEXT_FONT)
854 && !getPreferenceStore().isDefault(JFaceResources.TEXT_FONT)) {
855 if (!getPreferenceStore().getBoolean(fontPropagatedKey))
857 .setValue(PlatformUI.getWorkbench()
858 .getPreferenceStore(),
859 PreferenceConstants.EDITOR_TEXT_FONT,
860 PreferenceConverter.getFontDataArray(
861 getPreferenceStore(),
862 JFaceResources.TEXT_FONT));
864 getPreferenceStore().setValue(fontPropagatedKey, true);
867 * Backwards compatibility: set the Java editor font in this plug-in's
868 * preference store to let older versions access it. Since 2.1 the Java
869 * editor font is managed by the workbench font preference page.
871 PreferenceConverter.putValue(getPreferenceStore(),
872 JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry()
873 .getFontData(PreferenceConstants.EDITOR_TEXT_FONT));
875 fFontPropertyChangeListener = new IPropertyChangeListener() {
876 public void propertyChange(PropertyChangeEvent event) {
877 if (PreferenceConstants.EDITOR_TEXT_FONT.equals(event
879 PreferenceConverter.putValue(getPreferenceStore(),
880 JFaceResources.TEXT_FONT,
881 JFaceResources.getFontRegistry().getFontData(
882 PreferenceConstants.EDITOR_TEXT_FONT));
886 /*JFaceResources.getFontRegistry().addListener(
887 fFontPropertyChangeListener);*/