View | Details | Raw Unified | Return to bug 88293 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (-1 / +3 lines)
Lines 5-11 Link Here
5
    <extension-point id="quickDiffReferenceProvider" name="%ExtPoint.referenceProvider" schema="schema/quickDiffReferenceProvider.exsd"/>
5
    <extension-point id="quickDiffReferenceProvider" name="%ExtPoint.referenceProvider" schema="schema/quickDiffReferenceProvider.exsd"/>
6
	<extension-point id="spellingEngine" name="%SpellingEngine" schema="schema/spellingEngine.exsd"/>
6
	<extension-point id="spellingEngine" name="%SpellingEngine" schema="schema/spellingEngine.exsd"/>
7
    <extension-point id="rulerColumns" name="%ExtPoint.rulerColumns" schema="schema/rulerColumns.exsd"/>
7
    <extension-point id="rulerColumns" name="%ExtPoint.rulerColumns" schema="schema/rulerColumns.exsd"/>
8
	   
8
    <extension-point id="hyperlinkDetectors" name="%ExtPoint.hyperlinkDetectors" schema="schema/hyperlinkDetectors.exsd"/>
9
    <extension-point id="hyperlinkDetectorTargets" name="%ExtPoint.hyperlinkDetectorTargets" schema="schema/hyperlinkDetectorTargets.exsd"/>
10
9
	<extension
11
	<extension
10
	     point="org.eclipse.ui.commands">
12
	     point="org.eclipse.ui.commands">
11
	  <category
13
	  <category
(-)plugin.properties (+2 lines)
Lines 16-21 Link Here
16
16
17
ExtPoint.referenceProvider= Reference Provider
17
ExtPoint.referenceProvider= Reference Provider
18
ExtPoint.rulerColumns= Ruler Columns
18
ExtPoint.rulerColumns= Ruler Columns
19
ExtPoint.hyperlinkDetectors= Hyperlink Detectors
20
ExtPoint.hyperlinkDetectorTargets= Hyperlink Detector Targets
19
21
20
textEditorPresentationActionSet.label= Editor Presentation
22
textEditorPresentationActionSet.label= Editor Presentation
21
23
(-)src/org/eclipse/ui/internal/texteditor/EditorMessages.java (+5 lines)
Lines 25-30 Link Here
25
25
26
	public static String Editor_error_gotoLastEditPosition_title;
26
	public static String Editor_error_gotoLastEditPosition_title;
27
	public static String Editor_error_gotoLastEditPosition_message;
27
	public static String Editor_error_gotoLastEditPosition_message;
28
	public static String Editor_error_HyperlinkDetector_couldNotCreate_message;
29
	public static String Editor_error_HyperlinkDetector_invalidElementName_message;
30
	public static String Editor_error_HyperlinkDetector_invalidExtension_message;
31
	public static String Editor_error_HyperlinkDetectorTarget_invalidElementName_message;
32
	public static String Editor_error_HyperlinkDetectorTarget_invalidExtension_message;
