Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2007-03-08 00:39:53 -0500
committerspingel2007-03-08 00:39:53 -0500
commitf9f43cca24f42cad79e3643e6e479e32a194fa4f (patch)
treeb099cb9c9aa293c019d5f36edb54fb45f2dbf72a
parentdaf99fc6225a98197fac5e7ee8e10ff8efeb18e0 (diff)
downloadorg.eclipse.mylyn.tasks-f9f43cca24f42cad79e3643e6e479e32a194fa4f.tar.gz
org.eclipse.mylyn.tasks-f9f43cca24f42cad79e3643e6e479e32a194fa4f.tar.xz
org.eclipse.mylyn.tasks-f9f43cca24f42cad79e3643e6e479e32a194fa4f.zip
NEW - bug 176566: Hyperlinking support for Trac
https://bugs.eclipse.org/bugs/show_bug.cgi?id=176566
-rw-r--r--org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkDetectorTest.java37
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java3
-rw-r--r--org.eclipse.mylyn.trac.ui/META-INF/MANIFEST.MF6
-rw-r--r--org.eclipse.mylyn.trac.ui/plugin.xml9
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TaskHyperlink.java57
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkDetector.java119
7 files changed, 233 insertions, 2 deletions
diff --git a/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF
index 48ba04ca3..c32d1a5e2 100644
--- a/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF
@@ -13,7 +13,9 @@ Require-Bundle: org.junit,
org.eclipse.mylar.trac.ui,
org.eclipse.mylar.trac.core,
org.eclipse.search,
- org.eclipse.mylar
+ org.eclipse.mylar,
+ org.eclipse.ui.workbench.texteditor,
+ org.eclipse.jface.text
Export-Package: org.eclipse.mylar.trac.tests
Bundle-Activator: org.eclipse.mylar.trac.tests.TracTestPlugin
Eclipse-LazyStart: true
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkDetectorTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkDetectorTest.java
new file mode 100644
index 000000000..77d3db6c9
--- /dev/null
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkDetectorTest.java
@@ -0,0 +1,37 @@
+package org.eclipse.mylar.internal.trac.ui;
+
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.mylar.internal.trac.core.TracCorePlugin;
+import org.eclipse.mylar.tasks.core.TaskRepository;
+
+import junit.framework.TestCase;
+
+public class TracHyperlinkDetectorTest extends TestCase {
+
+ private TracHyperlinkDetector detector;
+ private TaskRepository repository;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ repository = new TaskRepository(TracCorePlugin.REPOSITORY_KIND, "http://localhost/");
+ detector = new TracHyperlinkDetector();
+ }
+
+ public void testFindHyperlinks1() {
+ IHyperlink[] links = detector.findHyperlinks(repository, "#11", 0, 0);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertTrue(links[0].getHyperlinkText().endsWith(" 11"));
+ }
+
+// public void testFindHyperlinks2() {
+// IHyperlink[] links = detector.findHyperlinks(repository, "#11, #1", 0, 0);
+// assertNotNull(links);
+// assertEquals(2, links.length);
+// assertTrue(links[0].getHyperlinkText().endsWith(" 11"));
+// assertTrue(links[0].getHyperlinkText().endsWith(" 1"));
+// }
+
+}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java
index d137a714f..1ad703b3f 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java
@@ -14,6 +14,8 @@ package org.eclipse.mylar.trac.tests;
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.eclipse.mylar.internal.trac.ui.TracHyperlinkDetectorTest;
+
/**
* @author Mik Kersten
* @author Steffen Pingel
@@ -44,6 +46,7 @@ public class AllTracTests {
suite.addTestSuite(TracQueryHitTest.class);
suite.addTestSuite(TracRepositorySettingsPageTest.class);
suite.addTestSuite(TracClientProxyTest.class);
+ suite.addTestSuite(TracHyperlinkDetectorTest.class);
// $JUnit-END$
return suite;
}
diff --git a/org.eclipse.mylyn.trac.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.trac.ui/META-INF/MANIFEST.MF
index 599821e18..6c437246f 100644
--- a/org.eclipse.mylyn.trac.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.trac.ui/META-INF/MANIFEST.MF
@@ -13,7 +13,11 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.mylar.tasks.core,
org.eclipse.search,
org.eclipse.mylar.trac.core,
- org.eclipse.mylar
+ org.eclipse.mylar,
+ org.eclipse.ui.editors,
+ org.eclipse.jface.text,
+ org.eclipse.core.resources,
+ org.eclipse.ui.workbench.texteditor
Eclipse-LazyStart: true
Export-Package: org.eclipse.mylar.internal.trac.ui,
org.eclipse.mylar.internal.trac.ui.editor,
diff --git a/org.eclipse.mylyn.trac.ui/plugin.xml b/org.eclipse.mylyn.trac.ui/plugin.xml
index 59e3b57f0..44dc5f551 100644
--- a/org.eclipse.mylyn.trac.ui/plugin.xml
+++ b/org.eclipse.mylyn.trac.ui/plugin.xml
@@ -34,5 +34,14 @@
point="org.eclipse.mylar.tasks.ui.editors">
<editorFactory class="org.eclipse.mylar.internal.trac.ui.editor.TracTaskEditorFactory"/>
</extension>
+ <extension
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
+ <hyperlinkDetector
+ class="org.eclipse.mylar.internal.trac.ui.TracHyperlinkDetector"
+ id="org.eclipse.mylar.jira.ui.hyperlinkdetector"
+ name="Mylar Task"
+ targetId="org.eclipse.jdt.ui.javaCode">
+ </hyperlinkDetector>
+ </extension>
</plugin>
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TaskHyperlink.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TaskHyperlink.java
new file mode 100644
index 000000000..2bbbc1aa6
--- /dev/null
+++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TaskHyperlink.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 University Of British Columbia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * University Of British Columbia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylar.internal.trac.ui;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.mylar.tasks.core.TaskRepository;
+import org.eclipse.mylar.tasks.ui.TasksUiUtil;
+
+/**
+ * @author Eugene Kuleshov
+ * @author Steffen Pingel
+ */
+public class TaskHyperlink implements IHyperlink {
+
+ private final IRegion region;
+
+ private final TaskRepository repository;
+
+ private final String key;
+
+ public TaskHyperlink(IRegion region, TaskRepository repository, String key) {
+ this.region = region;
+ this.repository = repository;
+ this.key = key;
+ }
+
+ public IRegion getHyperlinkRegion() {
+ return region;
+ }
+
+ public String getTypeLabel() {
+ return null;
+ }
+
+ public String getHyperlinkText() {
+ return "Open Task " + key;
+ }
+
+ public void open() {
+ if (repository != null) {
+ TasksUiUtil.openRepositoryTask(repository, key);
+ } else {
+ MessageDialog.openError(null, "Mylar", "Could not determine repository for report");
+ }
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkDetector.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkDetector.java
new file mode 100644
index 000000000..bab01538f
--- /dev/null
+++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkDetector.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+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.Region;
+import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+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 Steffen Pingel
+ */
+public class TracHyperlinkDetector extends AbstractHyperlinkDetector {
+
+ Pattern taskPattern = Pattern.compile("#(\\d*)");
+
+ Pattern wikiPattern = Pattern.compile("\\[wiki:([^\\]*])\\]", Pattern.CASE_INSENSITIVE | Pattern.DOTALL
+ | Pattern.MULTILINE);
+
+ public TracHyperlinkDetector() {
+ }
+
+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
+ if (region == null || textViewer == null) {
+ return null;
+ }
+
+ TaskRepository repository = getRepository(textViewer);
+ if (repository == null) {
+ return null;
+ }
+
+ IDocument document = textViewer.getDocument();
+ if (document == null) {
+ return null;
+ }
+
+ IRegion lineInfo;
+ String line;
+ try {
+ lineInfo = document.getLineInformationOfOffset(region.getOffset());
+ line = document.get(lineInfo.getOffset(), lineInfo.getLength());
+ } catch (BadLocationException ex) {
+ return null;
+ }
+
+ // TracRepositoryUi connector = (TracRepositoryUi)
+ // TasksUiPlugin.getRepositoryUi(repository.getKind());
+ return findHyperlinks(repository, line, region.getOffset() - lineInfo.getOffset(), lineInfo.getOffset());
+ }
+
+ private TaskRepository getRepository(ITextViewer textViewer) {
+ if (textViewer instanceof RepositoryTextViewer) {
+ RepositoryTextViewer viewer = (RepositoryTextViewer) textViewer;
+ return viewer.getRepository();
+ } 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) {
+ return TasksUiPlugin.getDefault().getRepositoryForResource(resource, true);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Detects:
+ *
+ * <ul>
+ * <li>#taskid
+ * <li>[wiki:page]
+ * <li>WikiPage
+ * </ul>
+ *
+ * @param repository
+ * @param text
+ * @param region
+ * @return
+ */
+ public IHyperlink[] findHyperlinks(TaskRepository repository, String text, int lineOffset, int regionOffset) {
+ List<IHyperlink> links = new ArrayList<IHyperlink>();
+
+ Matcher m = taskPattern.matcher(text);
+ while (m.find()) {
+ String id = m.group(1);
+ if (lineOffset >= m.start() && lineOffset <= m.end()) {
+ IRegion linkRegion = new Region(regionOffset + m.start(), m.end() - m.start());
+ links.add(new TaskHyperlink(linkRegion, repository, id));
+ }
+ }
+
+ return links.isEmpty() ? null : links.toArray(new IHyperlink[0]);
+ }
+
+}

Back to the top