Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrelves2007-02-15 14:02:29 -0500
committerrelves2007-02-15 14:02:29 -0500
commitb1a50c64c835ee5c45cb3e31b081a1e4767bd0fe (patch)
tree243541c90dc941911749f08f9089d3247a5f4f16
parent4b0eddbf170e1bb166dd57a8ac89641540c2dfb2 (diff)
downloadorg.eclipse.mylyn.tasks-b1a50c64c835ee5c45cb3e31b081a1e4767bd0fe.tar.gz
org.eclipse.mylyn.tasks-b1a50c64c835ee5c45cb3e31b081a1e4767bd0fe.tar.xz
org.eclipse.mylyn.tasks-b1a50c64c835ee5c45cb3e31b081a1e4767bd0fe.zip
NEW - bug 170679: [api] improve hyperlink detection api
https://bugs.eclipse.org/bugs/show_bug.cgi?id=170679
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/plugin.xml9
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/BugzillaTaskHyperlinkDetector.java42
2 files changed, 39 insertions, 12 deletions
diff --git a/org.eclipse.mylyn.bugzilla.ui/plugin.xml b/org.eclipse.mylyn.bugzilla.ui/plugin.xml
index 08a473a56..c2c190f80 100644
--- a/org.eclipse.mylyn.bugzilla.ui/plugin.xml
+++ b/org.eclipse.mylyn.bugzilla.ui/plugin.xml
@@ -53,4 +53,13 @@
</description>
</decorator>
</extension>
+ <extension
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
+ <hyperlinkDetector
+ class="org.eclipse.mylar.internal.bugzilla.ui.BugzillaTaskHyperlinkDetector"
+ id="org.eclipse.mylar.bugzilla.ui.bugzillataskhyperlink"
+ name="Bugzilla Task"
+ targetId="org.eclipse.jdt.ui.javaCode">
+ </hyperlinkDetector>
+ </extension>
</plugin>
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/BugzillaTaskHyperlinkDetector.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/BugzillaTaskHyperlinkDetector.java
index 361ea2bd6..3ef0c2761 100644
--- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/BugzillaTaskHyperlinkDetector.java
+++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/BugzillaTaskHyperlinkDetector.java
@@ -11,19 +11,25 @@
package org.eclipse.mylar.internal.bugzilla.ui;
+import org.eclipse.core.resources.IResource;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
import org.eclipse.jface.text.hyperlink.IHyperlink;
-import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.mylar.tasks.core.TaskRepository;
+import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
import org.eclipse.mylar.tasks.ui.editors.RepositoryTextViewer;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
/**
* @author Rob Elves
*/
-public class BugzillaTaskHyperlinkDetector implements IHyperlinkDetector {
+public class BugzillaTaskHyperlinkDetector extends AbstractHyperlinkDetector {
+ // IHyperlinkDetector
private TaskRepository repository;
@@ -31,16 +37,28 @@ public class BugzillaTaskHyperlinkDetector implements IHyperlinkDetector {
if (region == null || textViewer == null)
return null;
- if (!(textViewer instanceof RepositoryTextViewer))
- return null;
-
- RepositoryTextViewer viewer = (RepositoryTextViewer) textViewer;
-
- repository = viewer.getRepository();
-
- if (repository == null)
- return null;
-
+ if (textViewer instanceof RepositoryTextViewer) {
+ // Get repository from repository text viewer
+ RepositoryTextViewer viewer = (RepositoryTextViewer) textViewer;
+
+ repository = viewer.getRepository();
+
+ if (repository == null)
+ return null;
+
+ } else {
+ // Get repository from files associated project -> repository mapping
+ IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ IEditorInput input = part.getEditorInput();
+ IResource resource = (IResource) input.getAdapter(IResource.class);
+ if (resource != null) {
+ repository = TasksUiPlugin.getDefault().getRepositoryForResource(resource, true);
+ if (repository == null) {
+ return null;
+ }
+ }
+ }
+
IDocument document = textViewer.getDocument();
int offset = region.getOffset();

Back to the top