Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2008-05-14 01:19:20 +0000
committerspingel2008-05-14 01:19:20 +0000
commitfe65ea61dabc1a7ba2b3d35bc11b61742d766f21 (patch)
tree33a5b5e57d020ad154addce9bdd539f288a4b781 /org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java
parent79755482f929bf189ae3ab9d507c02c151ac7af2 (diff)
downloadorg.eclipse.mylyn.tasks-fe65ea61dabc1a7ba2b3d35bc11b61742d766f21.tar.gz
org.eclipse.mylyn.tasks-fe65ea61dabc1a7ba2b3d35bc11b61742d766f21.tar.xz
org.eclipse.mylyn.tasks-fe65ea61dabc1a7ba2b3d35bc11b61742d766f21.zip
NEW - bug 199818: [api] arbitrary attributes in AbstractTask
https://bugs.eclipse.org/bugs/show_bug.cgi?id=199818
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java')
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java52
1 files changed, 50 insertions, 2 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java
index 5b08c9f24..dac945fb6 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java
@@ -13,9 +13,12 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -24,6 +27,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.context.core.ContextCore;
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
+import org.eclipse.mylyn.internal.tasks.core.TaskAttachment;
import org.eclipse.mylyn.internal.tasks.core.TaskDataStorageManager;
import org.eclipse.mylyn.internal.tasks.core.data.FileTaskAttachmentSource;
import org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractAttachmentHandler;
@@ -39,6 +43,7 @@ import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.ITask.SynchronizationState;
import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentHandler;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.ui.TasksUi;
/**
@@ -109,7 +114,7 @@ public class AttachmentUtil {
*
* @return an empty set if no contexts
*/
- public static Set<RepositoryAttachment> getContextAttachments(TaskRepository repository, ITask task) {
+ public static Set<RepositoryAttachment> getLegacyContextAttachments(TaskRepository repository, ITask task) {
TaskDataStorageManager taskDataManager = TasksUiPlugin.getTaskDataStorageManager();
Set<RepositoryAttachment> contextAttachments = new HashSet<RepositoryAttachment>();
if (taskDataManager != null) {
@@ -127,15 +132,58 @@ public class AttachmentUtil {
return contextAttachments;
}
+ public static ITaskAttachment[] getContextAttachments(TaskRepository repository, ITask task) {
+ List<ITaskAttachment> contextAttachments = new ArrayList<ITaskAttachment>();
+ TaskData taskData;
+ try {
+ taskData = TasksUi.getTaskDataManager().getTaskData(task, task.getConnectorKind());
+ } catch (CoreException e) {
+ // ignore
+ return new ITaskAttachment[0];
+ }
+ if (taskData != null) {
+ TaskAttribute[] taskAttachments = taskData.getAttributeMapper().getAttributesByType(taskData,
+ TaskAttribute.TYPE_ATTACHMENT);
+ for (TaskAttribute attribute : taskAttachments) {
+ TaskAttachment taskAttachment = new TaskAttachment(repository, task, attribute);
+ taskData.getAttributeMapper().updateTaskAttachment(taskAttachment, attribute);
+ if (isContext(taskAttachment)) {
+ contextAttachments.add(taskAttachment);
+ }
+ }
+ }
+ return contextAttachments.toArray(new ITaskAttachment[0]);
+ }
+
public static boolean hasContext(TaskRepository repository, ITask task) {
if (repository == null || task == null) {
return false;
} else {
- Set<RepositoryAttachment> remoteContextAttachments = getContextAttachments(repository, task);
+ Set<RepositoryAttachment> remoteContextAttachments = getLegacyContextAttachments(repository, task);
return (remoteContextAttachments != null && remoteContextAttachments.size() > 0);
}
}
+ public static boolean hasContextAttachment(ITask task) {
+ Assert.isNotNull(task);
+ TaskRepository repository = TasksUi.getRepositoryManager().getRepository(task.getConnectorKind(),
+ task.getRepositoryUrl());
+ AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector(
+ repository.getConnectorKind());
+ if (connector instanceof AbstractLegacyRepositoryConnector) {
+ Set<RepositoryAttachment> remoteContextAttachments = getLegacyContextAttachments(repository, task);
+ return (remoteContextAttachments != null && remoteContextAttachments.size() > 0);
+ } else {
+ ITaskAttachment[] contextAttachments = getContextAttachments(repository, task);
+ return contextAttachments.length > 0;
+ }
+ }
+
+ public static boolean hasLocalContext(ITask task) {
+ Assert.isNotNull(task);
+ return ContextCore.getContextManager().hasContext(task.getHandleIdentifier());
+ }
+
@Deprecated
public static boolean isContext(RepositoryAttachment attachment) {
return CONTEXT_DESCRIPTION.equals(attachment.getDescription())

Back to the top