28
33
29
	static {
34
	static {
30
		NLS.initializeMessages(BUNDLE_NAME, EditorMessages.class);
35
		NLS.initializeMessages(BUNDLE_NAME, EditorMessages.class);
(-)src/org/eclipse/ui/internal/texteditor/EditorMessages.properties (+5 lines)
Lines 14-16 Link Here
14
14
15
Editor_error_gotoLastEditPosition_title= Problems going to last edit position
15
Editor_error_gotoLastEditPosition_title= Problems going to last edit position
16
Editor_error_gotoLastEditPosition_message= Unable to go to the last edit position.
16
Editor_error_gotoLastEditPosition_message= Unable to go to the last edit position.
17
Editor_error_HyperlinkDetector_couldNotCreate_message= The ''{0}'' extension from plug-in ''{1}'' to the ''org.eclipse.ui.workbench.texteditor.hyperlinkDetectors'' extension point failed to load the hyperlink detector.
18
Editor_error_HyperlinkDetector_invalidElementName_message= An extension from plug-in ''{0}'' to the ''org.eclipse.ui.workbench.texteditor.hyperlinkDetectors'' extension point was ignored because it contains the following invalid element: ''{1}''.
19
Editor_error_HyperlinkDetector_invalidExtension_message= The ''{0}'' extension from plug-in ''{1}'' to the ''org.eclipse.ui.workbench.texteditor.hyperlinkDetectors'' extension point will be ignored because it contains invalid attributes.
20
Editor_error_HyperlinkDetectorTarget_invalidElementName_message= An extension from plug-in ''{0}'' to the ''org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets'' extension point was ignored because it contains the following invalid element: ''{1}''.
21
Editor_error_HyperlinkDetectorTarget_invalidExtension_message= The ''{0}'' extension from plug-in ''{1}'' to the ''org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets'' extension point will be ignored because it contains invalid attributes.
(-)schema/hyperlinkDetectors.exsd (+162 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.ui.workbench.texteditor">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.ui.workbench.texteditor" id="hyperlinkDetectors" name="Hyperlink Detectors"/>
7
      </appInfo>
8
      <documentation>
9
         This extension point is used to plug-in hyperlink detectors.
10
&lt;p&gt;
11
&lt;em&gt;This API is provisional and may change any time before the 3.3 API freeze.&lt;/em&gt;
12
&lt;/p&gt;
13
      </documentation>
14
   </annotation>
15
16
   <element name="extension">
17
      <complexType>
18
         <sequence>
19
            <element ref="hyperlinkDetector" minOccurs="1" maxOccurs="unbounded"/>
20
         </sequence>
21
         <attribute name="point" type="string" use="required">
22
            <annotation>
23
               <documentation>
24
                  a fully qualified identifier of the target extension point
25
               </documentation>
26
            </annotation>
27
         </attribute>
28
         <attribute name="id" type="string">
29
            <annotation>
30
               <documentation>
31
                  an optional identifier of the extension instance
32
               </documentation>
33
            </annotation>
34
         </attribute>
35
         <attribute name="name" type="string">
36
            <annotation>
37
               <documentation>
38
                  an optional name of the extension instance
39
               </documentation>
40
               <appInfo>
41
                  <meta.attribute translatable="true"/>
42
               </appInfo>
43
            </annotation>
44
         </attribute>
45
      </complexType>
46
   </element>
47
48
   <element name="hyperlinkDetector">
49
      <complexType>
50
         <attribute name="id" type="string" use="required">
51
            <annotation>
52
               <documentation>
53
                  a unique id that will be used to identify this hyperlink detector
54
               </documentation>
55
            </annotation>
56
         </attribute>
57
         <attribute name="name" type="string" use="required">
58
            <annotation>
59
               <documentation>
60
                  a name that allows to identify this hyperlink detector in the UI
61
               </documentation>
62
               <appInfo>
63
                  <meta.attribute translatable="true"/>
64
               </appInfo>
65
            </annotation>
66
         </attribute>
67
         <attribute name="description" type="string">
68
            <annotation>
69
               <documentation>
70
                  the translatable description for this hyperlink detector
71
               </documentation>
72
               <appInfo>
73
                  <meta.attribute translatable="true"/>
74
               </appInfo>
75
            </annotation>
76
         </attribute>
77
         <attribute name="targetId" type="string" use="required">
78
            <annotation>
79
               <documentation>
80
                  the id of the hyperlink target which has been registered via &lt;code&gt;org.eclipse.ui.workbench.texteditor.hyperlinkTargets&lt;/code&gt; extension point
81
               </documentation>
82
            </annotation>
83
         </attribute>
84
         <attribute name="class" type="string" use="required">
85
            <annotation>
86
               <documentation>
87
                  the fully qualified class name implementing the interface &lt;code&gt;org.eclipse.jface.text.hyperlink.IHyperlinkDetector&lt;/code&gt;
88
               </documentation>
89
               <appInfo>
90
                  <meta.attribute kind="java" basedOn="org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector"/>
91
               </appInfo>
92
            </annotation>
93
         </attribute>
94
         <attribute name="activate" type="boolean" use="default" value="true">
95
            <annotation>
96
               <documentation>
97
                  an attribute that tells whether to activate the contributing plug-in when hyperlink detection takes place in the given target
98
               </documentation>
99
            </annotation>
100
         </attribute>
101
      </complexType>
102
   </element>
103
104
   <annotation>
105
      <appInfo>
106
         <meta.section type="examples"/>
107
      </appInfo>
108
      <documentation>
109
         The following is an example of a hyperlink detector definition:
110
111
&lt;pre&gt;
112
&lt;extension
113
  point=&quot;org.eclipse.ui.workbench.texteditor&quot;&gt;
114
  &lt;hyperlinkDetector
115
    id=&quot;org.eclipse.example.jdt.internal.debug.ui.JavaHyperlinkDetector&quot;
116
    targetId=&quot;org.eclipse.jdt.ui.javaCode&quot;
117
    class=&quot;org.eclipse.example.jdt.internal.debug.ui.JavaHyperlinkDetector&quot;
118
    name=&quot;%javaHyperlinkDetector&quot;/&gt;
119
  &lt;/hyperlinkDetector&gt;
120
&lt;/extension&gt;
121
&lt;/pre&gt;
122
      </documentation>
123
   </annotation>
124
125
   <annotation>
126
      <appInfo>
127
         <meta.section type="apiInfo"/>
128
      </appInfo>
129
      <documentation>
130
         
131
      </documentation>
132
   </annotation>
133
134
   <annotation>
135
      <appInfo>
136
         <meta.section type="since"/>
137
      </appInfo>
138
      <documentation>
139
         3.3
140
      </documentation>
141
   </annotation>
142
143
   <annotation>
144
      <appInfo>
145
         <meta.section type="implementation"/>
146
      </appInfo>
147
      <documentation>
148
         
149
      </documentation>
150
   </annotation>
151
152
   <annotation>
153
      <appInfo>
154
         <meta.section type="copyright"/>
155
      </appInfo>
156
      <documentation>
157
         Copyright (c) 2007 IBM Corporation and others.&lt;br&gt;
158
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 &lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
159
      </documentation>
160
   </annotation>
161
162
</schema>
(-)src/org/eclipse/ui/texteditor/HyperlinkDetectorRegistry.java (+129 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.texteditor;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IAdaptable;
19
20
import org.eclipse.jface.text.IRegion;
21
import org.eclipse.jface.text.ITextViewer;
22
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
23
import org.eclipse.jface.text.hyperlink.IHyperlink;
24
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
25
import org.eclipse.jface.text.hyperlink.IHyperlinkDetectorExtension;
26
27
import org.eclipse.ui.internal.texteditor.HyperlinkDetectorDescriptor;
28
29
30
/**
31
 * Hyperlink detector registry that manages the detectors
32
 * contributed by the <code>org.eclipse.ui.workbench.texteditor.hyperlinkDetectors</code> extension point for
33
 * targets contributed by the <code>org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets</code> extension point.
34
 * <p>
35
 * <em>This API is provisional and may change any time before the 3.3 API freeze.</em>
36
 * </p>
37
 * 
38
 *  FIXME: must take a preference store to disable detectors via preference page
39
 * 
40
 * @since 3.3
41
 */
42
public class HyperlinkDetectorRegistry {
43
	
44
	/**
45
	 * Delegate for contributed hyperlink detectors.
46
	 */
47
	private static class HyperlinkDetectorDelegate implements IHyperlinkDetector, IHyperlinkDetectorExtension {
48
		
49
		private HyperlinkDetectorDescriptor fHyperlinkDescriptor;
50
		private AbstractHyperlinkDetector fHyperlinkDetector;
51
		private boolean fFailedDuringCreation= false;
52
		private IAdaptable fContext;
53
54
		
55
		private HyperlinkDetectorDelegate(HyperlinkDetectorDescriptor descriptor) {
56
			fHyperlinkDescriptor= descriptor;
57
		}
58
59
		/*
60
		 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
61
		 */
62
		public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
63
			if (fHyperlinkDetector == null && !fFailedDuringCreation) {
64
				try {
65
					fHyperlinkDetector= fHyperlinkDescriptor.createHyperlinkDetector();
66
				} catch (CoreException ex) {
67
					fFailedDuringCreation= true;
68
				}
69
				if (fHyperlinkDetector != null && fContext != null)
70
					fHyperlinkDetector.setContext(fContext);
71
			}
72
			if (fHyperlinkDetector != null)
73
				return fHyperlinkDetector.detectHyperlinks(textViewer, region, canShowMultipleHyperlinks);
74
			
75
			return null;
76
		}
77
		
78
		private void setContext(IAdaptable context) {
79
			fContext= context;
80
		}
81
		
82
		/*
83
		 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetectorExtension#dispose()
84
		 */
85
		public void dispose() {
86
			if (fHyperlinkDetector != null) {
87
				fHyperlinkDetector.dispose();
88
				fHyperlinkDetector= null;
89
			}
90
			fHyperlinkDescriptor= null;
91
			fContext= null;
92
		}
93
		
94
	}
95
96
	
97
	
98
	private HyperlinkDetectorDescriptor[] fHyperlinkDetectorDescriptors;
99
	
100
	
101
	/**
102
	 * Returns all Java editor text hovers contributed to the workbench.
103
	 * 
104
	 * @return an array of hyperlink detector descriptors
105
	 */
106
	public synchronized HyperlinkDetectorDescriptor[] getHyperlinkDetectorDescriptors() {
107
		if (fHyperlinkDetectorDescriptors == null)
108
			fHyperlinkDetectorDescriptors= HyperlinkDetectorDescriptor.getContributedHyperlinkDetectors();
109
		return fHyperlinkDetectorDescriptors;
110
	} 
111
112
	/*
113
	 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetectorRegistry#createHyperlinkDetectors(java.lang.String[], org.eclipse.core.runtime.IAdaptable)
114
	 */
115
	public IHyperlinkDetector[] createHyperlinkDetectors(String targetId, IAdaptable context) {
116
		Assert.isLegal(targetId != null);
117
		
118
		List result= new ArrayList();
119
		for (int i= 0; i < getHyperlinkDetectorDescriptors().length; i++) {
120
			if (targetId.equals(getHyperlinkDetectorDescriptors()[i].getTargetId())) {
121
				HyperlinkDetectorDelegate detector= new HyperlinkDetectorDelegate(getHyperlinkDetectorDescriptors()[i]);
122
				result.add(detector);
123
				detector.setContext(context);
124
			}
125
		}
126
		return (IHyperlinkDetector[])result.toArray(new IHyperlinkDetector[result.size()]);
127
	}
128
129
}
(-)src/org/eclipse/ui/internal/texteditor/HyperlinkDetectorDescriptor.java (+203 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.internal.texteditor;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import org.osgi.framework.Bundle;
18
19
import org.eclipse.core.runtime.Assert;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IConfigurationElement;
22
import org.eclipse.core.runtime.IExtensionRegistry;
23
import org.eclipse.core.runtime.ISafeRunnable;
24
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.Platform;
26
import org.eclipse.core.runtime.SafeRunner;
27
import org.eclipse.core.runtime.Status;
28
29
import org.eclipse.jface.util.SafeRunnable;
30
31
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
32
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
33
34
/**
35
 * Describes a contribution to the 'org.eclipse.ui.workbench.texteditor.hyperlinkDetectors'
36
 * extension point.
37
 *
38
 * @since 3.3
39
 */
40
public class HyperlinkDetectorDescriptor {
41
42
	private static final String HYPERLINK_DETECTORS_EXTENSION_POINT= "org.eclipse.ui.workbench.texteditor.hyperlinkDetectors"; //$NON-NLS-1$
43
	private static final String HYPERLINK_DETECTOR_ELEMENT= "hyperlinkDetector"; //$NON-NLS-1$
44
	private static final String ID_ATTRIBUTE= "id"; //$NON-NLS-1$
45
	private static final String NAME_ATTRIBUTE= "name"; //$NON-NLS-1$
46
	private static final String DESCRIPTION_ATTRIBUTE= "description"; //$NON-NLS-1$
47
	private static final String TARGET_ID_ATTRIBUTE= "targetId"; //$NON-NLS-1$
48
	private static final String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$
49
	private static final String ACTIVATE_PLUG_IN_ATTRIBUTE= "activate"; //$NON-NLS-1$
50
51
	private IConfigurationElement fElement;
52
53
54
	/**
55
	 * Returns descriptors for all hyperlink detector extensions.
56
	 *
57
	 * @return an array with the contributed hyperlink detectors
58
	 */
59
	public static HyperlinkDetectorDescriptor[] getContributedHyperlinkDetectors() {
60
		IExtensionRegistry registry= Platform.getExtensionRegistry();
61
		IConfigurationElement[] elements= registry.getConfigurationElementsFor(HYPERLINK_DETECTORS_EXTENSION_POINT);
62
		HyperlinkDetectorDescriptor[] hyperlinkDetectorDescs= createDescriptors(elements);
63
		return hyperlinkDetectorDescs;
64
	}
65
66
	/**
67
	 * Creates a new descriptor from the given configuration element.
68
	 * 
69
	 * @param element the configuration element 
70
	 */
71
	private HyperlinkDetectorDescriptor(IConfigurationElement element) {
72
		Assert.isNotNull(element);
73
		fElement= element;
74
	}
75
76
	/**
77
	 * Creates a new {@link IHyperlinkDetector}.
78
	 * 
79
	 * @return the hyperlink detector or <code>null</code> if the plug-in isn't loaded yet 
80
	 * @throws CoreException if a failure occurred during creation
81
	 */
82
	public AbstractHyperlinkDetector createHyperlinkDetector() throws CoreException {
83
		final Throwable[] exception= new Throwable[1];
84
		final AbstractHyperlinkDetector[] result= new AbstractHyperlinkDetector[1];
85
		String message= NLSUtility.format(EditorMessages.Editor_error_HyperlinkDetector_couldNotCreate_message, new String[] { getId(), fElement.getContributor().getName() }); 
86
		ISafeRunnable code= new SafeRunnable(message) {
87
			/*
88
			 * @see org.eclipse.core.runtime.ISafeRunnable#run()
89
			 */
90
			public void run() throws Exception {
91
		 		String pluginId = fElement.getContributor().getName();
92
				boolean isPlugInActivated= Platform.getBundle(pluginId).getState() == Bundle.ACTIVE;
93
				if (isPlugInActivated || canActivatePlugIn())
94
					result[0]= (AbstractHyperlinkDetector)fElement.createExecutableExtension(CLASS_ATTRIBUTE);
95
			}
96
			/*
97
			 * @see org.eclipse.jface.util.SafeRunnable#handleException(java.lang.Throwable)
98
			 */
99
			public void handleException(Throwable ex) {
100
				super.handleException(ex);
101
				exception[0]= ex;
102
			}
103
			
104
		};
105
		
106
		SafeRunner.run(code);
107
		
108
		if (exception[0] == null)
109
			return result[0];
110
		throw new CoreException(new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, IStatus.OK, message, exception[0]));
111
		
112
	}
113
	
114
	private boolean isValid(HyperlinkDetectorTargetDescriptor[] targets) {
115
		if (getId() == null || getName() == null || getTargetId() == null)
116
			return false;
117
118
		String targetId= getTargetId();
119
		for (int i= 0; i < targets.length; i++) {
120
			if (targetId.equals(targets[i].getId()))
121
				return true;
122
		}
123
		return false;
124
125
	}
126
127
	//---- XML Attribute accessors ---------------------------------------------
128
129
	/**
130
	 * Returns the hyperlink detector's id.
131
	 * 
132
	 * @return the hyperlink detector's id 
133
	 */
134
	public String getId() {
135
		return fElement.getAttribute(ID_ATTRIBUTE);
136
	}
137
138
	/**
139
	 * Returns the hyperlink detector's name.
140
	 * 
141
	 * @return the hyperlink detector's name 
142
	 */
143
	public String getName() {
144
		return fElement.getAttribute(NAME_ATTRIBUTE);
145
	}
146
	
147
	/**
148
	 * Returns the hyperlink detector's target id.
149
	 * 
150
	 * @return the hyperlink detector's target id 
151
	 */
152
	public String getTargetId() {
153
		return fElement.getAttribute(TARGET_ID_ATTRIBUTE);
154
	}
155
156
	/**
157
	 * Returns the hyperlink detector's description.
158
	 *
159
	 * @return the hyperlink detector's description or <code>null</code> if not provided
160
	 */
161
	public String getDescription() {
162
		return fElement.getAttribute(DESCRIPTION_ATTRIBUTE);
163
	}
164
165
	public boolean canActivatePlugIn() {
166
		String value= fElement.getAttribute(ACTIVATE_PLUG_IN_ATTRIBUTE);
167
		if (value == null)
168
			return true;
169
		return Boolean.valueOf(value).booleanValue();
170
	}
171
172
	public boolean equals(Object obj) {
173
		if (obj == null || !obj.getClass().equals(this.getClass()) || getId() == null)
174
			return false;
175
		return getId().equals(((HyperlinkDetectorDescriptor)obj).getId());
176
	}
177
178
	public int hashCode() {
179
		return getId().hashCode();
180
	}
181
182
	private static HyperlinkDetectorDescriptor[] createDescriptors(IConfigurationElement[] elements) {
183
		HyperlinkDetectorTargetDescriptor[] targets= HyperlinkDetectorTargetDescriptor.getContributedHyperlinkDetectorTargets();
184
		List result= new ArrayList(elements.length);
185
		for (int i= 0; i < elements.length; i++) {
186
			IConfigurationElement element= elements[i];
187
			if (HYPERLINK_DETECTOR_ELEMENT.equals(element.getName())) {
188
				HyperlinkDetectorDescriptor desc= new HyperlinkDetectorDescriptor(element);
189
				if (desc.isValid(targets))
190
					result.add(desc);
191
				else {
192
					String message= NLSUtility.format(EditorMessages.Editor_error_HyperlinkDetector_invalidExtension_message, new String[] {desc.getId(), element.getContributor().getName()});
193
					TextEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, IStatus.OK, message, null));
194
				}
195
			} else {
196
				String message= NLSUtility.format(EditorMessages.Editor_error_HyperlinkDetector_invalidElementName_message, new String[] { element.getContributor().getName(), element.getName() });
197
				TextEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, IStatus.OK, message, null));
198
			}
199
		}
200
		return (HyperlinkDetectorDescriptor[])result.toArray(new HyperlinkDetectorDescriptor[result.size()]);
201
	}
