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.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";
136 * The key to store customized templates.
140 private static final String TEMPLATES_KEY = "net.sourceforge.phpdt.ui.text.custom_templates"; //$NON-NLS-1$
143 * The key to store customized code templates.
147 private static final String CODE_TEMPLATES_KEY = "net.sourceforge.phpdt.ui.text.custom_code_templates"; //$NON-NLS-1$
153 private static final String CUSTOM_TEMPLATES_KEY = "net.sourceforge.phpeclipse.ui.templates"; //$NON-NLS-1$
156 * The key to store customized code templates.
160 // private static final String CODE_TEMPLATES_KEY = "net.sourceforge.phpdt.ui.text.custom_code_templates"; //$NON-NLS-1$
162 * The maximum number of allowed proposals by category
164 public final static int MAX_PROPOSALS = 200;
166 public final static String PHP_NATURE_ID = PLUGIN_ID + ".phpnature";
168 // Constants ---------------------------------------------------------------
170 public static final String ICON_OVERLAY_ERROR = "full/ovr16/error_co.gif"; //$NON-NLS-1$
172 public static final String ICON_OVERLAY_WARNING = "full/ovr16/warning_co.gif"; //$NON-NLS-1$
174 // Instance Variables ------------------------------------------------------
176 /** The shared instance. */
177 private static WebUI plugin;
180 * The combined preference store.
184 private IPreferenceStore fCombinedPreferenceStore;
187 * The coded template store for the java editor.
191 private TemplateStore fCodeTemplateStore;
194 * The code template context type registry for the java editor.
198 private ContextTypeRegistry fCodeTemplateContextTypeRegistry;
201 * The template context type registry for the java editor.
205 private ContextTypeRegistry fContextTypeRegistry;
207 private ResourceAdapterFactory fResourceAdapterFactory;
209 private JavaElementAdapterFactory fJavaElementAdapterFactory;
211 private ICompilationUnitDocumentProvider fCompilationUnitDocumentProvider;
213 private JavaTextTools fJavaTextTools;
215 private IWorkingCopyManager fWorkingCopyManager;
217 private IPropertyChangeListener fFontPropertyChangeListener;
219 private ProblemMarkerManager fProblemMarkerManager;
221 private MockupPreferenceStore fMockupPreferenceStore;
223 private ImageDescriptorRegistry fImageDescriptorRegistry;
225 private JavaEditorTextHoverDescriptor[] fJavaEditorTextHoverDescriptors;
227 private MembersOrderPreferenceCache fMembersOrderPreferenceCache;
229 private HashMap fIndexManagerMap = new HashMap();
232 * The extension point registry for the
233 * <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code>
238 private JavaFoldingStructureProviderRegistry fFoldingStructureProviderRegistry;
240 public static IWorkbenchPage getActivePage() {
241 return getDefault().internalGetActivePage();
244 private IWorkbenchPage internalGetActivePage() {
245 return getWorkbench().getActiveWorkbenchWindow().getActivePage();
248 public static Shell getActiveWorkbenchShell() {
249 return getActiveWorkbenchWindow().getShell();
252 public static IWorkbenchWindow getActiveWorkbenchWindow() {
253 return getDefault().getWorkbench().getActiveWorkbenchWindow();
256 // Public Methods ----------------------------------------------------------
259 * Returns the shared instance.
261 public static WebUI getDefault() {
266 * Returns the workspace instance.
268 public static IWorkspace getWorkspace() {
269 return ResourcesPlugin.getWorkspace();
272 /** The context type registry. */
273 private ContributionContextTypeRegistry fRegistry;
275 /** The template store. */
276 private TemplateStore fStore;
278 // Constructors ------------------------------------------------------------
288 * Returns this plug-in's context type registry.
290 * @return the context type registry for this plug-in instance
292 public ContextTypeRegistry getContextTypeRegistry() {
293 if (fRegistry == null) {
294 // create an configure the contexts available in the editor
295 fRegistry = new ContributionContextTypeRegistry();
296 fRegistry.addContextType(XMLTemplateContextType.XML_CONTEXT_TYPE);
297 fRegistry.addContextType(HTMLTemplateContextType.HTML_CONTEXT_TYPE);
298 fRegistry.addContextType(SmartyTemplateContextType.SMARTY_CONTEXT_TYPE);
299 fRegistry.addContextType(JSTemplateContextType.JS_CONTEXT_TYPE);
304 // Private Methods ---------------------------------------------------------
307 * Returns an image descriptor for the image corresponding to the specified
308 * key (which is the name of the image file).
311 * The key of the image
312 * @return The descriptor for the requested image, or <code>null</code> if
313 * the image could not be found
315 private ImageDescriptor getImageDescriptor(String key) {
317 URL url = getBundle().getEntry("/icons/" + key); //$NON-NLS-1$
318 return ImageDescriptor.createFromURL(url);
319 } catch (IllegalStateException e) {
325 * Returns this plug-in's template store.
327 * @return the template store of this plug-in instance
329 public TemplateStore getTemplateStore() {
330 if (fStore == null) {
331 fStore = new ContributionTemplateStore(/*getContextTypeRegistry()*/getTemplateContextRegistry(),
332 getDefault().getPreferenceStore(), /*CUSTOM_*/TEMPLATES_KEY);
335 } catch (IOException e) {
342 "net.sourceforge.phpeclipse.ui", IStatus.OK, "", e)); //$NON-NLS-1$ //$NON-NLS-2$
349 * @see AbstractUIPlugin#initializeImageRegistry(ImageRegistry)
351 protected void initializeImageRegistry(ImageRegistry reg) {
352 reg.put(ICON_OVERLAY_ERROR, getImageDescriptor(ICON_OVERLAY_ERROR));
353 reg.put(ICON_OVERLAY_WARNING, getImageDescriptor(ICON_OVERLAY_WARNING));
356 // private IWorkbenchPage internalGetActivePage() {
357 // IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
358 // if (window != null)
359 // return window.getActivePage();
363 public static void log(IStatus status) {
364 getDefault().getLog().log(status);
367 public static void log(Throwable e) {
368 log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, ""
369 + e.getLocalizedMessage(), e));
372 public static String getPluginId() {
373 return getDefault().getBundle().getSymbolicName();
377 * Returns a combined preference store, this store is read-only.
379 * @return the combined preference store
383 public IPreferenceStore getCombinedPreferenceStore() {
384 if (fCombinedPreferenceStore == null) {
385 IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
386 fCombinedPreferenceStore = new ChainedPreferenceStore(
387 new IPreferenceStore[] {
388 getPreferenceStore(),
389 new PreferencesAdapter(WebUI
390 .getDefault().getPluginPreferences()),
393 return fCombinedPreferenceStore;
396 // TODO: refactor this into a better method name !
397 public synchronized ICompilationUnitDocumentProvider getCompilationUnitDocumentProvider() {
398 if (fCompilationUnitDocumentProvider == null)
399 fCompilationUnitDocumentProvider = new PHPDocumentProvider();
400 return fCompilationUnitDocumentProvider;
403 public synchronized JavaTextTools getJavaTextTools() {
404 if (fJavaTextTools == null)
405 fJavaTextTools = new JavaTextTools(getPreferenceStore(), /*JavaCore
406 .getPlugin().*/getPluginPreferences());
407 return fJavaTextTools;
410 public synchronized IWorkingCopyManager getWorkingCopyManager() {
411 if (fWorkingCopyManager == null) {
412 ICompilationUnitDocumentProvider provider = getCompilationUnitDocumentProvider();
413 fWorkingCopyManager = new WorkingCopyManager(provider);
415 return fWorkingCopyManager;
418 public synchronized ProblemMarkerManager getProblemMarkerManager() {
419 if (fProblemMarkerManager == null)
420 fProblemMarkerManager = new ProblemMarkerManager();
421 return fProblemMarkerManager;
425 * Returns the mockup preference store for firing events and registering
426 * listeners on project setting changes. Temporary solution.
428 public MockupPreferenceStore getMockupPreferenceStore() {
429 if (fMockupPreferenceStore == null)
430 fMockupPreferenceStore = new MockupPreferenceStore();
432 return fMockupPreferenceStore;
435 public static ImageDescriptorRegistry getImageDescriptorRegistry() {
436 return getDefault().internalGetImageDescriptorRegistry();
439 private ImageDescriptorRegistry internalGetImageDescriptorRegistry() {
440 if (fImageDescriptorRegistry == null)
441 fImageDescriptorRegistry = new ImageDescriptorRegistry();
442 return fImageDescriptorRegistry;
446 * Returns the registry of the extensions to the
447 * <code>net.sourceforge.phpdt.ui.javaFoldingStructureProvider</code>
450 * @return the registry of contributed
451 * <code>IJavaFoldingStructureProvider</code>
454 public synchronized JavaFoldingStructureProviderRegistry getFoldingStructureProviderRegistry() {
455 if (fFoldingStructureProviderRegistry == null)
456 fFoldingStructureProviderRegistry = new JavaFoldingStructureProviderRegistry();
457 return fFoldingStructureProviderRegistry;
460 * Returns all Java editor text hovers contributed to the workbench.
462 * @return an array of JavaEditorTextHoverDescriptor
465 public JavaEditorTextHoverDescriptor[] getJavaEditorTextHoverDescriptors() {
466 if (fJavaEditorTextHoverDescriptors == null) {
467 fJavaEditorTextHoverDescriptors = JavaEditorTextHoverDescriptor
468 .getContributedHovers();
469 ConfigurationElementSorter sorter = new ConfigurationElementSorter() {
471 * @see org.eclipse.ui.texteditor.ConfigurationElementSorter#getConfigurationElement(java.lang.Object)
473 public IConfigurationElement getConfigurationElement(
475 return ((JavaEditorTextHoverDescriptor) object)
476 .getConfigurationElement();
479 sorter.sort(fJavaEditorTextHoverDescriptors);
481 // The Problem hover has to be the first and the Annotation hover
483 // be the last one in the JDT UI's hover list
484 int length = fJavaEditorTextHoverDescriptors.length;
486 int last = length - 1;
487 int problemHoverIndex = -1;
488 int annotationHoverIndex = -1;
489 for (int i = 0; i < length; i++) {
490 if (!fJavaEditorTextHoverDescriptors[i].getId().startsWith(
492 if (problemHoverIndex == -1 || annotationHoverIndex == -1)
502 if (fJavaEditorTextHoverDescriptors[i].getId().equals(
503 "net.sourceforge.phpdt.ui.AnnotationHover")) { //$NON-NLS-1$
504 annotationHoverIndex = i;
507 if (fJavaEditorTextHoverDescriptors[i].getId().equals(
508 "net.sourceforge.phpdt.ui.ProblemHover")) { //$NON-NLS-1$
509 problemHoverIndex = i;
514 JavaEditorTextHoverDescriptor hoverDescriptor = null;
516 if (first > -1 && problemHoverIndex > -1
517 && problemHoverIndex != first) {
518 // move problem hover to beginning
519 hoverDescriptor = fJavaEditorTextHoverDescriptors[first];
520 fJavaEditorTextHoverDescriptors[first] = fJavaEditorTextHoverDescriptors[problemHoverIndex];
521 fJavaEditorTextHoverDescriptors[problemHoverIndex] = hoverDescriptor;
523 // update annotation hover index if needed
524 if (annotationHoverIndex == first)
525 annotationHoverIndex = problemHoverIndex;
528 if (annotationHoverIndex > -1 && annotationHoverIndex != last) {
529 // move annotation hover to end
530 hoverDescriptor = fJavaEditorTextHoverDescriptors[last];
531 fJavaEditorTextHoverDescriptors[last] = fJavaEditorTextHoverDescriptors[annotationHoverIndex];
532 fJavaEditorTextHoverDescriptors[annotationHoverIndex] = hoverDescriptor;
535 // Move Best Match hover to front
536 for (int i = 0; i < fJavaEditorTextHoverDescriptors.length - 1; i++) {
537 if (PreferenceConstants.ID_BESTMATCH_HOVER
538 .equals(fJavaEditorTextHoverDescriptors[i].getId())) {
539 hoverDescriptor = fJavaEditorTextHoverDescriptors[i];
540 for (int j = i; j > 0; j--)
541 fJavaEditorTextHoverDescriptors[j] = fJavaEditorTextHoverDescriptors[j - 1];
542 fJavaEditorTextHoverDescriptors[0] = hoverDescriptor;
549 return fJavaEditorTextHoverDescriptors;
552 public synchronized MembersOrderPreferenceCache getMemberOrderPreferenceCache() {
553 if (fMembersOrderPreferenceCache == null)
554 fMembersOrderPreferenceCache = new MembersOrderPreferenceCache();
555 return fMembersOrderPreferenceCache;
558 * Open a file in the Workbench that may or may not exist in the workspace.
559 * Must be run on the UI thread.
562 * @throws CoreException
564 public ITextEditor openFileInTextEditor(String filename)
565 throws CoreException {
566 // reject directories
567 if (new File(filename).isDirectory())
569 IWorkbench workbench = PlatformUI.getWorkbench();
570 IWorkbenchWindow window = workbench.getWorkbenchWindows()[0];
571 IWorkbenchPage page = window.getActivePage();
572 IPath path = new Path(filename);
573 // If the file exists in the workspace, open it
574 IFile file = getWorkspace().getRoot().getFile(path);
576 ITextEditor textEditor;
577 if (file != null && file.exists()) {
578 editor = IDE.openEditor(page, file, true);
579 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
581 // Otherwise open the stream directly
584 FileStorage storage = new FileStorage(path);
585 IEditorRegistry registry = getWorkbench().getEditorRegistry();
586 IEditorDescriptor desc = registry.getDefaultEditor(filename);
589 .findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
590 // desc = registry.getDefaultEditor();
592 IEditorInput input = new ExternalEditorInput(storage);
593 editor = page.openEditor(input, desc.getId());
594 textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
595 // If the storage provider is not ours, we can't guarantee
597 if (textEditor != null) {
598 IDocumentProvider documentProvider = textEditor
599 .getDocumentProvider();
600 if (!(documentProvider instanceof ExternalStorageDocumentProvider)) {
601 storage.setReadOnly();
608 * Creates the PHP plugin standard groups in a context menu.
610 public static void createStandardGroups(IMenuManager menu) {
613 menu.add(new Separator(IContextMenuConstants.GROUP_NEW));
614 menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO));
615 menu.add(new Separator(IContextMenuConstants.GROUP_OPEN));
616 menu.add(new GroupMarker(IContextMenuConstants.GROUP_SHOW));
617 menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE));
618 menu.add(new Separator(IContextMenuConstants.GROUP_GENERATE));
619 menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH));
620 menu.add(new Separator(IContextMenuConstants.GROUP_BUILD));
621 menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS));
622 menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP));
623 menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES));
626 public IdentifierIndexManager getIndexManager(IProject iProject) {
627 IPath path = iProject.getWorkingLocation(/*WebUI*/PHPeclipsePlugin.PLUGIN_ID);
628 path = path.append("project.index");
629 String indexFilename = path.toString();
631 // IdentDB db = IdentDB.getInstance();
632 // } catch (ClassNotFoundException e) {
633 // e.printStackTrace();
634 // } catch (SQLException e) {
635 // e.printStackTrace();
637 IdentifierIndexManager indexManager = (IdentifierIndexManager) fIndexManagerMap
639 if (indexManager == null) {
640 indexManager = new IdentifierIndexManager(indexFilename);
641 fIndexManagerMap.put(indexFilename, indexManager);
647 * Returns the template store for the code generation templates.
649 * @return the template store for the code generation templates
652 public TemplateStore getCodeTemplateStore() {
653 if (fCodeTemplateStore == null) {
654 fCodeTemplateStore = new ContributionTemplateStore(
655 getCodeTemplateContextRegistry(), getPreferenceStore(),
658 fCodeTemplateStore.load();
659 } catch (IOException e) {
664 return fCodeTemplateStore;
667 * Returns the template context type registry for the code generation
670 * @return the template context type registry for the code generation
674 public ContextTypeRegistry getCodeTemplateContextRegistry() {
675 if (fCodeTemplateContextTypeRegistry == null) {
676 fCodeTemplateContextTypeRegistry = new ContributionContextTypeRegistry();
678 CodeTemplateContextType
679 .registerContextTypes(fCodeTemplateContextTypeRegistry);
682 return fCodeTemplateContextTypeRegistry;
685 public void openFileAndGotoOffset(String filename, int offset, int length)
686 throws CoreException {
687 ITextEditor textEditor = openFileInTextEditor(filename);
688 if (textEditor != null) {
689 // If a line number was given, go to it
691 // IDocument document = textEditor.getDocumentProvider()
692 // .getDocument(textEditor.getEditorInput());
693 textEditor.selectAndReveal(offset, length);
698 public void openFileAndFindString(String filename, String findString)
699 throws CoreException {
700 ITextEditor textEditor = openFileInTextEditor(filename);
701 if (textEditor != null) {
702 // If a string was given, go to it
703 if (findString != null) {
705 IDocument document = textEditor.getDocumentProvider()
706 .getDocument(textEditor.getEditorInput());
707 int offset = document.search(0, findString, true, false,
709 textEditor.selectAndReveal(offset, findString.length());
710 } catch (BadLocationException e) {
711 // invalid text position -> do nothing
717 public static void logErrorMessage(String message) {
718 log(new Status(IStatus.ERROR, getPluginId(),IJavaStatusConstants.INTERNAL_ERROR, message, null));
720 public static void log(int severity, String message) {
721 Status status = new Status(severity, PLUGIN_ID, IStatus.OK, message,
726 public static void log(String message, Throwable t) {
727 log(error(message, t));
729 public static IStatus error(Throwable t) {
730 return error("PHPeclipsePlugin.internalErrorOccurred", t); //$NON-NLS-1$
733 public static IStatus error(String message, Throwable t) {
734 return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, t);
738 * Resets the Java editor text hovers contributed to the workbench.
740 * This will force a rebuild of the descriptors the next time a client asks
744 * @return an array of JavaEditorTextHoverDescriptor
747 public void resetJavaEditorTextHoverDescriptors() {
748 fJavaEditorTextHoverDescriptors = null;
752 * Returns the template context type registry for the java plugin.
754 * @return the template context type registry for the java plugin
757 public ContextTypeRegistry getTemplateContextRegistry() {
758 if (fContextTypeRegistry == null) {
759 fContextTypeRegistry = new ContributionContextTypeRegistry();
761 fContextTypeRegistry.addContextType(new JavaContextType());
762 fContextTypeRegistry.addContextType(new JavaDocContextType());
763 fContextTypeRegistry.addContextType(new HTMLContextType());
766 return fContextTypeRegistry;
768 // public static void logErrorMessage(String message) {
769 // log(new Status(IStatus.ERROR, getPluginId(),
770 // JavaStatusConstants.INTERNAL_ERROR, message, null));
776 * (non - Javadoc) Method declared in Plugin
778 public void start(BundleContext context) throws Exception {
779 super.start(context);
781 // JavaCore.start(this, context);
782 final JavaModelManager modelManager = JavaModelManager
783 .getJavaModelManager();
785 modelManager.configurePluginDebugOptions();
787 // request state folder creation (workaround 19885)
789 // retrieve variable values
790 PHPeclipsePlugin.getDefault().getPluginPreferences()
791 .addPropertyChangeListener(
792 new JavaModelManager.PluginPreferencesListener());
793 // manager.loadVariablesAndContainers();
795 final IWorkspace workspace = ResourcesPlugin.getWorkspace();
796 workspace.addResourceChangeListener(modelManager.deltaState,
797 IResourceChangeEvent.PRE_BUILD
798 | IResourceChangeEvent.POST_BUILD
799 | IResourceChangeEvent.POST_CHANGE
800 | IResourceChangeEvent.PRE_DELETE
801 | IResourceChangeEvent.PRE_CLOSE);
803 // ISavedState savedState = workspace.addSaveParticipant(
804 // /*PHPeclipsePlugin*/WebUI.this, modelManager);
806 WorkspaceJob processSavedState = new WorkspaceJob(
807 Util.bind("savedState.jobName")) { //$NON-NLS-1$
808 public IStatus runInWorkspace(IProgressMonitor monitor)
809 throws CoreException {
810 ISavedState savedState = workspace.addSaveParticipant(
811 /*PHPeclipsePlugin*/WebUI.this, modelManager);
812 if (savedState != null) {
813 modelManager.deltaState.getDeltaProcessor().overridenEventType
814 = IResourceChangeEvent.POST_CHANGE;
815 savedState.processResourceChangeEvents(modelManager.deltaState);
817 return Status.OK_STATUS;
820 processSavedState.setSystem(true);
821 processSavedState.setPriority(Job.SHORT); // process asap
822 processSavedState.schedule();
823 } catch (RuntimeException e) {
824 modelManager.shutdown();
830 // if (USE_WORKING_COPY_OWNERS) {
831 WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
832 public IBuffer createBuffer(ICompilationUnit workingCopy) {
833 ICompilationUnit original = workingCopy.getPrimary();
834 IResource resource = original.getResource();
835 if (resource instanceof IFile)
836 return new DocumentAdapter(workingCopy, (IFile) resource);
837 return DocumentAdapter.NULL;
842 installPreferenceStoreBackwardsCompatibility();
847 private void registerAdapters() {
848 fJavaElementAdapterFactory = new JavaElementAdapterFactory();
849 fResourceAdapterFactory = new ResourceAdapterFactory();
851 IAdapterManager manager = Platform.getAdapterManager();
853 .registerAdapters(fJavaElementAdapterFactory,
855 manager.registerAdapters(fResourceAdapterFactory, IResource.class);
861 * Installs backwards compatibility for the preference store.
863 private void installPreferenceStoreBackwardsCompatibility() {
866 * Installs backwards compatibility: propagate the Java editor font from
867 * a pre-2.1 plug-in to the Platform UI's preference store to preserve
868 * the Java editor font from a pre-2.1 workspace. This is done only
871 String fontPropagatedKey = "fontPropagated"; //$NON-NLS-1$
872 if (getPreferenceStore().contains(JFaceResources.TEXT_FONT)
873 && !getPreferenceStore().isDefault(JFaceResources.TEXT_FONT)) {
874 if (!getPreferenceStore().getBoolean(fontPropagatedKey))
876 .setValue(PlatformUI.getWorkbench()
877 .getPreferenceStore(),
878 PreferenceConstants.EDITOR_TEXT_FONT,
879 PreferenceConverter.getFontDataArray(
880 getPreferenceStore(),
881 JFaceResources.TEXT_FONT));
883 getPreferenceStore().setValue(fontPropagatedKey, true);
886 * Backwards compatibility: set the Java editor font in this plug-in's
887 * preference store to let older versions access it. Since 2.1 the Java
888 * editor font is managed by the workbench font preference page.
890 PreferenceConverter.putValue(getPreferenceStore(),
891 JFaceResources.TEXT_FONT, JFaceResources.getFontRegistry()
892 .getFontData(PreferenceConstants.EDITOR_TEXT_FONT));
894 fFontPropertyChangeListener = new IPropertyChangeListener() {
895 public void propertyChange(PropertyChangeEvent event) {
896 if (PreferenceConstants.EDITOR_TEXT_FONT.equals(event
898 PreferenceConverter.putValue(getPreferenceStore(),
899 JFaceResources.TEXT_FONT,
900 JFaceResources.getFontRegistry().getFontData(
901 PreferenceConstants.EDITOR_TEXT_FONT));
905 /*JFaceResources.getFontRegistry().addListener(
906 fFontPropertyChangeListener);*/