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
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')
-rw-r--r--org.eclipse.mylyn.tasks.ui/plugin.xml22
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java52
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskRepositoryAdapterFactory.java4
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksAdapterFactory.java49
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorActionContributor.java23
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskPropertyTester.java32
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java4
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditorInput.java3
9 files changed, 166 insertions, 25 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/plugin.xml b/org.eclipse.mylyn.tasks.ui/plugin.xml
index 45918ff35..80ac4d27f 100644
--- a/org.eclipse.mylyn.tasks.ui/plugin.xml
+++ b/org.eclipse.mylyn.tasks.ui/plugin.xml
@@ -1067,6 +1067,26 @@
class="org.eclipse.mylyn.internal.tasks.ui.TaskRepositoryAdapterFactory">
<adapter type="org.eclipse.ui.IActionFilter"/>
</factory>
+ <factory
+ adaptableType="org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput"
+ class="org.eclipse.mylyn.internal.tasks.ui.TasksAdapterFactory">
+ <adapter
+ type="org.eclipse.mylyn.tasks.core.ITask">
+ </adapter>
+ <adapter
+ type="org.eclipse.mylyn.tasks.core.TaskRepository">
+ </adapter>
+ </factory>
+ <factory
+ adaptableType="org.eclipse.mylyn.tasks.core.ITaskAttachment"
+ class="org.eclipse.mylyn.internal.tasks.ui.TasksAdapterFactory">
+ <adapter
+ type="org.eclipse.mylyn.tasks.core.ITask">
+ </adapter>
+ <adapter
+ type="org.eclipse.mylyn.tasks.core.TaskRepository">
+ </adapter>
+ </factory>
</extension>
<extension
@@ -1588,7 +1608,7 @@
class="org.eclipse.mylyn.internal.tasks.ui.util.TaskPropertyTester"
id="org.eclipse.mylyn.tasks.ui.propertyTester.task"
namespace="org.eclipse.mylyn.task"
- properties="connectorKink,isLocal,isCompleted"
+ properties="connectorKink,isLocal,isCompleted,canPostAttachment,canGetAttachment,hasLocalContext,hasRepositoryContext"
type="org.eclipse.mylyn.tasks.core.ITask">
</propertyTester>
</extension>
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())
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskRepositoryAdapterFactory.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskRepositoryAdapterFactory.java
index 036adf069..1774e416a 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskRepositoryAdapterFactory.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskRepositoryAdapterFactory.java
@@ -44,8 +44,8 @@ public class TaskRepositoryAdapterFactory implements IAdapterFactory {
.getRepositoryConnector(repository.getConnectorKind());
return null != connectorUi.getQueryWizard(repository, null) && connector.canQuery(repository);
} else if ("supportNewTask".equals(name)) {
- AbstractRepositoryConnector connector = TasksUi.getRepositoryManager()
- .getRepositoryConnector(repository.getConnectorKind());
+ AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector(
+ repository.getConnectorKind());
return connector.canCreateNewTask(repository);
} else if ("hasRepository".equals(name)) {
return !repository.getConnectorKind().equals(LocalRepositoryConnector.CONNECTOR_KIND);
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksAdapterFactory.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksAdapterFactory.java
new file mode 100644
index 000000000..fc902f807
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TasksAdapterFactory.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Mylyn project 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.mylyn.internal.tasks.ui;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.ITaskAttachment;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput;
+
+/**
+ * Factory for adapting objects to task elements.
+ *
+ * @author Steffen Pingel
+ */
+public class TasksAdapterFactory implements IAdapterFactory {
+
+ private static final Class<?>[] ADAPTER_LIST = new Class[] { ITask.class, TaskRepository.class };
+
+ @SuppressWarnings("unchecked")
+ public Class[] getAdapterList() {
+ return ADAPTER_LIST;
+ }
+
+ public Object getAdapter(final Object adaptable, @SuppressWarnings("unchecked") Class adapterType) {
+ if (adapterType == ITask.class) {
+ if (adaptable instanceof TaskEditorInput) {
+ return ((TaskEditorInput) adaptable).getTask();
+ } else if (adaptable instanceof ITaskAttachment) {
+ return ((ITaskAttachment) adaptable).getTask();
+ }
+ }
+ if (adapterType == TaskRepository.class) {
+ if (adaptable instanceof TaskEditorInput) {
+ return ((TaskEditorInput) adaptable).getTaskRepository();
+ } else if (adaptable instanceof ITaskAttachment) {
+ return ((ITaskAttachment) adaptable).getTaskRepository();
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorActionContributor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorActionContributor.java
index c284f325a..08425c188 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorActionContributor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorActionContributor.java
@@ -224,11 +224,12 @@ public class TaskEditorActionContributor extends MultiPageEditorActionBarContrib
IStructuredSelection selection = new StructuredSelection(task);
openWithBrowserAction.selectionChanged(selection);
copyTaskDetailsAction.selectionChanged(selection);
- attachAction.selectionChanged(selection);
- attachAction.setEditor(editor);
- attachScreenshotAction.selectionChanged(selection);
- attachScreenshotAction.setEditor(editor);
-
+ if (getPage() instanceof AbstractRepositoryTaskEditor) {
+ attachAction.selectionChanged(selection);
+ attachAction.setEditor(editor);
+ attachScreenshotAction.selectionChanged(selection);
+ attachScreenshotAction.setEditor(editor);
+ }
synchronizeEditorAction.selectionChanged(new StructuredSelection(this.getEditor()));
showInTaskListAction.selectionChanged(selection);
@@ -255,6 +256,8 @@ public class TaskEditorActionContributor extends MultiPageEditorActionBarContrib
manager.add(showInTaskListAction);
manager.add(new Separator());
+ manager.add(new GroupMarker(TaskListView.ID_SEPARATOR_OPERATIONS));
+ manager.add(new GroupMarker(TaskListView.ID_SEPARATOR_CONTEXT));
for (String menuPath : TasksUiPlugin.getDefault().getDynamicMenuMap().keySet()) {
for (IDynamicSubMenuContributor contributor : TasksUiPlugin.getDefault().getDynamicMenuMap().get(
@@ -271,10 +274,12 @@ public class TaskEditorActionContributor extends MultiPageEditorActionBarContrib
}
}
}
-
- manager.add(new Separator());
- manager.add(attachAction);
- manager.add(attachScreenshotAction);
+ manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
+ if (getPage() instanceof AbstractRepositoryTaskEditor) {
+ manager.add(new Separator());
+ manager.add(attachAction);
+ manager.add(attachScreenshotAction);
+ }
manager.add(new Separator());
// HACK: there should be a saner way of doing this
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java
index 291bbc27c..1bcf9dda2 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java
@@ -177,7 +177,7 @@ public class TaskEditorAttachmentPart extends AbstractTaskEditorPart {
menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
- getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer, false);
+ getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer, true);
Menu menu = menuManager.createContextMenu(attachmentsTable);
attachmentsTable.setMenu(menu);
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskPropertyTester.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskPropertyTester.java
index 899ccbb4e..583a52598 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskPropertyTester.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskPropertyTester.java
@@ -10,6 +10,7 @@ package org.eclipse.mylyn.internal.tasks.ui.util;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
+import org.eclipse.mylyn.internal.tasks.ui.AttachmentUtil;
import org.eclipse.mylyn.tasks.core.ITask;
/**
@@ -17,24 +18,45 @@ import org.eclipse.mylyn.tasks.core.ITask;
*/
public class TaskPropertyTester extends PropertyTester {
+ private static final String PROPERTY_CAN_GET_ATTACHEMNT = "canGetAttachment";
+
+ private static final String PROPERTY_CAN_POST_ATTACHMENT = "canPostAttachment";
+
private static final String PROPERTY_CONNECTOR_KIND = "connectorKind";
- private static final String PROPERTY_IS_LOCAL = "isLocal";
+ private static final String PROPERTY_HAS_LOCAL_CONTEXT = "hasLocalContext";
+
+ private static final String PROPERTY_HAS_REPOSITORY_CONTEXT = "hasRepositoryContext";
private static final String PROPERTY_IS_COMPLETED = "isCompleted";
+ private static final String PROPERTY_IS_LOCAL = "isLocal";
+
+ private boolean equals(boolean value, Object expectedValue) {
+ return new Boolean(value).equals(expectedValue);
+ }
+
+ @SuppressWarnings("deprecation")
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (receiver instanceof ITask) {
ITask task = (ITask) receiver;
if (PROPERTY_CONNECTOR_KIND.equals(property)) {
return task.getConnectorKind().equals(expectedValue);
- } else if (PROPERTY_IS_LOCAL.equals(property)) {
- return (task instanceof AbstractTask)
- && new Boolean(((AbstractTask) task).isLocal()).equals(expectedValue);
+ } else if (PROPERTY_CAN_POST_ATTACHMENT.equals(property)) {
+ return equals(AttachmentUtil.canDownloadAttachment(task), expectedValue);
+ } else if (PROPERTY_CAN_GET_ATTACHEMNT.equals(property)) {
+ return equals(AttachmentUtil.canUploadAttachment(task), expectedValue);
+ } else if (PROPERTY_HAS_LOCAL_CONTEXT.equals(property)) {
+ return equals(AttachmentUtil.hasLocalContext(task), expectedValue);
+ } else if (PROPERTY_HAS_REPOSITORY_CONTEXT.equals(property)) {
+ return equals(AttachmentUtil.hasContextAttachment(task), expectedValue);
} else if (PROPERTY_IS_COMPLETED.equals(property)) {
- return new Boolean(task.isCompleted()).equals(expectedValue);
+ return equals(task.isCompleted(), expectedValue);
+ } else if (PROPERTY_IS_LOCAL.equals(property)) {
+ return (task instanceof AbstractTask) && equals(((AbstractTask) task).isLocal(), expectedValue);
}
}
return false;
}
+
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java
index a39358d37..de6db427f 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskListView.java
@@ -233,9 +233,9 @@ public class TaskListView extends ViewPart implements IPropertyChangeListener {
private static final String ID_SEPARATOR_NEW = "new";
- private static final String ID_SEPARATOR_OPERATIONS = "operations";
+ public static final String ID_SEPARATOR_OPERATIONS = "operations";
- private static final String ID_SEPARATOR_CONTEXT = "context";
+ public static final String ID_SEPARATOR_CONTEXT = "context";
public static final String ID_SEPARATOR_TASKS = "tasks";
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditorInput.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditorInput.java
index 490c8ea48..ed94a4636 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditorInput.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditorInput.java
@@ -12,7 +12,6 @@ package org.eclipse.mylyn.tasks.ui.editors;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorInputFactory;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.TaskRepository;
@@ -90,8 +89,6 @@ public class TaskEditorInput implements IEditorInput, IPersistableElement {
public Object getAdapter(Class adapter) {
if (adapter == IEditorInput.class) {
return this;
- } else if (adapter == AbstractTask.class) {
- return task;
}
return null;
}

Back to the top