summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2012-02-04 13:36:24 (EST)
committer Steffen Pingel2012-02-04 13:37:37 (EST)
commitddf3e859c612e9f33e23d6fa42e86c0a13056503 (patch)
tree5f1cf89caf2a1baead668ee5a90d3bb9d890b5b3
parent36af7097778ad8c52c7b213204b610315741aecb (diff)
downloadorg.eclipse.mylyn.tasks-ddf3e859c612e9f33e23d6fa42e86c0a13056503.zip
org.eclipse.mylyn.tasks-ddf3e859c612e9f33e23d6fa42e86c0a13056503.tar.gz
org.eclipse.mylyn.tasks-ddf3e859c612e9f33e23d6fa42e86c0a13056503.tar.bz2
NEW - bug 370504: register URL handler for opening tasks in rich editor
https://bugs.eclipse.org/bugs/show_bug.cgi?id=370504 Change-Id: I1990e3f5d5f9cbae235cd5d8ed76a7a40bb3a0af
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/TaskUrlHyperlinkDetectorTest.java18
-rw-r--r--org.eclipse.mylyn.tasks.ui/plugin.xml7
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskUrlHandler.java63
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/BrowserPreviewViewer.java7
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskUrlHyperlink.java3
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskUrlHyperlinkDetector.java7
6 files changed, 88 insertions, 17 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/TaskUrlHyperlinkDetectorTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/TaskUrlHyperlinkDetectorTest.java
index d043987..6fa275a 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/TaskUrlHyperlinkDetectorTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/TaskUrlHyperlinkDetectorTest.java
@@ -22,8 +22,8 @@ import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.mylyn.commons.workbench.browser.UrlHyperlink;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
-import org.eclipse.mylyn.internal.tasks.ui.editors.TaskUrlHyperlink;
import org.eclipse.mylyn.internal.tasks.ui.editors.TaskUrlHyperlinkDetector;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.tests.TaskTestUtil;
@@ -63,7 +63,7 @@ public class TaskUrlHyperlinkDetectorTest extends TestCase {
IHyperlink[] links = detect("http://foo", 0, 0);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals("http://foo", ((TaskUrlHyperlink) links[0]).getURLString());
+ assertEquals("http://foo", ((UrlHyperlink) links[0]).getURLString());
}
public void testInvalidUrl() {
@@ -81,39 +81,39 @@ public class TaskUrlHyperlinkDetectorTest extends TestCase {
IHyperlink[] links = detect("(http://foo)", 2, 0);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals("http://foo", ((TaskUrlHyperlink) links[0]).getURLString());
+ assertEquals("http://foo", ((UrlHyperlink) links[0]).getURLString());
links = detect("( http://foo)", 2, 0);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals("http://foo", ((TaskUrlHyperlink) links[0]).getURLString());
+ assertEquals("http://foo", ((UrlHyperlink) links[0]).getURLString());
links = detect("( http://foo).", 2, 0);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals("http://foo", ((TaskUrlHyperlink) links[0]).getURLString());
+ assertEquals("http://foo", ((UrlHyperlink) links[0]).getURLString());
}
public void testClosingParenthesis() {
IHyperlink[] links = detect("http://foo?(bar)", 0, 0);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals("http://foo?(bar)", ((TaskUrlHyperlink) links[0]).getURLString());
+ assertEquals("http://foo?(bar)", ((UrlHyperlink) links[0]).getURLString());
links = detect("(http://foo?(bar))", 0, 18);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals("http://foo?(bar)", ((TaskUrlHyperlink) links[0]).getURLString());
+ assertEquals("http://foo?(bar)", ((UrlHyperlink) links[0]).getURLString());
links = detect("http://foo?((((bar).", 0, 0);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals("http://foo?((((bar)", ((TaskUrlHyperlink) links[0]).getURLString());
+ assertEquals("http://foo?((((bar)", ((UrlHyperlink) links[0]).getURLString());
links = detect("http://foo?(bar))))))))", 0, 0);
assertNotNull(links);
assertEquals(1, links.length);
- assertEquals("http://foo?(bar)", ((TaskUrlHyperlink) links[0]).getURLString());
+ assertEquals("http://foo?(bar)", ((UrlHyperlink) links[0]).getURLString());
}
public void testDetectionUsingExtent() {
diff --git a/org.eclipse.mylyn.tasks.ui/plugin.xml b/org.eclipse.mylyn.tasks.ui/plugin.xml
index 754afad..2f9ac42 100644
--- a/org.eclipse.mylyn.tasks.ui/plugin.xml
+++ b/org.eclipse.mylyn.tasks.ui/plugin.xml
@@ -2357,5 +2357,12 @@
</enabledWhen>
</handler>
</extension>
+ <extension
+ point="org.eclipse.mylyn.commons.workbench.urlHandlers">
+ <handler
+ class="org.eclipse.mylyn.internal.tasks.ui.TaskUrlHandler"
+ id="org.eclipse.mylyn.tasks.ui.urlHandler.TaskUrlHandler">
+ </handler>
+ </extension>
</plugin>
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskUrlHandler.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskUrlHandler.java
new file mode 100644
index 0000000..6f619c8
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskUrlHandler.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.ui;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.mylyn.commons.workbench.EditorHandle;
+import org.eclipse.mylyn.commons.workbench.browser.AbstractUrlHandler;
+import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
+import org.eclipse.mylyn.internal.tasks.core.LocalTask;
+import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.ui.TasksUi;
+import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
+import org.eclipse.ui.IWorkbenchPage;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TaskUrlHandler extends AbstractUrlHandler {
+
+ public TaskUrlHandler() {
+ // ignore
+ }
+
+ @Override
+ public EditorHandle openUrl(IWorkbenchPage page, String url, int customFlags) {
+ Assert.isNotNull(url);
+ AbstractTask task = TasksUiInternal.getTaskByUrl(url);
+ if (task != null && !(task instanceof LocalTask)) {
+ TaskRepository repository = TasksUi.getRepositoryManager().getRepository(task.getConnectorKind(),
+ task.getRepositoryUrl());
+ return TasksUiUtil.openTaskWithResult(repository, task.getTaskId());
+ } else {
+ AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager()
+ .getConnectorForRepositoryTaskUrl(url);
+ if (connector != null) {
+ String repositoryUrl = connector.getRepositoryUrlFromTaskUrl(url);
+ if (repositoryUrl != null) {
+ String id = connector.getTaskIdFromTaskUrl(url);
+ if (id != null) {
+ TaskRepository repository = TasksUi.getRepositoryManager().getRepository(
+ connector.getConnectorKind(), repositoryUrl);
+ if (repository != null) {
+ return TasksUiUtil.openTaskWithResult(repository, id);
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/BrowserPreviewViewer.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/BrowserPreviewViewer.java
index 39320ea..cba02b5 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/BrowserPreviewViewer.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/BrowserPreviewViewer.java
@@ -20,8 +20,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.mylyn.commons.workbench.browser.BrowserUtil;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
import org.eclipse.mylyn.tasks.core.RepositoryStatus;
@@ -68,9 +67,7 @@ public class BrowserPreviewViewer {
if (event.location != null && !event.location.startsWith("about")) { //$NON-NLS-1$
event.doit = false;
- IHyperlink link = new TaskUrlHyperlink(
- new Region(0, 0)/* a fake region just to make constructor happy */, event.location);
- link.open();
+ BrowserUtil.openUrl(event.location);
}
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskUrlHyperlink.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskUrlHyperlink.java
index 16a3849..30fabed 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskUrlHyperlink.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskUrlHyperlink.java
@@ -13,12 +13,15 @@ package org.eclipse.mylyn.internal.tasks.ui.editors;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.hyperlink.URLHyperlink;
+import org.eclipse.mylyn.commons.workbench.browser.UrlHyperlink;
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
import org.eclipse.osgi.util.NLS;
/**
* @author Rob Elves
+ * @deprecated use {@link UrlHyperlink} instead
*/
+@Deprecated
public class TaskUrlHyperlink extends URLHyperlink {
private final String hyperlinkText;
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskUrlHyperlinkDetector.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskUrlHyperlinkDetector.java
index 59dd7da..b760488 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskUrlHyperlinkDetector.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskUrlHyperlinkDetector.java
@@ -23,6 +23,7 @@ import java.util.regex.Pattern;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.mylyn.commons.workbench.browser.UrlHyperlink;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.ui.AbstractTaskHyperlinkDetector;
@@ -56,7 +57,7 @@ public class TaskUrlHyperlinkDetector extends AbstractTaskHyperlinkDetector {
while (m.find()) {
if (isInRegion(indexInContent, m)) {
String urlString = getUrlString(content, m);
- TaskUrlHyperlink link = null;
+ IHyperlink link = null;
if (getAdapter(TaskRepository.class) != null) {
try {
new URL(urlString);
@@ -104,8 +105,8 @@ public class TaskUrlHyperlinkDetector extends AbstractTaskHyperlinkDetector {
return (offsetInText == -1) || (offsetInText >= m.start() && offsetInText <= m.end());
}
- private static TaskUrlHyperlink createTaskUrlHyperlink(int textOffset, Matcher m, String urlString) {
- return new TaskUrlHyperlink(new Region(textOffset + m.start(), urlString.length()), urlString);
+ private static IHyperlink createTaskUrlHyperlink(int textOffset, Matcher m, String urlString) {
+ return new UrlHyperlink(new Region(textOffset + m.start(), urlString.length()), urlString);
}
}