diff options
author | Brandon Dong | 2016-06-06 18:11:43 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-06-08 18:10:36 +0000 |
commit | c7b61a4748ba0ca0687fef5563165c01cfde0dc3 (patch) | |
tree | 29c1290d2e2fd17499a143637f8a94c781a0673c | |
parent | 06987bc26647b3a2f7d0af591325daeb75acf4b9 (diff) | |
download | org.eclipse.mylyn.tasks-c7b61a4748ba0ca0687fef5563165c01cfde0dc3.tar.gz org.eclipse.mylyn.tasks-c7b61a4748ba0ca0687fef5563165c01cfde0dc3.tar.xz org.eclipse.mylyn.tasks-c7b61a4748ba0ca0687fef5563165c01cfde0dc3.zip |
436128: [api] connectors can provide the PriorityLevel for icons that
should be shown in PriorityEditor and tooltip uses priority
value label from taskdata
Change-Id: I7ab493f912fab6ec72ca3819b782467de122943a
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=436128
Signed-off-by: Brandon Dong <brandon.dong@tasktop.com>
7 files changed, 86 insertions, 21 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java index 2aba1c959..1682e2cd4 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java @@ -67,6 +67,8 @@ public interface ITasksCoreConstants { public static final String ATTRIBUTE_ARTIFACT = "org.eclipse.mylyn.is.artifact"; //$NON-NLS-1$ + public static final String ATTRIBUTE_PRIORITY_LABEL = "task.common.priority.label"; //$NON-NLS-1$ + /** * @deprecated Since Mylyn 3.11, all TaskRepositories store their credentials in the secure store. */ diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITask.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITask.java index 4c00e944a..759448d62 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITask.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITask.java @@ -75,7 +75,7 @@ public interface ITask extends IRepositoryElement, IAttributeContainer { /** * Defines an interface for priorities that have an associated integer value. - * + * * @author Steffen Pingel * @since 3.7 * @see PriorityLevel#fromValue(IPriorityValue[], IPriorityValue) @@ -205,11 +205,23 @@ public interface ITask extends IRepositoryElement, IAttributeContainer { } /** + * @since 3.20 + */ + public static boolean isValidPriority(String string) { + try { + PriorityLevel.valueOf(string); + return true; + } catch (IllegalArgumentException e) { + return false; + } + } + + /** * Maps a priority value to a {@link PriorityLevel}. The value needs to be present in <code>priorities</code>, * otherwise {@link PriorityLevel#getDefault()} is returned. * <p> * NOTE: <code>priorities</code> needs to be sorted in ascending order. - * + * * @param priorities * a sorted array of priority levels * @param value @@ -242,28 +254,28 @@ public interface ITask extends IRepositoryElement, IAttributeContainer { /** * Returns the date that the task was completed. - * + * * @since 3.0 */ public abstract Date getCompletionDate(); /** * Returns the identifier that uniquely distinguishes the repository connector associated with this task. - * + * * @since 3.0 */ public abstract String getConnectorKind(); /** * Returns the date that this task was created. - * + * * @since 3.0 */ public abstract Date getCreationDate(); /** * Returns the date after which this task will become overdue. - * + * * @since 3.0 */ public abstract Date getDueDate(); @@ -275,7 +287,7 @@ public interface ITask extends IRepositoryElement, IAttributeContainer { /** * Returns the date that the repository contents of this task were last modified. - * + * * @since 3.0 */ public abstract Date getModificationDate(); @@ -284,7 +296,7 @@ public interface ITask extends IRepositoryElement, IAttributeContainer { * Returns the label of the owner, that is, the <i>option label</i> corresponding to the value of the * {@link TaskAttribute#USER_ASSIGNED} attribute in the TaskData. If the connector does not provide option labels * for this attribute, the {@link #getOwnerId() ID} is returned instead. - * + * * @since 3.0 */ public abstract String getOwner(); @@ -292,7 +304,7 @@ public interface ITask extends IRepositoryElement, IAttributeContainer { /** * Returns the ID of the owner, that is, the <i>value</i> of the {@link TaskAttribute#USER_ASSIGNED} attribute in * the TaskData. - * + * * @since 3.15 */ public abstract String getOwnerId(); @@ -325,7 +337,7 @@ public interface ITask extends IRepositoryElement, IAttributeContainer { /** * User identifiable key for the task to be used in UI facilities such as label displays and hyperlinked references. * Can return the same as the ID (e.g. in the case of Bugzilla). Can return null if no such label exists. - * + * * @since 3.0 */ public abstract String getTaskKey(); diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMapper.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMapper.java index f3daee40f..97ea66e67 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMapper.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMapper.java @@ -21,6 +21,7 @@ import org.eclipse.core.runtime.Assert; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.mylyn.tasks.core.IRepositoryPerson; +import org.eclipse.mylyn.tasks.core.ITask.PriorityLevel; import org.eclipse.mylyn.tasks.core.ITaskAttachment; import org.eclipse.mylyn.tasks.core.ITaskComment; import org.eclipse.mylyn.tasks.core.TaskRepository; @@ -40,8 +41,8 @@ public class TaskAttributeMapper { @NonNull public TaskAttribute createTaskAttachment(@NonNull TaskData taskData) { - TaskAttribute taskAttribute = taskData.getRoot().createAttribute( - mapToRepositoryKey(taskData.getRoot(), TaskAttribute.NEW_ATTACHMENT)); + TaskAttribute taskAttribute = taskData.getRoot() + .createAttribute(mapToRepositoryKey(taskData.getRoot(), TaskAttribute.NEW_ATTACHMENT)); // TaskAttachmentMapper mapper = TaskAttachmentMapper.createFrom(taskAttribute); // mapper.setContentType(""); // mapper.setFileName(""); @@ -360,4 +361,15 @@ public class TaskAttributeMapper { TaskCommentMapper.createFrom(taskAttribute).applyTo(taskComment); } + /** + * Connectors may override this method to specify the mapping from the repository's priority options to + * {@link PriorityLevel} + * + * @return the {@link PriorityLevel} corresponding to the given option for the given priority attribute + * @since 3.20 + */ + public PriorityLevel getPriorityLevel(TaskAttribute priorityAttribute, String priorityOption) { + return PriorityLevel.fromString(priorityOption); + } + } diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java index 63c0511a3..660601f39 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java @@ -17,6 +17,7 @@ import java.util.List; import org.eclipse.core.runtime.Assert; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants; import org.eclipse.mylyn.tasks.core.ITask; import org.eclipse.mylyn.tasks.core.ITask.PriorityLevel; import org.eclipse.mylyn.tasks.core.ITaskMapping; @@ -72,6 +73,12 @@ public class TaskMapper implements ITaskMapping { task.setPriority(getPriorityLevelString()); changed = true; } + String priorityLabel = getPriority(); + if (hasChanges(task.getAttribute(ITasksCoreConstants.ATTRIBUTE_PRIORITY_LABEL), priorityLabel, + TaskAttribute.PRIORITY)) { + task.setAttribute(ITasksCoreConstants.ATTRIBUTE_PRIORITY_LABEL, priorityLabel); + changed = true; + } if (hasChanges(task.getSummary(), getSummary(), TaskAttribute.SUMMARY)) { task.setSummary(getSummary()); changed = true; @@ -139,7 +146,7 @@ public class TaskMapper implements ITaskMapping { * <li>description * </ul> * Other attribute values are only set if they exist on <code>sourceTaskData</code> and <code>targetTaskData</code>. - * + * * @param sourceTaskData * the source task data values are copied from, the connector kind of repository of * <code>sourceTaskData</code> can be different from <code>targetTaskData</code> @@ -282,10 +289,21 @@ public class TaskMapper implements ITaskMapping { return getValue(TaskAttribute.PRIORITY); } + /** + * Connectors should override {@link TaskAttributeMapper#getPriorityLevel(TaskAttribute, String)} to customize how + * priority options are mapped to {@link PriorityLevel} + */ @Nullable public PriorityLevel getPriorityLevel() { - String value = getPriority(); - return (value != null) ? PriorityLevel.fromString(value) : null; + String valueLabel = getPriority(); + if (valueLabel != null && PriorityLevel.isValidPriority(valueLabel)) { + return PriorityLevel.fromString(valueLabel); + } + TaskAttribute attribute = taskData.getRoot().getMappedAttribute(TaskAttribute.PRIORITY); + if (attribute != null) { + return getTaskData().getAttributeMapper().getPriorityLevel(attribute, attribute.getValue()); + } + return null; } @Nullable @@ -400,6 +418,8 @@ public class TaskMapper implements ITaskMapping { changed |= hasChanges(task.getTaskKey(), getTaskKey(), TaskAttribute.TASK_KEY); changed |= hasChanges(task.getTaskKind(), getTaskKind(), TaskAttribute.TASK_KIND); changed |= hasChanges(task.getUrl(), getTaskUrl(), TaskAttribute.TASK_URL); + changed |= hasChanges(task.getAttribute(ITasksCoreConstants.ATTRIBUTE_PRIORITY_LABEL), getPriority(), + TaskAttribute.PRIORITY); return changed; } diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/PriorityAttributeEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/PriorityAttributeEditor.java index 40d3c79b0..9812efb5e 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/PriorityAttributeEditor.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/PriorityAttributeEditor.java @@ -39,10 +39,10 @@ public class PriorityAttributeEditor extends AbstractAttributeEditor { @Override public void createControl(final Composite parent, FormToolkit toolkit) { - AbstractRepositoryConnector connector = TasksUi.getRepositoryConnector(getModel().getTaskRepository() - .getConnectorKind()); + AbstractRepositoryConnector connector = TasksUi + .getRepositoryConnector(getModel().getTaskRepository().getConnectorKind()); mapping = connector.getTaskMapping(getModel().getTaskData()); - editor = new PriorityEditor() { + editor = new PriorityEditor(getTaskAttribute()) { @Override protected void valueChanged(String value) { setValue(value); diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/PriorityEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/PriorityEditor.java index 7c309e7a1..84160b944 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/PriorityEditor.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/PriorityEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Tasktop Technologies and others. + * Copyright (c) 2009, 2011 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 @@ -19,6 +19,7 @@ import java.util.Map; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.mylyn.commons.ui.CommonImages; import org.eclipse.mylyn.tasks.core.ITask.PriorityLevel; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.ui.TasksUiImages; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; @@ -60,7 +61,14 @@ public class PriorityEditor { private String value; + private final TaskAttribute attribute; + public PriorityEditor() { + this(null); + } + + public PriorityEditor(TaskAttribute attribute) { + this.attribute = attribute; } public void createControl(final Composite parent, FormToolkit toolkit) { @@ -154,13 +162,20 @@ public class PriorityEditor { } private ImageDescriptor getSmallImageDescriptor(String value) { - PriorityLevel priorityLevel = PriorityLevel.fromString(value); + PriorityLevel priorityLevel = getPriorityLevel(value); if (priorityLevel != null) { return TasksUiImages.getImageDescriptorForPriority(priorityLevel); } return null; } + private PriorityLevel getPriorityLevel(String value) { + if (attribute != null) { + return attribute.getTaskData().getAttributeMapper().getPriorityLevel(attribute, value); + } + return PriorityLevel.fromString(value); + } + public String getToolTipText() { if (label != null) { return label.getToolTipText(); diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListToolTip.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListToolTip.java index 0de8d9b97..60b2603ea 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListToolTip.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListToolTip.java @@ -225,7 +225,11 @@ public class TaskListToolTip extends GradientToolTip { sb.append(") "); //$NON-NLS-1$ } sb.append(", "); //$NON-NLS-1$ - sb.append(task.getPriority()); + String priorityLabel = task.getAttribute(ITasksCoreConstants.ATTRIBUTE_PRIORITY_LABEL); + if (Strings.isNullOrEmpty(priorityLabel)) { + priorityLabel = task.getPriority(); + } + sb.append(priorityLabel); sb.append(" ["); //$NON-NLS-1$ sb.append(getRepositoryLabel(task.getConnectorKind(), task.getRepositoryUrl())); sb.append("]"); //$NON-NLS-1$ |