リビジョン | 123 (tree) |
---|---|
日時 | 2009-05-06 00:01:36 |
作者 | chomakichi |
HyperlinkDetectorを追加できる拡張ポイントを作成
@@ -1,13 +1,26 @@ | ||
1 | 1 | package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors; |
2 | 2 | |
3 | +import java.util.ArrayList; | |
4 | +import java.util.List; | |
5 | + | |
3 | 6 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.PropertiesEditorPlugin; |
4 | 7 | import jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.preference.PropertiesEditorPreference; |
5 | 8 | |
9 | +import org.eclipse.core.runtime.CoreException; | |
10 | +import org.eclipse.core.runtime.IConfigurationElement; | |
11 | +import org.eclipse.core.runtime.IExtension; | |
12 | +import org.eclipse.core.runtime.IExtensionPoint; | |
13 | +import org.eclipse.core.runtime.IExtensionRegistry; | |
14 | +import org.eclipse.core.runtime.ILog; | |
15 | +import org.eclipse.core.runtime.IStatus; | |
16 | +import org.eclipse.core.runtime.Platform; | |
17 | +import org.eclipse.core.runtime.Status; | |
6 | 18 | import org.eclipse.jface.preference.IPreferenceStore; |
7 | 19 | import org.eclipse.jface.preference.PreferenceConverter; |
8 | 20 | import org.eclipse.jface.text.IDocument; |
9 | 21 | import org.eclipse.jface.text.ITextDoubleClickStrategy; |
10 | 22 | import org.eclipse.jface.text.TextAttribute; |
23 | +import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; | |
11 | 24 | import org.eclipse.jface.text.presentation.IPresentationReconciler; |
12 | 25 | import org.eclipse.jface.text.presentation.PresentationReconciler; |
13 | 26 | import org.eclipse.jface.text.reconciler.IReconciler; |
@@ -19,6 +32,8 @@ | ||
19 | 32 | import org.eclipse.swt.graphics.RGB; |
20 | 33 | |
21 | 34 | public class PropertiesConfiguration extends SourceViewerConfiguration { |
35 | + | |
36 | + private static final String EXTENSION_POINT = "jp.gr.java_conf.ussiy.app.propedit.hyperlinkdetectors"; //$NON-NLS-1$ | |
22 | 37 | |
23 | 38 | private PropertiesDoubleClickStrategy doubleClickStrategy; |
24 | 39 |
@@ -96,5 +111,44 @@ | ||
96 | 111 | |
97 | 112 | return reconciler; |
98 | 113 | } |
114 | + | |
115 | + /** | |
116 | + * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getHyperlinkDetectors(org.eclipse.jface.text.source.ISourceViewer) | |
117 | + */ | |
118 | + public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer viewer) { | |
119 | + IHyperlinkDetector[] detectors = super.getHyperlinkDetectors(viewer); | |
120 | + List list = new ArrayList(); | |
121 | + for (int i = 0; i < detectors.length; i++) { | |
122 | + if (detectors[i] != null) list.add(detectors[i]); | |
123 | + } | |
124 | + list.addAll(computePropertiesHyperlinkDetectors()); | |
125 | + detectors = (IHyperlinkDetector[])list.toArray(new IHyperlinkDetector[0]); | |
126 | + return detectors; | |
127 | + } | |
128 | + | |
129 | + protected List computePropertiesHyperlinkDetectors() { | |
130 | + IExtensionRegistry registry = Platform.getExtensionRegistry(); | |
131 | + IExtensionPoint extensionPoint = registry.getExtensionPoint(EXTENSION_POINT); | |
132 | + IExtension[] extensions = extensionPoint.getExtensions(); | |
133 | + ArrayList results = new ArrayList(); | |
134 | + for (int i = 0; i < extensions.length; i++) { | |
135 | + IConfigurationElement[] elements = extensions[i].getConfigurationElements(); | |
136 | + for (int j = 0; j < elements.length; j++) { | |
137 | + try { | |
138 | + Object detector = elements[j].createExecutableExtension("class"); //$NON-NLS-1$ | |
139 | + if (detector instanceof jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.detector.IHyperlinkDetector) { | |
140 | + ((jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.detector.IHyperlinkDetector)detector).setTextEditor(editor); | |
141 | + results.add(detector); | |
142 | + } | |
143 | + } catch(CoreException e) { | |
144 | + IStatus status = new Status(IStatus.ERROR, PropertiesEditorPlugin.PLUGIN_ID, 0, e.getMessage(), e); | |
145 | + ILog log = PropertiesEditorPlugin.getDefault().getLog(); | |
146 | + log.log(status); | |
147 | + } | |
148 | + } | |
149 | + } | |
150 | + | |
151 | + return results; | |
152 | + } | |
99 | 153 | |
100 | 154 | } |
\ No newline at end of file |
@@ -0,0 +1,10 @@ | ||
1 | +package jp.gr.java_conf.ussiy.app.propedit.eclipse.plugin.editors.detector; | |
2 | + | |
3 | +import org.eclipse.ui.texteditor.ITextEditor; | |
4 | + | |
5 | +public interface IHyperlinkDetector extends | |
6 | + org.eclipse.jface.text.hyperlink.IHyperlinkDetector { | |
7 | + | |
8 | + public void setTextEditor(ITextEditor editor); | |
9 | + | |
10 | +} |
@@ -3,6 +3,7 @@ | ||
3 | 3 | <plugin> |
4 | 4 | |
5 | 5 | <extension-point id="listeners" name="Extension Unicode Convert" schema="schema/listeners.exsd"/> |
6 | + <extension-point id="hyperlinkdetectors" name="Extension Hyperlink Detector" schema="schema/hyperlinkdetectors.exsd"/> | |
6 | 7 | |
7 | 8 | <!-- Extensions --> |
8 | 9 | <!-- properties editor --> |