202
203
}
(-)src/org/eclipse/ui/internal/texteditor/HyperlinkDetectorTargetDescriptor.java (+144 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.internal.texteditor;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.core.runtime.IConfigurationElement;
19
import org.eclipse.core.runtime.IExtensionRegistry;
20
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.core.runtime.Status;
23
24
/**
25
 * Describes a contribution to the 'org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets'
26
 * extension point.
27
 *
28
 * @since 3.3
29
 */
30
public class HyperlinkDetectorTargetDescriptor {
31
32
	private static final String HYPERLINK_DETECTOR_TARGETS_EXTENSION_POINT= "org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets"; //$NON-NLS-1$
33
	private static final String TARGET_ELEMENT= "target"; //$NON-NLS-1$
34
	private static final String ID_ATTRIBUTE= "id"; //$NON-NLS-1$
35
	private static final String NAME_ATTRIBUTE= "name"; //$NON-NLS-1$
36
	private static final String DESCRIPTION_ATTRIBUTE= "description"; //$NON-NLS-1$
37
	private static final String CONTEXT_ELEMENT= "context"; //$NON-NLS-1$
38
	private static final String TYPE_ATTRIBUTE= "type"; //$NON-NLS-1$
39
40
	private IConfigurationElement fElement;
41
42
43
	/**
44
	 * Returns descriptors for all hyperlink detector extensions.
45
	 *
46
	 * @return an array with the contributed hyperlink detectors
47
	 */
48
	public static HyperlinkDetectorTargetDescriptor[] getContributedHyperlinkDetectorTargets() {
49
		IExtensionRegistry registry= Platform.getExtensionRegistry();
50
		IConfigurationElement[] elements= registry.getConfigurationElementsFor(HYPERLINK_DETECTOR_TARGETS_EXTENSION_POINT);
51
		HyperlinkDetectorTargetDescriptor[] hyperlinkDetectorDescs= createDescriptors(elements);
52
		return hyperlinkDetectorDescs;
53
	}
54
55
	/**
56
	 * Creates a new descriptor from the given configuration element.
57
	 * 
58
	 * @param element the configuration element 
59
	 */
60
	private HyperlinkDetectorTargetDescriptor(IConfigurationElement element) {
61
		Assert.isNotNull(element);
62
		fElement= element;
63
	}
64
65
	//---- XML Attribute accessors ---------------------------------------------
66
67
	/**
68
	 * Returns the hyperlink detector target's id.
69
	 * 
70
	 * @return the hyperlink detector target's id 
71
	 */
72
	public String getId() {
73
		return fElement.getAttribute(ID_ATTRIBUTE);
74
	}
75
76
	/**
77
	 * Returns the hyperlink detector target's name.
78
	 * 
79
	 * @return the hyperlink detector target's name 
80
	 */
81
	public String getName() {
82
		return fElement.getAttribute(NAME_ATTRIBUTE);
83
	}
84
	
85
	/**
86
	 * Returns the types that the context of this
87
	 * hyperlink detector target supports.
88
	 * 
89
	 * @return an array with type names that this target's context supports 
90
	 */
91
	public String[] getTypes() {
92
		IConfigurationElement[] contexts= fElement.getChildren(CONTEXT_ELEMENT);
93
		String[] types= new String[contexts.length];
94
		for (int i= 0; i < contexts.length; i++)
95
			types[i]= contexts[i].getAttribute(TYPE_ATTRIBUTE);
96
		return types;
97
	}
98
99
	/**
100
	 * Returns the hyperlink detector target's description.
101
	 *
102
	 * @return the hyperlink detector target's description or <code>null</code> if not provided
103
	 */
104
	public String getDescription() {
105
		return fElement.getAttribute(DESCRIPTION_ATTRIBUTE);
106
	}
107
108
109
	public boolean equals(Object obj) {
110
		if (obj == null || !obj.getClass().equals(this.getClass()) || getId() == null)
111
			return false;
112
		return getId().equals(((HyperlinkDetectorTargetDescriptor)obj).getId());
113
	}
114
115
	public int hashCode() {
116
		return getId().hashCode();
117
	}
118
119
	private static HyperlinkDetectorTargetDescriptor[] createDescriptors(IConfigurationElement[] elements) {
120
		List result= new ArrayList(elements.length);
121
		for (int i= 0; i < elements.length; i++) {
122
			IConfigurationElement element= elements[i];
123
			if (TARGET_ELEMENT.equals(element.getName())) {
124
				HyperlinkDetectorTargetDescriptor desc= new HyperlinkDetectorTargetDescriptor(element);
125
				if (desc.isValid())
126
					result.add(desc);
127
				else {
128
					String message= NLSUtility.format(EditorMessages.Editor_error_HyperlinkDetectorTarget_invalidExtension_message, new String[] {desc.getId(), element.getContributor().getName()});
129
					TextEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, IStatus.OK, message, null));
130
				}
131
			} else {
132
				String message= NLSUtility.format(EditorMessages.Editor_error_HyperlinkDetectorTarget_invalidElementName_message, new String[] { element.getContributor().getName(), element.getName() });
133
				TextEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, IStatus.OK, message, null));
134
			}
135
			
136
		}
137
		return (HyperlinkDetectorTargetDescriptor[])result.toArray(new HyperlinkDetectorTargetDescriptor[result.size()]);
138
	}
139
	
140
	private boolean isValid() {
141
		return getId() != null && getName() != null;
142
	}
143
144
}
(-)schema/hyperlinkDetectorTargets.exsd (+155 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.ui.workbench.texteditor">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.ui.workbench.texteditor" id="hyperlinkDetectorTargets" name="Hyperlink Detector Targets"/>
7
      </appInfo>
8
      <documentation>
9
         This extension point is used to plug-in hyperlink detector targets.
10
&lt;p&gt;
11
&lt;em&gt;This API is provisional and may change any time before the 3.3 API freeze.&lt;/em&gt;
12
&lt;/p&gt;
13
      </documentation>
14
   </annotation>
15
16
   <element name="extension">
17
      <complexType>
18
         <sequence>
19
            <element ref="target" minOccurs="1" maxOccurs="unbounded"/>
20
         </sequence>
21
         <attribute name="point" type="string" use="required">
22
            <annotation>
23
               <documentation>
24
                  a fully qualified identifier of the target extension point
25
               </documentation>
26
            </annotation>
27
         </attribute>
28
         <attribute name="id" type="string">
29
            <annotation>
30
               <documentation>
31
                  an optional identifier of the extension instance
32
               </documentation>
33
            </annotation>
34
         </attribute>
35
         <attribute name="name" type="string">
36
            <annotation>
37
               <documentation>
38
                  an optional name of the extension instance
39
               </documentation>
40
               <appInfo>
41
                  <meta.attribute translatable="true"/>
42
               </appInfo>
43
            </annotation>
44
         </attribute>
45
      </complexType>
46
   </element>
47
48
   <element name="target">
49
      <complexType>
50
         <sequence minOccurs="0" maxOccurs="1">
51
            <element ref="context" minOccurs="1" maxOccurs="unbounded"/>
52
         </sequence>
53
         <attribute name="id" type="string" use="required">
54
            <annotation>
55
               <documentation>
56
                  a unique id that will be used to identify this hyperlink detector target
57
               </documentation>
58
            </annotation>
59
         </attribute>
60
         <attribute name="name" type="string" use="required">
61
            <annotation>
62
               <documentation>
63
                  a name that allows to identify this hyperlink detector target in the UI
64
               </documentation>
65
               <appInfo>
66
                  <meta.attribute translatable="true"/>
67
               </appInfo>
68
            </annotation>
69
         </attribute>
70
         <attribute name="description" type="string">
71
            <annotation>
72
               <documentation>
73
                  the translatable description for this hyperlink detector target
74
               </documentation>
75
               <appInfo>
76
                  <meta.attribute translatable="true"/>
77
               </appInfo>
78
            </annotation>
79
         </attribute>
80
      </complexType>
81
   </element>
82
83
   <element name="context">
84
      <complexType>
85
         <attribute name="type" type="string" use="required">
86
            <annotation>
87
               <documentation>
88
                  a hyperlink detector target context that can be access through &lt;code&gt;org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector.getAdapter(...)&lt;/code&gt;
89
               </documentation>
90
               <appInfo>
91
                  <meta.attribute kind="java"/>
92
               </appInfo>
93
            </annotation>
94
         </attribute>
95
      </complexType>
96
   </element>
97
98
   <annotation>
99
      <appInfo>
100
         <meta.section type="examples"/>
101
      </appInfo>
102
      <documentation>
103
         The following is an example of a hyperlink detector target definition:
104
105
&lt;pre&gt;
106
&lt;extension
107
  point=&quot;org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets&quot;&gt;
108
  &lt;target
109
    id=&quot;org.eclipse.jdt.ui.javaCode&quot;
110
    name=&quot;Java Editor&quot;&gt;
111
    &lt;context type=&quot;org.eclipse.ui.texteditor.ITextEditor&quot;/&gt;
112
  &lt;/target&gt;
113
&lt;/extension&gt;
114
&lt;/pre&gt;
115
      </documentation>
116
   </annotation>
117
118
   <annotation>
119
      <appInfo>
120
         <meta.section type="apiInfo"/>
121
      </appInfo>
122
      <documentation>
123
         
124
      </documentation>
125
   </annotation>
126
127
   <annotation>
128
      <appInfo>
129
         <meta.section type="since"/>
130
      </appInfo>
131
      <documentation>
132
         3.3
133
      </documentation>
134
   </annotation>
135
136
   <annotation>
137
      <appInfo>
138
         <meta.section type="implementation"/>
139
      </appInfo>
140
      <documentation>
141
         
142
      </documentation>
143
   </annotation>
144
145
   <annotation>
146
      <appInfo>
147
         <meta.section type="copyright"/>
148
      </appInfo>
149
      <documentation>
150
         Copyright (c) 2007 IBM Corporation and others.&lt;br&gt;
151
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 &lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
152
      </documentation>
153
   </annotation>
154
155
</schema>
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/NLSKeyHyperlinkDetector.java (-20 / +7 lines)
Lines 11-23 Link Here
11
11
12
package org.eclipse.jdt.internal.ui.javaeditor;
12
package org.eclipse.jdt.internal.ui.javaeditor;
13
13
14
import org.eclipse.core.runtime.Assert;
15
16
import org.eclipse.jface.text.IRegion;
14
import org.eclipse.jface.text.IRegion;
17
import org.eclipse.jface.text.ITextViewer;
15
import org.eclipse.jface.text.ITextViewer;
18
import org.eclipse.jface.text.Region;
16
import org.eclipse.jface.text.Region;
17
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
19
import org.eclipse.jface.text.hyperlink.IHyperlink;
18
import org.eclipse.jface.text.hyperlink.IHyperlink;
20
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
21
19
22
import org.eclipse.ui.IEditorInput;
20
import org.eclipse.ui.IEditorInput;
23
import org.eclipse.ui.IEditorSite;
21
import org.eclipse.ui.IEditorSite;
Lines 42-74 Link Here
42
 *
40
 *
43
 * @since 3.1
41
 * @since 3.1
44
 */
42
 */
45
public class NLSKeyHyperlinkDetector implements IHyperlinkDetector {
43
public class NLSKeyHyperlinkDetector extends AbstractHyperlinkDetector {
46
47
	private ITextEditor fTextEditor;
48
49
44
50
	/**
51
	 * Creates a new NLS hyperlink detector.
52
	 *
53
	 * @param editor the editor in which to detect the hyperlink
54
	 */
55
	public NLSKeyHyperlinkDetector(ITextEditor editor) {
56
		Assert.isNotNull(editor);
57
		fTextEditor= editor;
58
	}
59
45
60
	/*
46
	/*
61
	 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
47
	 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
62
	 */
48
	 */
63
	public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
49
	public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
64
		if (region == null || fTextEditor == null || canShowMultipleHyperlinks)
50
		ITextEditor textEditor= (ITextEditor)getAdapter(ITextEditor.class);
51
		if (region == null || textEditor == null || canShowMultipleHyperlinks)
65
			return null;
52
			return null;
66
53
67
		IEditorSite site= fTextEditor.getEditorSite();
54
		IEditorSite site= textEditor.getEditorSite();
68
		if (site == null)
55
		if (site == null)
69
			return null;
56
			return null;
70
57
71
		IJavaElement javaElement= getInputJavaElement(fTextEditor);
58
		IJavaElement javaElement= getInputJavaElement(textEditor);
72
		if (javaElement == null)
59
		if (javaElement == null)
73
			return null;
60
			return null;
74
61
Lines 94-100 Link Here
94
			keyName= ((SimpleName)node).getIdentifier();
81
			keyName= ((SimpleName)node).getIdentifier();
95
		}
82
		}
96
		if (keyName != null)
83
		if (keyName != null)
97
			return new IHyperlink[] {new NLSKeyHyperlink(nlsKeyRegion, keyName, ref, fTextEditor)};
84
			return new IHyperlink[] {new NLSKeyHyperlink(nlsKeyRegion, keyName, ref, textEditor)};
98
85
99
		return null;
86
		return null;
100
	}
87
	}
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlinkDetector.java (-21 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-24 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.javaeditor;
11
package org.eclipse.jdt.internal.ui.javaeditor;
12
12
13
import org.eclipse.core.runtime.Assert;
14
15
import org.eclipse.jface.action.IAction;
13
import org.eclipse.jface.action.IAction;
16
14
17
import org.eclipse.jface.text.IDocument;
15
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.jface.text.IRegion;
16
import org.eclipse.jface.text.IRegion;
19
import org.eclipse.jface.text.ITextViewer;
17
import org.eclipse.jface.text.ITextViewer;
18
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
20
import org.eclipse.jface.text.hyperlink.IHyperlink;
19
import org.eclipse.jface.text.hyperlink.IHyperlink;
21
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
22
20
23
import org.eclipse.ui.texteditor.ITextEditor;
21
import org.eclipse.ui.texteditor.ITextEditor;
24
22
Lines 34-72 Link Here
34
 *
32
 *
35
 * @since 3.1
33
 * @since 3.1
36
 */
34
 */
37
public class JavaElementHyperlinkDetector implements IHyperlinkDetector {
35
public class JavaElementHyperlinkDetector extends AbstractHyperlinkDetector {
38
39
	private ITextEditor fTextEditor;
40
41
	/**
42
	 * Creates a new Java element hyperlink detector.
43
	 *
44
	 * @param editor the editor in which to detect the hyperlink
45
	 */
46
	public JavaElementHyperlinkDetector(ITextEditor editor) {
47
		Assert.isNotNull(editor);
48
		fTextEditor= editor;
49
	}
50
36
51
	/*
37
	/*
52
	 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
38
	 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
53
	 */
39
	 */
54
	public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
40
	public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
55
		if (region == null || canShowMultipleHyperlinks || !(fTextEditor instanceof JavaEditor))
41
		ITextEditor textEditor= (ITextEditor)getAdapter(ITextEditor.class);
42
		if (region == null || canShowMultipleHyperlinks || !(textEditor instanceof JavaEditor))
56
			return null;
43
			return null;
57
44
58
		IAction openAction= fTextEditor.getAction("OpenEditor"); //$NON-NLS-1$
45
		IAction openAction= textEditor.getAction("OpenEditor"); //$NON-NLS-1$
59
		if (openAction == null)
46
		if (openAction == null)
60
			return null;
47
			return null;
61
48
62
		int offset= region.getOffset();
49
		int offset= region.getOffset();
63
50
64
		IJavaElement input= EditorUtility.getEditorInputJavaElement(fTextEditor, false);
51
		IJavaElement input= EditorUtility.getEditorInputJavaElement(textEditor, false);
65
		if (input == null)
52
		if (input == null)
66
			return null;
53
			return null;
67
54
68
		try {
55
		try {
69
			IDocument document= fTextEditor.getDocumentProvider().getDocument(fTextEditor.getEditorInput());
56
			IDocument document= textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
70
			IRegion wordRegion= JavaWordFinder.findWord(document, offset);
57
			IRegion wordRegion= JavaWordFinder.findWord(document, offset);
71
			if (wordRegion == null)
58
			if (wordRegion == null)
72
				return null;
59
				return null;
Lines 81-84 Link Here
81
68
82
		return null;
69
		return null;
83
	}
70
	}
71
84
}
72
}
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/NLSKeyHyperlink.java (-1 / +2 lines)
Lines 120-126 Link Here
120
			IDocument document= ((ITextEditor)editor).getDocumentProvider().getDocument(editorInput);
120
			IDocument document= ((ITextEditor)editor).getDocumentProvider().getDocument(editorInput);
121
			if (document != null) {
121
			if (document != null) {
122
				FindReplaceDocumentAdapter finder= new FindReplaceDocumentAdapter(document);
122
				FindReplaceDocumentAdapter finder= new FindReplaceDocumentAdapter(document);
123
				PropertyKeyHyperlinkDetector detector= new PropertyKeyHyperlinkDetector((ITextEditor)editor);
123
				PropertyKeyHyperlinkDetector detector= new PropertyKeyHyperlinkDetector();
124
				detector.setContext(editor);
124
				String key= PropertyFileDocumentModel.unwindEscapeChars(fKeyName);
125
				String key= PropertyFileDocumentModel.unwindEscapeChars(fKeyName);
125
				int offset= document.getLength() - 1;
126
				int offset= document.getLength() - 1;
126
				try {
127
				try {
(-)ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertyKeyHyperlinkDetector.java (-28 / +14 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-23 Link Here
16
import java.text.StringCharacterIterator;
16
import java.text.StringCharacterIterator;
17
import java.util.Properties;
17
import java.util.Properties;
18
18
19
import org.eclipse.core.runtime.Assert;
20
21
import org.eclipse.jface.text.BadLocationException;
19
import org.eclipse.jface.text.BadLocationException;
22
import org.eclipse.jface.text.BadPartitioningException;
20
import org.eclipse.jface.text.BadPartitioningException;
23
import org.eclipse.jface.text.IDocument;
21
import org.eclipse.jface.text.IDocument;
Lines 26-33 Link Here
26
import org.eclipse.jface.text.ITextViewer;
24
import org.eclipse.jface.text.ITextViewer;
27
import org.eclipse.jface.text.ITypedRegion;
25
import org.eclipse.jface.text.ITypedRegion;
28
import org.eclipse.jface.text.Region;
26
import org.eclipse.jface.text.Region;
27
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
29
import org.eclipse.jface.text.hyperlink.IHyperlink;
28
import org.eclipse.jface.text.hyperlink.IHyperlink;
30
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
31
29
32
import org.eclipse.ui.IEditorSite;
30
import org.eclipse.ui.IEditorSite;
33
import org.eclipse.ui.IFileEditorInput;
31
import org.eclipse.ui.IFileEditorInput;
Lines 45-84 Link Here
45
 *
43
 *
46
 * @since 3.1
44
 * @since 3.1
47
 */
45
 */
48
public class PropertyKeyHyperlinkDetector implements IHyperlinkDetector {
46
public class PropertyKeyHyperlinkDetector extends AbstractHyperlinkDetector {
49
50
	private ITextEditor fTextEditor;
51
52
53
	/**
54
	 * Creates a new Properties key hyperlink detector.
55
	 *
56
	 * @param editor the editor in which to detect the hyperlink
57
	 */
58
	public PropertyKeyHyperlinkDetector(ITextEditor editor) {
59
		Assert.isNotNull(editor);
60
		fTextEditor= editor;
61
	}
62
47
63
	/*
48
	/*
64
	 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
49
	 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
65
	 */
50
	 */
66
	public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
51
	public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
67
		if (region == null || fTextEditor == null || canShowMultipleHyperlinks)
52
		ITextEditor textEditor= (ITextEditor)getAdapter(ITextEditor.class);
53
		if (region == null || textEditor == null || canShowMultipleHyperlinks)
68
			return null;
54
			return null;
69
55
70
		IEditorSite site= fTextEditor.getEditorSite();
56
		IEditorSite site= textEditor.getEditorSite();
71
		if (site == null)
57
		if (site == null)
72
			return null;
58
			return null;
73
59
74
		if (!checkEnabled(region))
60
		int offset= region.getOffset();
61
		if (!checkEnabled(textEditor, offset))
75
			return null;
62
			return null;
76
63
77
		int offset= region.getOffset();
78
		ITypedRegion partition= null;
64
		ITypedRegion partition= null;
79
		try {
65
		try {
80
			IStorageEditorInput storageEditorInput= (IStorageEditorInput)fTextEditor.getEditorInput();
66
			IStorageEditorInput storageEditorInput= (IStorageEditorInput)textEditor.getEditorInput();
81
			IDocument document= fTextEditor.getDocumentProvider().getDocument(storageEditorInput);
67
			IDocument document= textEditor.getDocumentProvider().getDocument(storageEditorInput);
82
			if (document instanceof IDocumentExtension3)
68
			if (document instanceof IDocumentExtension3)
83
				partition= ((IDocumentExtension3)document).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, offset, false);
69
				partition= ((IDocumentExtension3)document).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, offset, false);
84
70
Lines 106-112 Link Here
106
				return null;
92
				return null;
107
			}
93
			}
108
94
109
			return new PropertyKeyHyperlink[] {new PropertyKeyHyperlink(new Region(partition.getOffset() + delta, realKey.length()), realKey, fTextEditor)};
95
			return new PropertyKeyHyperlink[] {new PropertyKeyHyperlink(new Region(partition.getOffset() + delta, realKey.length()), realKey, textEditor)};
110
96
111
		} catch (BadLocationException ex) {
97
		} catch (BadLocationException ex) {
112
			return null;
98
			return null;
Lines 140-150 Link Here
140
		return result.toString();
126
		return result.toString();
141
	}
127
	}
142
128
143
	private boolean checkEnabled(IRegion region) {
129
	private boolean checkEnabled(ITextEditor textEditor, int offset) {
144
		if (region == null || region.getOffset() < 0)
130
		if (offset < 0)
145
			return false;
131
			return false;
146
132
147
		 // XXX: Must be changed to IStorageEditorInput once support for JARs is available (see class Javadoc for details)
133
		 // XXX: Must be changed to IStorageEditorInput once support for JARs is available (see class Javadoc for details)
148
		return fTextEditor.getEditorInput() instanceof IFileEditorInput;
134
		return textEditor.getEditorInput() instanceof IFileEditorInput;
149
	}
135
	}
150
}
136
}
(-)ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/PropertiesFileSourceViewerConfiguration.java (-20 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.propertiesfileeditor;
11
package org.eclipse.jdt.internal.ui.propertiesfileeditor;
12
12
13
import java.util.Map;
14
13
import org.eclipse.core.runtime.NullProgressMonitor;
15
import org.eclipse.core.runtime.NullProgressMonitor;
14
import org.eclipse.core.runtime.Platform;
16
import org.eclipse.core.runtime.Platform;
15
import org.eclipse.core.runtime.content.IContentType;
17
import org.eclipse.core.runtime.content.IContentType;
Lines 26-32 Link Here
26
import org.eclipse.jface.text.IInformationControl;
28
import org.eclipse.jface.text.IInformationControl;
27
import org.eclipse.jface.text.IInformationControlCreator;
29
import org.eclipse.jface.text.IInformationControlCreator;
28
import org.eclipse.jface.text.ITextDoubleClickStrategy;
30
import org.eclipse.jface.text.ITextDoubleClickStrategy;
29
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
30
import org.eclipse.jface.text.presentation.IPresentationReconciler;
31
import org.eclipse.jface.text.presentation.IPresentationReconciler;
31
import org.eclipse.jface.text.presentation.PresentationReconciler;
32
import org.eclipse.jface.text.presentation.PresentationReconciler;
32
import org.eclipse.jface.text.reconciler.IReconciler;
33
import org.eclipse.jface.text.reconciler.IReconciler;
Lines 38-44 Link Here
38
import org.eclipse.jface.text.source.IAnnotationHover;
39
import org.eclipse.jface.text.source.IAnnotationHover;
39
import org.eclipse.jface.text.source.ISourceViewer;
40
import org.eclipse.jface.text.source.ISourceViewer;
40
41
41
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
42
import org.eclipse.ui.texteditor.ITextEditor;
42
import org.eclipse.ui.texteditor.ITextEditor;
43
import org.eclipse.ui.texteditor.spelling.SpellingReconcileStrategy;
43
import org.eclipse.ui.texteditor.spelling.SpellingReconcileStrategy;
44
import org.eclipse.ui.texteditor.spelling.SpellingService;
44
import org.eclipse.ui.texteditor.spelling.SpellingService;
Lines 250-273 Link Here
250
	}
250
	}
251
251
252
	/*
252
	/*
253
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getHyperlinkDetectors(org.eclipse.jface.text.source.ISourceViewer)
253
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getHyperlinkDetectorTargets(org.eclipse.jface.text.source.ISourceViewer)
254
	 * @since 3.3
254
	 */
255
	 */
255
	public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
256
	protected Map getHyperlinkDetectorTargets(ISourceViewer sourceViewer) {
256
		if (!fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
257
		Map targets= super.getHyperlinkDetectorTargets(sourceViewer);
257
			return null;
258
		targets.put("org.eclipse.jdt.ui.PropertiesFileEditor", fTextEditor); //$NON-NLS-1$
258
259
		return targets;
259
		IHyperlinkDetector[] inheritedDetectors= super.getHyperlinkDetectors(sourceViewer);
260
261
		if (fTextEditor == null)
262
			return inheritedDetectors;
263
264
		int inheritedDetectorsLength= inheritedDetectors != null ? inheritedDetectors.length : 0;
265
		IHyperlinkDetector[] detectors= new IHyperlinkDetector[inheritedDetectorsLength + 2];
266
		detectors[0]= new PropertyKeyHyperlinkDetector(fTextEditor);
267
		for (int i= 0; i < inheritedDetectorsLength; i++)
268
			detectors[i+1]= inheritedDetectors[i];
269
270
		return detectors;
271
	}
260
	}
272
261
273
	/*
262
	/*
(-)ui/org/eclipse/jdt/internal/ui/propertiesfileeditor/OpenAction.java (-2 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 75-81 Link Here
75
			return;
75
			return;
76
76
77
		IRegion region= new Region(selection.getOffset(), selection.getLength());
77
		IRegion region= new Region(selection.getOffset(), selection.getLength());
78
		IHyperlink[]hyperlinks= new PropertyKeyHyperlinkDetector(fEditor).detectHyperlinks(fEditor.internalGetSourceViewer(), region, false);
78
		PropertyKeyHyperlinkDetector detector= new PropertyKeyHyperlinkDetector();
79
		detector.setContext(fEditor);
80
		IHyperlink[]hyperlinks= detector.detectHyperlinks(fEditor.internalGetSourceViewer(), region, false);
79
81
80
		if (hyperlinks != null && hyperlinks.length == 1)
82
		if (hyperlinks != null && hyperlinks.length == 1)
81
			hyperlinks[0].open();
83
			hyperlinks[0].open();
(-)plugin.properties (-4 / +11 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2006 IBM Corporation and others.
2
# Copyright (c) 2000, 2007 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 111-118 Link Here
111
preferenceKeywords.saveparticipant=Java editor save cleanup participants
111
preferenceKeywords.saveparticipant=Java editor save cleanup participants
112
112
113
sourceAttachmentPageName=Java Source Attachment
113
sourceAttachmentPageName=Java Source Attachment
114
classFileViewerName=Class File Viewer
114
ClassFileViewerName=Class File Viewer
115
propertiesFileEditorName=Properties File Editor
116
jarDescEditorName=JAR Description Editor
115
jarDescEditorName=JAR Description Editor
117
116
118
javaEditorFontDefiniton.label= Java Editor Text Font
117
javaEditorFontDefiniton.label= Java Editor Text Font
Lines 182-188 Link Here
182
JavaElementCreationActionSet.label= Java Element Creation
181
JavaElementCreationActionSet.label= Java Element Creation
183
JavaElementCreationActionSet.description= Java Element Creation Action Set
182
JavaElementCreationActionSet.description= Java Element Creation Action Set
184
183
185
JavaEditor.label= Java Editor
184
CompilationUnitEditorName= Java Editor
186
185
187
OpenTypeAction.label=Open &Type...
186
OpenTypeAction.label=Open &Type...
188
OpenTypeAction.tooltip=Open Type
187
OpenTypeAction.tooltip=Open Type
Lines 1008-1013 Link Here
1008
javaPresentation.label= Java
1007
javaPresentation.label= Java
1009
1008
1010
#--- Properties File Editor
1009
#--- Properties File Editor
1010
PropertiesFileEditorName=Properties File Editor
1011
propertiesFileDocumentSetupParticipant= Properties File Document Setup Participant
1011
propertiesFileDocumentSetupParticipant= Properties File Document Setup Participant
1012
1012
1013
propertiesFileEditorFontDefiniton.label= Properties File Editor Text Font
1013
propertiesFileEditorFontDefiniton.label= Properties File Editor Text Font
Lines 1038-1040 Link Here
1038
MarkerCategory.unnecessary=Unnecessary Code
1038
MarkerCategory.unnecessary=Unnecessary Code
1039
MarkerCategory.nls=Externalized Strings
1039
MarkerCategory.nls=Externalized Strings
1040
MarkerCategory.restrictedAPI=Restricted API
1040
MarkerCategory.restrictedAPI=Restricted API
1041
1042
#--- Hyperlinking ---
1043
JavaEditorHyperlinkTarget= Java Editor
1044
PropertiesFileEditorHyperlinkTarget=Properties File Editor
1045
JavaElementHyperlinkDetector= Java Element Hyperlink Detector
1046
NLSHyperlinkDetector= NLS Hyperlink Detector
1047
PropertyKeyHyperlinkDetector= Java Property Key Hyperlink Detector
(-)plugin.xml (-3 / +39 lines)
Lines 824-830 Link Here
824
         id="javaeditor"
824
         id="javaeditor"
825
         point="org.eclipse.ui.editors">
825
         point="org.eclipse.ui.editors">
826
      <editor
826
      <editor
827
            name="%JavaEditor.label"
827
            name="%CompilationUnitEditorName"
828
            default="true"
828
            default="true"
829
            icon="$nl$/icons/full/obj16/jcu_obj.gif"
829
            icon="$nl$/icons/full/obj16/jcu_obj.gif"
830
            contributorClass="org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditorActionContributor"
830
            contributorClass="org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditorActionContributor"
Lines 836-842 Link Here
836
            /> 
836
            /> 
837
      </editor>
837
      </editor>
838
      <editor
838
      <editor
839
            name="%classFileViewerName"
839
            name="%ClassFileViewerName"
840
            default="true"
840
            default="true"
841
            icon="$nl$/icons/full/obj16/classf_obj.gif"
841
            icon="$nl$/icons/full/obj16/classf_obj.gif"
842
            contributorClass="org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditorActionContributor"
842
            contributorClass="org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditorActionContributor"
Lines 848-854 Link Here
848
            /> 
848
            /> 
849
      </editor>
849
      </editor>
850
      <editor
850
      <editor
851
            name="%propertiesFileEditorName"
851
            name="%PropertiesFileEditorName"
852
            icon="$nl$/icons/full/obj16/file_obj.gif"
852
            icon="$nl$/icons/full/obj16/file_obj.gif"
853
            contributorClass="org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileEditorActionContributor"
853
            contributorClass="org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileEditorActionContributor"
854
            class="org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileEditor"
854
            class="org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileEditor"
Lines 1156-1161 Link Here
1156
   </extension>
1156
   </extension>
1157
1157
1158
   <extension
1158
   <extension
1159
         point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets">
1160
      <target
1161
            id="org.eclipse.jdt.ui.javaCode"
1162
            name="%JavaEditorHyperlinkTarget">
1163
            <context type="org.eclipse.ui.texteditor.ITextEditor"/>
1164
      </target>
1165
      <target
1166
            id="org.eclipse.jdt.ui.PropertiesFileEditor"
1167
            name="%PropertiesFileEditorHyperlinkTarget">
1168
            <context type="org.eclipse.ui.texteditor.ITextEditor"/>
1169
      </target>
1170
   </extension>
1171
1172
   <extension
1173
         point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
1174
      <hyperlinkDetector
1175
            class="org.eclipse.jdt.internal.ui.javaeditor.NLSKeyHyperlinkDetector"
1176
            id="org.eclipse.jdt.internal.ui.javaeditor.NLSKeyHyperlinkDetector"
1177
            name="%NLSHyperlinkDetector"
1178
            targetId="org.eclipse.jdt.ui.javaCode">
1179
      </hyperlinkDetector>
1180
      <hyperlinkDetector
1181
            class="org.eclipse.jdt.internal.ui.javaeditor.JavaElementHyperlinkDetector"
1182
            id="org.eclipse.jdt.internal.ui.javaeditor.JavaElementHyperlinkDetector"
1183
            name="%JavaElementHyperlinkDetector"
1184
            targetId="org.eclipse.jdt.ui.javaCode">
1185
      </hyperlinkDetector>
1186
      <hyperlinkDetector
1187
            class="org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertyKeyHyperlinkDetector"
1188
            id="org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertyKeyHyperlinkDetector"
1189
            name="%PropertyKeyHyperlinkDetector"
1190
            targetId="org.eclipse.jdt.ui.PropertiesFileEditor">
1191
      </hyperlinkDetector>
1192
   </extension>
1193
1194
   <extension
1159
         point="org.eclipse.ui.preferencePages">
1195
         point="org.eclipse.ui.preferencePages">
1160
      <page
1196
      <page
1161
            name="%javaPrefName"
1197
            name="%javaPrefName"
(-)ui/org/eclipse/jdt/ui/text/JavaSourceViewerConfiguration.java (-24 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-16 Link Here
11
package org.eclipse.jdt.ui.text;
11
package org.eclipse.jdt.ui.text;
12
12
13
import java.util.Arrays;
13
import java.util.Arrays;
14
import java.util.Map;
14
15
15
import org.eclipse.core.runtime.Assert;
16
import org.eclipse.core.runtime.Assert;
16
import org.eclipse.core.runtime.NullProgressMonitor;
17
import org.eclipse.core.runtime.NullProgressMonitor;
Lines 38-44 Link Here
38
import org.eclipse.jface.text.contentassist.IContentAssistant;
39
import org.eclipse.jface.text.contentassist.IContentAssistant;
39
import org.eclipse.jface.text.formatter.IContentFormatter;
40
import org.eclipse.jface.text.formatter.IContentFormatter;
40
import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
41
import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
41
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
42
import org.eclipse.jface.text.information.IInformationPresenter;
42
import org.eclipse.jface.text.information.IInformationPresenter;
43
import org.eclipse.jface.text.information.IInformationProvider;
43
import org.eclipse.jface.text.information.IInformationProvider;
44
import org.eclipse.jface.text.information.InformationPresenter;
44
import org.eclipse.jface.text.information.InformationPresenter;
Lines 75-82 Link Here
75
import org.eclipse.jdt.internal.ui.JavaPlugin;
75
import org.eclipse.jdt.internal.ui.JavaPlugin;
76
import org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput;
76
import org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput;
77
import org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider;
77
import org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider;
78
import org.eclipse.jdt.internal.ui.javaeditor.JavaElementHyperlinkDetector;
79
import org.eclipse.jdt.internal.ui.javaeditor.NLSKeyHyperlinkDetector;
80
import org.eclipse.jdt.internal.ui.text.AbstractJavaScanner;
78
import org.eclipse.jdt.internal.ui.text.AbstractJavaScanner;
81
import org.eclipse.jdt.internal.ui.text.ContentAssistPreference;
79
import org.eclipse.jdt.internal.ui.text.ContentAssistPreference;
82
import org.eclipse.jdt.internal.ui.text.HTMLAnnotationHover;
80
import org.eclipse.jdt.internal.ui.text.HTMLAnnotationHover;
Lines 899-924 Link Here
899
	}
897
	}
900
898
901
	/*
899
	/*
902
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getHyperlinkDetectors(org.eclipse.jface.text.source.ISourceViewer)
900
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getHyperlinkDetectorTargets(org.eclipse.jface.text.source.ISourceViewer)
903
	 * @since 3.1
901
	 * @since 3.3
904
	 */
902
	 */
905
	public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
903
	protected Map getHyperlinkDetectorTargets(ISourceViewer sourceViewer) {
906
		if (!fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
904
		Map targets= super.getHyperlinkDetectorTargets(sourceViewer);
907
			return null;
905
		targets.put("org.eclipse.jdt.ui.javaCode", fTextEditor); //$NON-NLS-1$
908
906
		return targets;
909
		IHyperlinkDetector[] inheritedDetectors= super.getHyperlinkDetectors(sourceViewer);
910
911
		if (fTextEditor == null)
912
			return inheritedDetectors;
913
914
		int inheritedDetectorsLength= inheritedDetectors != null ? inheritedDetectors.length : 0;
915
		IHyperlinkDetector[] detectors= new IHyperlinkDetector[inheritedDetectorsLength + 2];
916
		detectors[0]= new NLSKeyHyperlinkDetector(fTextEditor);
917
		detectors[1]= new JavaElementHyperlinkDetector(fTextEditor);
918
		for (int i= 0; i < inheritedDetectorsLength; i++)
919
			detectors[i+2]= inheritedDetectors[i];
920
921
		return detectors;
922
	}
907
	}
923
	
908
924
}
909
}
(-)src/org/eclipse/ui/editors/text/TextSourceViewerConfiguration.java (-2 / +80 lines)
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.editors.text;
11
package org.eclipse.ui.editors.text;
12
12
13
import java.util.HashMap;
14
import java.util.Iterator;
15
import java.util.Map;
13
import java.util.StringTokenizer;
16
import java.util.StringTokenizer;
17
import java.util.Map.Entry;
14
18
15
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.widgets.Shell;
20
import org.eclipse.swt.widgets.Shell;
17
21
22
import org.eclipse.core.runtime.Assert;
23
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.NullProgressMonitor;
24
import org.eclipse.core.runtime.NullProgressMonitor;
19
25
20
import org.eclipse.jface.action.Action;
26
import org.eclipse.jface.action.Action;
Lines 43-51 Link Here
43
import org.eclipse.jface.text.source.ISourceViewer;
49
import org.eclipse.jface.text.source.ISourceViewer;
44
import org.eclipse.jface.text.source.SourceViewerConfiguration;
50
import org.eclipse.jface.text.source.SourceViewerConfiguration;
45
51
46
import org.eclipse.ui.internal.editors.text.URLHyperlinkDetector;
47
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
52
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
48
import org.eclipse.ui.texteditor.AnnotationPreference;
53
import org.eclipse.ui.texteditor.AnnotationPreference;
54
import org.eclipse.ui.texteditor.HyperlinkDetectorRegistry;
49
import org.eclipse.ui.texteditor.spelling.SpellingCorrectionProcessor;
55
import org.eclipse.ui.texteditor.spelling.SpellingCorrectionProcessor;
50
import org.eclipse.ui.texteditor.spelling.SpellingReconcileStrategy;
56
import org.eclipse.ui.texteditor.spelling.SpellingReconcileStrategy;
51
import org.eclipse.ui.texteditor.spelling.SpellingService;
57
import org.eclipse.ui.texteditor.spelling.SpellingService;
Lines 216-223 Link Here
216
222
217
		if (!fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
223
		if (!fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
218
			return null;
224
			return null;
225
		
226
		return getRegisteredHyperlinkDetectors(sourceViewer);
227
	}
228
229
	/**
230
	 * Returns the registered hyperlink detectors which are used to detect
231
	 * hyperlinks in the given source viewer.
232
	 * <p>
233
	 * <em>This API is provisional and may change any time before the 3.3 API freeze.</em>
234
	 * </p>
235
	 *
236
	 * @param sourceViewer the source viewer to be configured by this configuration
237
	 * @return an array with hyperlink detectors or <code>null</code> if no hyperlink detectors are registered
238
	 * @since 3.3
239
	 */
240
	protected final IHyperlinkDetector[] getRegisteredHyperlinkDetectors(ISourceViewer sourceViewer) {
241
		HyperlinkDetectorRegistry registry= EditorsUI.getHyperlinkDetectorRegistry();
242
243
		Map targets= getHyperlinkDetectorTargets(sourceViewer);
244
		Assert.isNotNull(targets);
245
		
246
		IHyperlinkDetector[] result= null;
247
		Iterator iter= targets.entrySet().iterator();
248
		while (iter.hasNext()) {
249
			Entry target= (Entry)iter.next();
250
			String targetId= (String)target.getKey();
251
			IAdaptable context= (IAdaptable)target.getValue(); 
252
			result= merge(result, registry.createHyperlinkDetectors(targetId, context));
253
		}
254
		return result;
255
	}
219
256
220
		return new IHyperlinkDetector[] { new URLHyperlinkDetector() };
257
	/**
258
	 * Helper method to merge two {@link IHyperlinkDetector} arrays.
259
	 * 
260
	 * @param array1 an array of hyperlink detectors or <code>null</code>
261
	 * @param array2 an array of hyperlink detectors or <code>null</code>
262
	 * @return an array with the merged hyperlink detectors or <code>null</code> if both given arrays are <code>null</code>
263
	 * @since 3.3
264
	 */
265
	private IHyperlinkDetector[] merge(IHyperlinkDetector[] array1, IHyperlinkDetector[] array2) {
266
		if (array1 == null && array2 == null)
267
			return null;
268
		else if (array1 == null)
269
			return array2;
270
		else if (array2 == null)
271
			return array1;
272
		else {
273
			IHyperlinkDetector[] allHyperlinkDetectors;
274
			int size= array1.length + array2.length;  
275
			allHyperlinkDetectors= new IHyperlinkDetector[size];
276
			System.arraycopy(array1, 0, allHyperlinkDetectors, 0, array1.length);
277
			System.arraycopy(array2, 0, allHyperlinkDetectors, array1.length, array2.length);
278
			return allHyperlinkDetectors;
279
		}
280
	}
281
282
	/**
283
	 * Returns the hyperlink detector targets supported by the
284
	 * given source viewer.
285
	 * <p>
286
	 * <em>This API is provisional and may change any time before the 3.3 API freeze.</em>
287
	 * </p>
288
	 * 
289
	 * @param sourceViewer the source viewer to be configured by this configuration
290
	 * @return the hyperlink detector targets with target id (<code>String</code>) as key
291
	 * 			and the target context (<code>IAdaptable</code>) as value 
292
	 * @since 3.3
293
	 */
294
	protected Map getHyperlinkDetectorTargets(ISourceViewer sourceViewer) {
295
		Map targets= new HashMap();
296
		targets.put("org.eclipse.ui.DefaultTextEditor", null); //$NON-NLS-1$
297
		return targets;
221
	}
298
	}
222
299
223
	/*
300
	/*
Lines 368-371 Link Here
368
			}
445
			}
369
		};
446
		};
370
	}
447
	}
448
371
}
449
}
(-)src/org/eclipse/ui/editors/text/EditorsUI.java (+16 lines)
Lines 27-32 Link Here
27
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
27
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
28
import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
28
import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
29
import org.eclipse.ui.texteditor.AnnotationTypeLookup;
29
import org.eclipse.ui.texteditor.AnnotationTypeLookup;
30
import org.eclipse.ui.texteditor.HyperlinkDetectorRegistry;
30
import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
31
import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
31
import org.eclipse.ui.texteditor.spelling.SpellingService;
32
import org.eclipse.ui.texteditor.spelling.SpellingService;
32
33
Lines 169-174 Link Here
169
		return EditorsPlugin.getDefault().getSharedTextColors();
170
		return EditorsPlugin.getDefault().getSharedTextColors();
170
	}
171
	}
171
172
173
	/**
174
	 * Returns the registry that contains the hyperlink detectors contributed
175
	 * by  the <code>org.eclipse.ui.workbench.texteditor.hyperlinkDetectors</code>
176
	 * extension point.
177
	 * <p>
178
	 * <em>This API is provisional and may change any time before the 3.3 API freeze.</em>
179
	 * </p>
180
	 * 
181
	 * @return the hyperlink detector registry
182
	 * @since 3.3
183
	 */
184
	public static HyperlinkDetectorRegistry getHyperlinkDetectorRegistry() {
185
		return EditorsPlugin.getDefault().getHyperlinkDetectorRegistry();
186
	}
187
172
	// --------------- Status codes for this plug-in ---------------
188
	// --------------- Status codes for this plug-in ---------------
173
	
189
	
174
	// NOTE: See also IEditorsStatusConstants 
190
	// NOTE: See also IEditorsStatusConstants 
(-)src/org/eclipse/ui/internal/editors/text/EditorsPlugin.java (+22 lines)
Lines 25-30 Link Here
25
import org.eclipse.ui.plugin.AbstractUIPlugin;
25
import org.eclipse.ui.plugin.AbstractUIPlugin;
26
import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
26
import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
27
import org.eclipse.ui.texteditor.AnnotationTypeLookup;
27
import org.eclipse.ui.texteditor.AnnotationTypeLookup;
28
import org.eclipse.ui.texteditor.HyperlinkDetectorRegistry;
28
import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
29
import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
29
import org.eclipse.ui.texteditor.spelling.SpellingService;
30
import org.eclipse.ui.texteditor.spelling.SpellingService;
30
31
Lines 77-82 Link Here
77
	 * @since 3.1
78
	 * @since 3.1
78
	 */
79
	 */
79
	private SpellingService fSpellingService;
80
	private SpellingService fSpellingService;
81
	
82
	/**
83
	 * The hyperlink detector registry.
84
	 * @since 3.3
85
	 */
86
	private HyperlinkDetectorRegistry fHyperlinkDetectorRegistry;
80
87
81
	public EditorsPlugin() {
88
	public EditorsPlugin() {
82
		Assert.isTrue(fgInstance == null);
89
		Assert.isTrue(fgInstance == null);
Lines 181-186 Link Here
181
		fAnnotationPreferenceLookup= null;
188
		fAnnotationPreferenceLookup= null;
182
		fAnnotationTypeHierarchy= null;
189
		fAnnotationTypeHierarchy= null;
183
		fMarkerAnnotationPreferences= null;
190
		fMarkerAnnotationPreferences= null;
191
		fHyperlinkDetectorRegistry= null;
184
192
185
		super.stop(context);
193
		super.stop(context);
186
	}
194
	}
Lines 196-199 Link Here
196
			fSpellingService= new SpellingService(getPreferenceStore());
204
			fSpellingService= new SpellingService(getPreferenceStore());
197
		return fSpellingService;
205
		return fSpellingService;
198
	}
206
	}
207
208
	/**
209
	 * Returns the registry that contains the hyperlink detectors contributed
210
	 * by  the <code>org.eclipse.ui.workbench.texteditor.hyperlinkDetectors</code>
211
	 * extension point.
212
	 * 
213
	 * @return the hyperlink detector registry
214
	 * @since 3.3
215
	 */
216
	public synchronized HyperlinkDetectorRegistry getHyperlinkDetectorRegistry() {
217
		if (fHyperlinkDetectorRegistry == null)
218
			fHyperlinkDetectorRegistry= new HyperlinkDetectorRegistry();
219
		return fHyperlinkDetectorRegistry;
220
	}
199
}
221
}
(-)plugin.xml (+18 lines)
Lines 928-931 Link Here
928
      </factory>
928
      </factory>
929
   </extension>
929
   </extension>
930
   
930
   
931
   <extension
932
         point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets">
933
      <target
934
            id="org.eclipse.ui.DefaultTextEditor"
935
            name="%TextEditorHyperlinkTarget">
936
      </target>
937
   </extension>
938
   
939
   <extension
940
         point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
941
      <hyperlinkDetector
942
            class="org.eclipse.ui.internal.editors.text.URLHyperlinkDetector"
943
            id="org.eclipse.ui.internal.editors.text.URLHyperlinkDetector"
944
            name="%URLHyperlinkDetector"
945
            targetId="org.eclipse.ui.DefaultTextEditor">
946
      </hyperlinkDetector>
947
   </extension>
948
931
</plugin>
949
</plugin>
(-)plugin.properties (-2 / +6 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2006 IBM Corporation and others.
2
# Copyright (c) 2000, 2007 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 133-136 Link Here
133
133
134
#--- rulers
134
#--- rulers
135
LineNumberRuler.name= Line Numbers
135
LineNumberRuler.name= Line Numbers
136
AnnotationRuler.name= Annotations
136
AnnotationRuler.name= Annotations
137
138
#--- Hyperlinking ---
139
TextEditorHyperlinkTarget= Text Editor
140
URLHyperlinkDetector= URL Hyperlink Detector
(-)topics_Reference.xml (+2 lines)
Lines 358-363 Link Here
358
       <topic label="org.eclipse.ui.views.properties.tabbed.propertyContributor" href="reference/extension-points/org_eclipse_ui_views_properties_tabbed_propertyContributor.html"/>
358
       <topic label="org.eclipse.ui.views.properties.tabbed.propertyContributor" href="reference/extension-points/org_eclipse_ui_views_properties_tabbed_propertyContributor.html"/>
359
       <topic label="org.eclipse.ui.views.properties.tabbed.propertySections" href="reference/extension-points/org_eclipse_ui_views_properties_tabbed_propertySections.html"/>
359
       <topic label="org.eclipse.ui.views.properties.tabbed.propertySections" href="reference/extension-points/org_eclipse_ui_views_properties_tabbed_propertySections.html"/>
360
       <topic label="org.eclipse.ui.views.properties.tabbed.propertyTabs" href="reference/extension-points/org_eclipse_ui_views_properties_tabbed_propertyTabs.html"/>
360
       <topic label="org.eclipse.ui.views.properties.tabbed.propertyTabs" href="reference/extension-points/org_eclipse_ui_views_properties_tabbed_propertyTabs.html"/>
361
       <topic label="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors" href="reference/extension-points/org_eclipse_ui_workbench_texteditor_hyperlinkDetectors.html"/>
362
       <topic label="org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets" href="reference/extension-points/org_eclipse_ui_workbench_texteditor_hyperlinkDetectorTargets.html"/>
361
       <topic label="org.eclipse.ui.workbench.texteditor.quickDiffReferenceProvider" href="reference/extension-points/org_eclipse_ui_workbench_texteditor_quickDiffReferenceProvider.html"/>
363
       <topic label="org.eclipse.ui.workbench.texteditor.quickDiffReferenceProvider" href="reference/extension-points/org_eclipse_ui_workbench_texteditor_quickDiffReferenceProvider.html"/>
362
       <topic label="org.eclipse.ui.workbench.texteditor.rulerColumns" href="reference/extension-points/org_eclipse_ui_workbench_texteditor_rulerColumns.html"/>
364
       <topic label="org.eclipse.ui.workbench.texteditor.rulerColumns" href="reference/extension-points/org_eclipse_ui_workbench_texteditor_rulerColumns.html"/>
363
       <topic label="org.eclipse.ui.workbench.texteditor.spellingEngine" href="reference/extension-points/org_eclipse_ui_workbench_texteditor_spellingEngine.html"/>
365
       <topic label="org.eclipse.ui.workbench.texteditor.spellingEngine" href="reference/extension-points/org_eclipse_ui_workbench_texteditor_spellingEngine.html"/>
(-)reference/extension-points/index.html (+2 lines)
Lines 50-55 Link Here
50
	<li><a href="org_eclipse_ui_editors_markerAnnotationSpecification.html">org.eclipse.ui.editors.markerAnnotationSpecification</a></li>
50
	<li><a href="org_eclipse_ui_editors_markerAnnotationSpecification.html">org.eclipse.ui.editors.markerAnnotationSpecification</a></li>
51
	<li><a href="org_eclipse_ui_editors_markerUpdaters.html">org.eclipse.ui.editors.markerUpdaters</a></li>
51
	<li><a href="org_eclipse_ui_editors_markerUpdaters.html">org.eclipse.ui.editors.markerUpdaters</a></li>
52
	<li><a href="org_eclipse_ui_editors_templates.html">org.eclipse.ui.editors.templates</a></li>
52
	<li><a href="org_eclipse_ui_editors_templates.html">org.eclipse.ui.editors.templates</a></li>
53
	<li><a href="org_eclipse_ui_workbench_texteditor_hyperlinkDetectors.html">org.eclipse.ui.workbench.texteditor.hyperlinkDetectors</a></li>
54
	<li><a href="org_eclipse_ui_workbench_texteditor_hyperlinkDetectorTargets.html">org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets</a></li>
53
	<li><a href="org_eclipse_ui_workbench_texteditor_rulerColumns.html">org.eclipse.ui.workbench.texteditor.rulerColumns</a></li>
55
	<li><a href="org_eclipse_ui_workbench_texteditor_rulerColumns.html">org.eclipse.ui.workbench.texteditor.rulerColumns</a></li>
54
	<li><a href="org_eclipse_ui_workbench_texteditor_quickDiffReferenceProvider.html">org.eclipse.ui.workbench.texteditor.quickDiffReferenceProvider</a></li>
56
	<li><a href="org_eclipse_ui_workbench_texteditor_quickDiffReferenceProvider.html">org.eclipse.ui.workbench.texteditor.quickDiffReferenceProvider</a></li>
55
	<li><a href="org_eclipse_ui_workbench_texteditor_spellingEngine.html">org.eclipse.ui.workbench.texteditor.spellingEngine</a></li>
57
	<li><a href="org_eclipse_ui_workbench_texteditor_spellingEngine.html">org.eclipse.ui.workbench.texteditor.spellingEngine</a></li>
(-)src/org/eclipse/jface/text/hyperlink/URLHyperlinkDetector.java (-1 / +1 lines)
Lines 27-33 Link Here
27
 *
27
 *
28
 * @since 3.1
28
 * @since 3.1
29
 */
29
 */
30
public class URLHyperlinkDetector implements IHyperlinkDetector {
30
public class URLHyperlinkDetector extends AbstractHyperlinkDetector {
31
31
32
32
33
	/**
33
	/**
(-)src/org/eclipse/jface/text/hyperlink/IHyperlinkDetector.java (+8 lines)
Lines 19-24 Link Here
19
 * A hyperlink detector tries to find a hyperlink at
19
 * A hyperlink detector tries to find a hyperlink at
20
 * a given location in a given text viewer.
20
 * a given location in a given text viewer.
21
 * <p>
21
 * <p>
22
 * In order to provide backward compatibility for clients of <code>IHyperlinkDetector</code>, extension
23
 * interfaces are used to provide a means of evolution. The following extension interfaces exist:
24
 * <ul>
25
 * <li>{@link IHyperlinkDetectorExtension} since version 3.3,
26
 * 		adds the ability to dispose a hyperlink detector
27
 * </li>
28
 * </ul></p>
29
 * <p>
22
 * Clients may implement this interface.
30
 * Clients may implement this interface.
23
 * </p>
31
 * </p>
24
 *
32
 *
(-)src/org/eclipse/jface/text/TextViewer.java (+8 lines)
Lines 64-69 Link Here
64
64
65
import org.eclipse.jface.text.hyperlink.HyperlinkManager;
65
import org.eclipse.jface.text.hyperlink.HyperlinkManager;
66
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
66
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
67
import org.eclipse.jface.text.hyperlink.IHyperlinkDetectorExtension;
67
import org.eclipse.jface.text.hyperlink.IHyperlinkPresenter;
68
import org.eclipse.jface.text.hyperlink.IHyperlinkPresenter;
68
import org.eclipse.jface.text.projection.ChildDocument;
69
import org.eclipse.jface.text.projection.ChildDocument;
69
import org.eclipse.jface.text.projection.ChildDocumentManager;
70
import org.eclipse.jface.text.projection.ChildDocumentManager;
Lines 5253-5258 Link Here
5253
	 * @since 3.1
5254
	 * @since 3.1
5254
	 */
5255
	 */
5255
	public void setHyperlinkDetectors(IHyperlinkDetector[] hyperlinkDetectors, int eventStateMask) {
5256
	public void setHyperlinkDetectors(IHyperlinkDetector[] hyperlinkDetectors, int eventStateMask) {
5257
		if (fHyperlinkDetectors != null) {
5258
			for (int i= 0; i < fHyperlinkDetectors.length; i++) {
5259
				if (fHyperlinkDetectors[i] instanceof IHyperlinkDetectorExtension)
5260
					((IHyperlinkDetectorExtension)fHyperlinkDetectors[i]).dispose();
5261
			}
5262
		}
5263
		
5256
		boolean enable= hyperlinkDetectors != null && hyperlinkDetectors.length > 0;
5264
		boolean enable= hyperlinkDetectors != null && hyperlinkDetectors.length > 0;
5257
		fHyperlinkStateMask= eventStateMask;
5265
		fHyperlinkStateMask= eventStateMask;
5258
		fHyperlinkDetectors= hyperlinkDetectors;
5266
		fHyperlinkDetectors= hyperlinkDetectors;
(-)src/org/eclipse/jface/text/hyperlink/IHyperlinkDetectorExtension.java (+26 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jface.text.hyperlink;
12
13
/**
14
 * Extends {@link IHyperlinkDetector} with ability
15
 * to dispose a hyperlink detector.
16
 * 
17
 * @since 3.3
18
 */
19
public interface IHyperlinkDetectorExtension {
20
21
	/**
22
	 * Disposes this hyperlink detector.
23
	 */
24
	void dispose();
25
26
}
(-)src/org/eclipse/jface/text/hyperlink/AbstractHyperlinkDetector.java (+75 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jface.text.hyperlink;
12
13
import org.eclipse.core.runtime.Assert;
14
import org.eclipse.core.runtime.IAdaptable;
15
16
17
/**
18
 * A hyperlink detector that can provide adapters through
19
 * a context that can be set by the creator of this hyperlink
20
 * detector.
21
 * <p>
22
 * Clients may implement this interface.
23
 * </p>
24
 * <p>
25
 * <em>This API is provisional and may change any time before the 3.3 API freeze.</em>
26
 * </p>
27
 * 
28
 * @since 3.3
29
 */
30
public abstract class AbstractHyperlinkDetector implements IHyperlinkDetector, IHyperlinkDetectorExtension {
31
32
	/**
33
	 * The context of this hyperlink detector.
34
	 */
35
	private IAdaptable fContext;
36
37
	/**
38
	 * Sets this hyperlink detector's context which
39
	 * is responsible to provide the adapters.
40
	 * 
41
	 * @param context the context for this hyperlink detector
42
	 * @throws IllegalArgumentException if the context is <code>null</code>
43
	 * @throws IllegalStateException if this method is called more than once
44
	 */
45
	public final void setContext(IAdaptable context) throws IllegalStateException, IllegalArgumentException {
46
		Assert.isLegal(context != null);
47
		if (fContext != null)
48
			throw new IllegalStateException();
49
		fContext= context;
50
	}
51
52
	/*
53
	 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetectorExtension#dispose()
54
	 */
55
	public void dispose() {
56
		fContext= null;
57
	}
58
59
	/**
60
	 * Returns an object which is an instance of the given class
61
	 * and provides additional context for this hyperlink detector.
62
	 *
63
	 * @param adapterClass the adapter class to look up
64
	 * @return an instance that can be cast to the given class, 
65
	 *			or <code>null</code> if this object does not
66
	 *			have an adapter for the given class
67
	 */
68
	protected final Object getAdapter(Class adapterClass) {
69
		Assert.isLegal(adapterClass != null);
70
		if (fContext != null)
71
			return fContext.getAdapter(adapterClass);
72
		return null;
73
	}
74
75
}

Return to bug 88293