Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Dos Santos2013-12-16 16:55:32 -0500
committerGerrit Code Review @ Eclipse.org2014-01-21 16:11:33 -0500
commit2ee34447ece6defdc170aea9168145894465dce7 (patch)
treea514aa0b87b1763d6219cb7b734c4631053c4f03
parentf6291e4a1d8816da3f33e9241294dd0102b74e28 (diff)
downloadorg.eclipse.mylyn.tasks-2ee34447ece6defdc170aea9168145894465dce7.tar.gz
org.eclipse.mylyn.tasks-2ee34447ece6defdc170aea9168145894465dce7.tar.xz
org.eclipse.mylyn.tasks-2ee34447ece6defdc170aea9168145894465dce7.zip
424188: Task attributes that set META_ATTRIBUTE_MEDIA_TYPE should be
displayed with the correct markup viewer when available. Change-Id: Iad8f6f1070d6572702c9e5f71aaebcb8c91e776d Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=424188 Signed-off-by: Leo Dos Santos <leo.dos.santos@tasktop.com>
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMetaData.java22
-rw-r--r--org.eclipse.mylyn.tasks.tests/plugin.xml13
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java2
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/MockTextileEditorExtension.java44
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/MockWikiEditorExtension.java43
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/TaskEditorExtensionsTest.java95
-rw-r--r--org.eclipse.mylyn.tasks.ui/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorExtensions.java42
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorFactory.java3
9 files changed, 265 insertions, 2 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMetaData.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMetaData.java
index ee3b0f599..2a5b0cd52 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMetaData.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMetaData.java
@@ -107,6 +107,14 @@ public class TaskAttributeMetaData {
return Boolean.parseBoolean(taskAttribute.getMetaDatum(TaskAttribute.META_REQUIRED));
}
+ /**
+ * @since 3.11
+ * @see TaskAttribute#META_ATTRIBUTE_MEDIA_TYPE
+ */
+ public String getMediaType() {
+ return taskAttribute.getMetaDatum(TaskAttribute.META_ATTRIBUTE_MEDIA_TYPE);
+ }
+
public TaskAttributeMetaData putValue(String key, String value) {
taskAttribute.putMetaDatum(key, value);
return this;
@@ -192,4 +200,18 @@ public class TaskAttributeMetaData {
return this;
}
+ /**
+ * @since 3.11
+ * @see TaskAttribute#META_ATTRIBUTE_MEDIA_TYPE
+ * @return this
+ */
+ public TaskAttributeMetaData setMediaType(String value) {
+ if (value != null) {
+ taskAttribute.putMetaDatum(TaskAttribute.META_ATTRIBUTE_MEDIA_TYPE, value);
+ } else {
+ taskAttribute.removeMetaDatum(TaskAttribute.META_ATTRIBUTE_MEDIA_TYPE);
+ }
+ return this;
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.tests/plugin.xml b/org.eclipse.mylyn.tasks.tests/plugin.xml
index a2c0b0b6c..8618babff 100644
--- a/org.eclipse.mylyn.tasks.tests/plugin.xml
+++ b/org.eclipse.mylyn.tasks.tests/plugin.xml
@@ -226,5 +226,18 @@
</adapter>
</factory>
</extension>
+ <extension
+ point="org.eclipse.mylyn.tasks.ui.taskEditorExtensions">
+ <taskEditorExtension
+ class="org.eclipse.mylyn.tasks.tests.ui.editor.MockWikiEditorExtension"
+ id="org.eclipse.mylyn.tasks.tests.editor.mock.wiki"
+ name="MockWiki">
+ </taskEditorExtension>
+ <taskEditorExtension
+ class="org.eclipse.mylyn.tasks.tests.ui.editor.MockTextileEditorExtension"
+ id="org.eclipse.mylyn.tasks.tests.editor.mock.textile"
+ name="MockTextile">
+ </taskEditorExtension>
+ </extension>
</plugin>
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
index 88730ef7f..176d26f7f 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
@@ -43,6 +43,7 @@ import org.eclipse.mylyn.tasks.tests.ui.TaskListSynchronizationSchedulerTest;
import org.eclipse.mylyn.tasks.tests.ui.TaskListViewTest;
import org.eclipse.mylyn.tasks.tests.ui.TaskRelationHyperlinkDetectorTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.AttachmentTableLabelProviderTest;
+import org.eclipse.mylyn.tasks.tests.ui.editor.TaskEditorExtensionsTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.EditorUtilTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.PlanningPartTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.RegionComparatorTest;
@@ -162,6 +163,7 @@ public class AllTasksTests {
suite.addTestSuite(RepositoryConnectorContributorTest.class);
suite.addTestSuite(TaskInitializationDataTest.class);
suite.addTestSuite(TaskDataDiffTest.class);
+ suite.addTestSuite(TaskEditorExtensionsTest.class);
}
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/MockTextileEditorExtension.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/MockTextileEditorExtension.java
new file mode 100644
index 000000000..268ab0fcc
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/MockTextileEditorExtension.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.tasks.tests.ui.editor;
+
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorExtension;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * @author Leo Dos Santos
+ */
+public class MockTextileEditorExtension extends AbstractTaskEditorExtension {
+
+ @Deprecated
+ @Override
+ public SourceViewer createViewer(TaskRepository taskRepository, Composite parent, int style) {
+ // ignore
+ return null;
+ }
+
+ @Deprecated
+ @Override
+ public SourceViewer createEditor(TaskRepository taskRepository, Composite parent, int style) {
+ // ignore
+ return null;
+ }
+
+ @Override
+ public String getEditorContextId() {
+ // ignore
+ return null;
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/MockWikiEditorExtension.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/MockWikiEditorExtension.java
new file mode 100644
index 000000000..89ab58d35
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/MockWikiEditorExtension.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.tasks.tests.ui.editor;
+
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorExtension;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * @author Leo Dos Santos
+ */
+public class MockWikiEditorExtension extends AbstractTaskEditorExtension {
+
+ @Deprecated
+ @Override
+ public SourceViewer createViewer(TaskRepository taskRepository, Composite parent, int style) {
+ return null;
+ }
+
+ @Deprecated
+ @Override
+ public SourceViewer createEditor(TaskRepository taskRepository, Composite parent, int style) {
+ // ignore
+ return null;
+ }
+
+ @Override
+ public String getEditorContextId() {
+ // ignore
+ return null;
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/TaskEditorExtensionsTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/TaskEditorExtensionsTest.java
new file mode 100644
index 000000000..f752f4140
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/TaskEditorExtensionsTest.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.tasks.tests.ui.editor;
+
+import junit.framework.TestCase;
+
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorExtensions;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorExtension;
+
+/**
+ * @author Leo Dos Santos
+ */
+public class TaskEditorExtensionsTest extends TestCase {
+
+ private static final String ID_TEXTILE_EXTENSION = "org.eclipse.mylyn.tasks.tests.editor.mock.textile";
+
+ private TaskRepository repository;
+
+ private TaskData taskData;
+
+ @Override
+ protected void setUp() throws Exception {
+ repository = new TaskRepository(MockRepositoryConnector.CONNECTOR_KIND, MockRepositoryConnector.REPOSITORY_URL);
+ TasksUiPlugin.getRepositoryManager().addRepository(repository);
+ taskData = new TaskData(new TaskAttributeMapper(repository), MockRepositoryConnector.CONNECTOR_KIND,
+ MockRepositoryConnector.REPOSITORY_URL, "taskId");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TasksUiPlugin.getRepositoryManager().removeRepository(repository);
+ }
+
+ public void testMarkupAssociationFromRepository() {
+ TaskEditorExtensions.setTaskEditorExtensionId(repository, ID_TEXTILE_EXTENSION);
+ TaskAttribute attribute = taskData.getRoot().createMappedAttribute(TaskAttribute.DESCRIPTION);
+ AbstractTaskEditorExtension extension = TaskEditorExtensions.getTaskEditorExtension(repository, attribute);
+ assertTrue(extension instanceof MockTextileEditorExtension);
+ }
+
+ public void testMarkupAssociationFromAttribute() {
+ TaskEditorExtensions.setTaskEditorExtensionId(repository, "none");
+ TaskAttribute attribute = taskData.getRoot().createMappedAttribute(TaskAttribute.DESCRIPTION);
+ attribute.getMetaData().setMediaType("text/plain; markup=MockWiki");
+ AbstractTaskEditorExtension extension = TaskEditorExtensions.getTaskEditorExtension(repository, attribute);
+ assertTrue(extension instanceof MockWikiEditorExtension);
+ }
+
+ public void testMarkupAssociationFromBoth() {
+ TaskEditorExtensions.setTaskEditorExtensionId(repository, ID_TEXTILE_EXTENSION);
+ TaskAttribute attribute = taskData.getRoot().createMappedAttribute(TaskAttribute.DESCRIPTION);
+ attribute.getMetaData().setMediaType("text/plain; markup=MockWiki");
+ AbstractTaskEditorExtension extension = TaskEditorExtensions.getTaskEditorExtension(repository, attribute);
+ assertTrue(extension instanceof MockWikiEditorExtension);
+ }
+
+ public void testMarkupAssociationComplexMediaType() {
+ TaskEditorExtensions.setTaskEditorExtensionId(repository, ID_TEXTILE_EXTENSION);
+ TaskAttribute attribute = taskData.getRoot().createMappedAttribute(TaskAttribute.DESCRIPTION);
+ attribute.getMetaData().setMediaType("text/plain; markup=MockWiki; charset=iso-8859-1");
+ AbstractTaskEditorExtension extension = TaskEditorExtensions.getTaskEditorExtension(repository, attribute);
+ assertTrue(extension instanceof MockWikiEditorExtension);
+ }
+
+ public void testMarkupAssociationNotMarkupMediaType() {
+ TaskEditorExtensions.setTaskEditorExtensionId(repository, ID_TEXTILE_EXTENSION);
+ TaskAttribute attribute = taskData.getRoot().createMappedAttribute(TaskAttribute.DESCRIPTION);
+ attribute.getMetaData().setMediaType("text/plain; notreallyamarkup=MockWiki");
+ AbstractTaskEditorExtension extension = TaskEditorExtensions.getTaskEditorExtension(repository, attribute);
+ assertTrue(extension instanceof MockTextileEditorExtension);
+ }
+
+ public void testMarkupAssociationNoAssociation() {
+ TaskEditorExtensions.setTaskEditorExtensionId(repository, "none");
+ TaskAttribute attribute = taskData.getRoot().createMappedAttribute(TaskAttribute.DESCRIPTION);
+ AbstractTaskEditorExtension extension = TaskEditorExtensions.getTaskEditorExtension(repository, attribute);
+ assertNull(extension);
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.ui/META-INF/MANIFEST.MF
index cc1abb518..9ae5082bb 100644
--- a/org.eclipse.mylyn.tasks.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.tasks.ui/META-INF/MANIFEST.MF
@@ -31,7 +31,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.mylyn.commons.workbench;bundle-version="3.8.0",
org.eclipse.mylyn.monitor.core;bundle-version="3.8.0",
org.eclipse.mylyn.monitor.ui;bundle-version="3.8.0",
- org.eclipse.mylyn.tasks.core;bundle-version="3.8.0"
+ org.eclipse.mylyn.tasks.core;bundle-version="3.8.0",
+ com.google.guava;bundle-version="12.0.0"
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %Bundle-Vendor
Export-Package: org.eclipse.mylyn.internal.provisional.tasks.ui.wizards;x-internal:=true,
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorExtensions.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorExtensions.java
index 5b2c06db3..50d069cff 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorExtensions.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorExtensions.java
@@ -12,6 +12,7 @@
package org.eclipse.mylyn.internal.tasks.ui.editors;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -22,10 +23,14 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorExtension;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
import org.eclipse.ui.IPluginContribution;
+import com.google.common.collect.Multimap;
+import com.google.common.net.MediaType;
+
/**
* @author David Green
*/
@@ -35,6 +40,8 @@ public class TaskEditorExtensions {
public static final String REPOSITORY_PROPERTY_AVATAR_SUPPORT = "avatarSupport"; //$NON-NLS-1$
+ private static final String MARKUP_KEY = "markup"; //$NON-NLS-1$
+
private static Map<String, RegisteredTaskEditorExtension> extensionsById = new HashMap<String, RegisteredTaskEditorExtension>();
private static Map<String, String> associationByConnectorKind = new HashMap<String, String>();
@@ -99,6 +106,41 @@ public class TaskEditorExtensions {
return null;
}
+ /**
+ * get a task editor extension for a specific task attribute
+ *
+ * @param taskRepository
+ * @param taskAttribute
+ * @return the extension, or null if there is none
+ * @see #getTaskEditorExtension(TaskRepository);
+ * @since 3.11
+ */
+ public static AbstractTaskEditorExtension getTaskEditorExtension(TaskRepository taskRepository,
+ TaskAttribute taskAttribute) {
+ init();
+ String input = taskAttribute.getMetaData().getMediaType();
+ if (input != null) {
+ try {
+ MediaType media = MediaType.parse(input);
+ Multimap<String, String> parameters = media.parameters();
+ if (parameters.containsKey(MARKUP_KEY)) {
+ Iterator<String> iter = parameters.get(MARKUP_KEY).iterator();
+ String markup = iter.next();
+ SortedSet<RegisteredTaskEditorExtension> extensions = getTaskEditorExtensions();
+ for (RegisteredTaskEditorExtension extension : extensions) {
+ if (markup.equals(extension.getName())) {
+ return extension.getExtension();
+ }
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, String.format(
+ "Unable to parse markup type for attribute %s", taskAttribute.toString()), e)); //$NON-NLS-1$
+ }
+ }
+ return getTaskEditorExtension(taskRepository);
+ }
+
public static String getTaskEditorExtensionId(TaskRepository taskRepository) {
init();
String id = taskRepository.getProperty(REPOSITORY_PROPERTY_EDITOR_EXTENSION);
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorFactory.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorFactory.java
index 369aae159..040ba78dc 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorFactory.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorFactory.java
@@ -101,7 +101,8 @@ public class AttributeEditorFactory {
if (serviceLocator != null) {
IContextService contextService = (IContextService) serviceLocator.getService(IContextService.class);
if (contextService != null) {
- AbstractTaskEditorExtension extension = TaskEditorExtensions.getTaskEditorExtension(model.getTaskRepository());
+ AbstractTaskEditorExtension extension = TaskEditorExtensions.getTaskEditorExtension(
+ model.getTaskRepository(), taskAttribute);
if (extension != null) {
editor = new RichTextAttributeEditor(model, taskRepository, taskAttribute, SWT.MULTI,
contextService, extension);

Back to the top