### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.workbench.texteditor Index: plugin.xml =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench.texteditor/plugin.xml,v retrieving revision 1.70 diff -u -r1.70 plugin.xml --- plugin.xml 6 Dec 2005 11:39:11 -0000 1.70 +++ plugin.xml 3 Feb 2006 19:34:32 -0000 @@ -4,7 +4,8 @@ - + + Index: plugin.properties =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench.texteditor/plugin.properties,v retrieving revision 1.32 diff -u -r1.32 plugin.properties --- plugin.properties 29 Apr 2005 07:39:22 -0000 1.32 +++ plugin.properties 3 Feb 2006 19:34:32 -0000 @@ -160,3 +160,4 @@ command.windowStart.name = Window Start SpellingEngine= Spelling Engine +HyperlinkDetectors= Hyperlink Detectors Index: src/org/eclipse/ui/texteditor/AbstractTextEditor.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java,v retrieving revision 1.190 diff -u -r1.190 AbstractTextEditor.java --- src/org/eclipse/ui/texteditor/AbstractTextEditor.java 24 Jan 2006 10:29:21 -0000 1.190 +++ src/org/eclipse/ui/texteditor/AbstractTextEditor.java 3 Feb 2006 19:34:33 -0000 @@ -17,6 +17,7 @@ import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -61,6 +62,9 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.ILog; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -162,7 +166,6 @@ import org.eclipse.ui.part.EditorActionBarContributor; import org.eclipse.ui.part.EditorPart; - /** * Abstract base implementation of a text editor. *

@@ -2559,6 +2562,7 @@ fSourceViewer.addTextInputListener(fTextListener); getSelectionProvider().addSelectionChangedListener(getSelectionChangedListener()); + initializeViewerHyperlinkDetectors(fSourceViewer); initializeViewerFont(fSourceViewer); initializeViewerColors(fSourceViewer); initializeFindScopeColor(fSourceViewer); @@ -5672,4 +5676,64 @@ return true; } + private HyperlinkDetectorExtensionReader fDetectorExtensionReader = new HyperlinkDetectorExtensionReader(); + + private IHyperlinkDetector[] fContributedHyperlinkDectors = null; + + private void initializeViewerHyperlinkDetectors(ISourceViewer sourceViewer) { + fDetectorExtensionReader.readHyperlinkDetectorsExtension(this); + if (fContributedHyperlinkDectors != null && fPreferenceStore.getBoolean(PREFERENCE_HYPERLINKS_ENABLED) + && fSourceViewer instanceof ITextViewerExtension6) { + + IHyperlinkDetector[] sourceViewerDetectors = getSourceViewerConfiguration().getHyperlinkDetectors(fSourceViewer); + int stateMask = getSourceViewerConfiguration().getHyperlinkStateMask(fSourceViewer); + ITextViewerExtension6 textViewer6 = (ITextViewerExtension6) fSourceViewer; + + List allDectors = new ArrayList(); + allDectors.addAll(Arrays.asList(sourceViewerDetectors)); + allDectors.addAll(Arrays.asList(fContributedHyperlinkDectors)); + textViewer6.setHyperlinkDetectors((IHyperlinkDetector[])allDectors.toArray(new IHyperlinkDetector[allDectors.size()]), stateMask); + } + } + + private final class HyperlinkDetectorExtensionReader { + + private List contributedDetectors = new ArrayList(); + + private boolean extensionsRead = false; + + public static final String EXTENSION_POINT_HYPERLINK_DETECTOR = "org.eclipse.ui.workbench.texteditor.hyperlinkDetectors"; + + public static final String ELEMENT_HYPERLINK_DETECTOR = "hyperlinkDetector"; + + public static final String ELEMENT_CLASS = "class"; + + private void readHyperlinkDetectorsExtension(ITextEditor textEditor) { + if (!extensionsRead) { + List contributedDectors = new ArrayList(); + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint extensionPoint = registry.getExtensionPoint(EXTENSION_POINT_HYPERLINK_DETECTOR); + IExtension[] extensions = extensionPoint.getExtensions(); + for (int i = 0; i < extensions.length; i++) { + IConfigurationElement[] elements = extensions[i].getConfigurationElements(); + for (int j = 0; j < elements.length; j++) { + if (elements[j].getName().compareTo(ELEMENT_HYPERLINK_DETECTOR) == 0) { + try { + Object detector = elements[j].createExecutableExtension(ELEMENT_CLASS); + if (detector instanceof AbstractHyperlinkDetector) { + ((AbstractHyperlinkDetector) detector).setEditor(textEditor); + contributedDectors.add(detector); + } + } catch (CoreException e) { + // TODO: handle once this goes where it belongs + throw new RuntimeException(e); + } + } + } + } + AbstractTextEditor.this.fContributedHyperlinkDectors = (IHyperlinkDetector[]) contributedDectors.toArray(new IHyperlinkDetector[contributedDectors.size()]); + extensionsRead = true; + } + } + } } Index: src/org/eclipse/ui/texteditor/AbstractHyperlinkDetector.java =================================================================== RCS file: src/org/eclipse/ui/texteditor/AbstractHyperlinkDetector.java diff -N src/org/eclipse/ui/texteditor/AbstractHyperlinkDetector.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/texteditor/AbstractHyperlinkDetector.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2006 University Of British Columbia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * University Of British Columbia - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ui.texteditor; + +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.hyperlink.IHyperlink; +import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; + +/** + * @author Mik Kersten + */ +public abstract class AbstractHyperlinkDetector implements IHyperlinkDetector { + + private ITextEditor fEditor; + + public abstract IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, + boolean canShowMultipleHyperlinks); + + public ITextEditor getEditor() { + return fEditor; + } + + public void setEditor(ITextEditor editor) { + this.fEditor = editor; + } +} Index: schema/hyperlinkDetectors.exsd =================================================================== RCS file: schema/hyperlinkDetectors.exsd diff -N schema/hyperlinkDetectors.exsd --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ schema/hyperlinkDetectors.exsd 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,122 @@ + + + + + + + + + This extension point is used to plug-in hyperlink detectors to a Java editor. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + + + + + + + + +