Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.mylyn.tasks.ui/plugin.xml20
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskAttachmentEditorInput.java100
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskAttachmentStorage.java118
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java8
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskAttachmentPropertyTester.java36
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiMenus.java26
6 files changed, 198 insertions, 110 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/plugin.xml b/org.eclipse.mylyn.tasks.ui/plugin.xml
index a7a681a21..36bc06967 100644
--- a/org.eclipse.mylyn.tasks.ui/plugin.xml
+++ b/org.eclipse.mylyn.tasks.ui/plugin.xml
@@ -1419,11 +1419,7 @@
</command>
</menuContribution>
<menuContribution
- locationURI="popup:org.eclipse.mylyn.tasks.ui.editor.menu.attachments">
- <separator
- name="group.open"
- visible="false">
- </separator>
+ locationURI="popup:org.eclipse.mylyn.tasks.ui.editor.menu.attachments?after=group.open">
<command
commandId="org.eclipse.mylyn.tasks.ui.command.attachment.openInBrowser"
label="Open With Browser"
@@ -1440,13 +1436,6 @@
style="push">
</command>
</menu>
- <separator
- name="group.save">
- </separator>
- <separator
- name="additions"
- visible="false">
- </separator>
</menuContribution>
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any?before=navigate">
@@ -1624,6 +1613,13 @@
properties="canGetAttachment,canPostAttachment,connectorKind,hasLocalContext,hasLocalCompletionState,hasRepositoryContext,isCompleted,isLocal,"
type="org.eclipse.mylyn.tasks.core.ITask">
</propertyTester>
+ <propertyTester
+ class="org.eclipse.mylyn.internal.tasks.ui.util.TaskAttachmentPropertyTester"
+ id="org.eclipse.mylyn.tasks.ui.propertyTester.task.attachment"
+ namespace="org.eclipse.mylyn.task.attachment"
+ properties="isContext"
+ type="org.eclipse.mylyn.tasks.core.ITaskAttachment">
+ </propertyTester>
</extension>
</plugin>
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskAttachmentEditorInput.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskAttachmentEditorInput.java
index e460cde48..f84d01bbc 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskAttachmentEditorInput.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskAttachmentEditorInput.java
@@ -8,24 +8,11 @@
package org.eclipse.mylyn.internal.tasks.ui.editors;
-import java.io.InputStream;
-
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.PlatformObject;
-import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
-import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
-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.core.data.AbstractTaskAttachmentHandler;
-import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
-import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.IStorageEditorInput;
@@ -35,57 +22,10 @@ import org.eclipse.ui.IStorageEditorInput;
*/
public class TaskAttachmentEditorInput extends PlatformObject implements IStorageEditorInput {
- private static final String ATTACHMENT_DEFAULT_NAME = "attachment";
-
- private static final String CTYPE_ZIP = "zip";
-
- private static final String CTYPE_OCTET_STREAM = "octet-stream";
-
- private static final String CTYPE_TEXT = "text";
-
- private static final String CTYPE_HTML = "html";
-
private final ITaskAttachment attachment;
- private final String name;
-
public TaskAttachmentEditorInput(ITaskAttachment attachment) {
this.attachment = attachment;
- this.name = getName(attachment);
- }
-
- private String getName(ITaskAttachment attachment) {
- String name = attachment.getFileName();
- // if no filename is set, make one up with the proper extension so
- // we can support opening in that filetype's default editor
- if (name == null || "".equals(name)) {
- String ctype = attachment.getContentType();
- if (ctype.endsWith(CTYPE_HTML)) {
- name = ATTACHMENT_DEFAULT_NAME + ".html";
- } else if (ctype.startsWith(CTYPE_TEXT)) {
- name = ATTACHMENT_DEFAULT_NAME + ".txt";
- } else if (ctype.endsWith(CTYPE_OCTET_STREAM)) {
- name = ATTACHMENT_DEFAULT_NAME;
- } else if (ctype.endsWith(CTYPE_ZIP)) {
- name = ATTACHMENT_DEFAULT_NAME + "." + CTYPE_ZIP;
- } else {
- name = ATTACHMENT_DEFAULT_NAME + "." + ctype.substring(ctype.indexOf("/") + 1);
- }
- }
- // treat .patch files as text files
- if (name.endsWith(".patch")) {
- name += ".txt";
- }
- return name;
- }
-
- public IStorage getStorage() throws CoreException {
- TaskAttribute taskAttribute = attachment.getTaskAttribute();
- if (taskAttribute == null) {
- throw new CoreException(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Failed to find attachment: "
- + attachment.getUrl()));
- }
- return new TaskAttachmentStorage(attachment.getTaskRepository(), attachment.getTask(), taskAttribute, name);
}
public boolean exists() {
@@ -109,43 +49,7 @@ public class TaskAttachmentEditorInput extends PlatformObject implements IStorag
return attachment.getUrl();
}
- private static class TaskAttachmentStorage extends PlatformObject implements IStorage {
-
- private final TaskRepository taskRepository;
-
- private final ITask task;
-
- private final TaskAttribute attachmentAttribute;
-
- private final String name;
-
- public TaskAttachmentStorage(TaskRepository taskRepository, ITask task,
- TaskAttribute attachmentAttribute, String name) {
- this.taskRepository = taskRepository;
- this.task = task;
- this.attachmentAttribute = attachmentAttribute;
- this.name = name;
- }
-
- public InputStream getContents() throws CoreException {
- AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector(
- taskRepository.getConnectorKind());
- AbstractTaskAttachmentHandler handler = connector.getTaskAttachmentHandler();
- return handler.getContent(taskRepository, task, attachmentAttribute, new NullProgressMonitor());
- }
-
- public IPath getFullPath() {
- // ignore
- return null;
- }
-
- public String getName() {
- return name;
- }
-
- public boolean isReadOnly() {
- return true;
- }
-
+ public IStorage getStorage() throws CoreException {
+ return TaskAttachmentStorage.create(attachment);
}
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskAttachmentStorage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskAttachmentStorage.java
new file mode 100644
index 000000000..c0dbac43d
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskAttachmentStorage.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * 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.editors;
+
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+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.core.data.AbstractTaskAttachmentHandler;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.ui.TasksUi;
+
+/**
+ * @author Jeff Pound
+ * @author Steffen Pingel
+ */
+public class TaskAttachmentStorage extends PlatformObject implements IStorage {
+
+ private static final String ATTACHMENT_DEFAULT_NAME = "attachment";
+
+ private static final String CTYPE_ZIP = "zip";
+
+ private static final String CTYPE_OCTET_STREAM = "octet-stream";
+
+ private static final String CTYPE_TEXT = "text";
+
+ private static final String CTYPE_HTML = "html";
+
+ private final TaskRepository taskRepository;
+
+ private final ITask task;
+
+ private final TaskAttribute attachmentAttribute;
+
+ private final String name;
+
+ public TaskAttachmentStorage(TaskRepository taskRepository, ITask task, TaskAttribute attachmentAttribute,
+ String name) {
+ this.taskRepository = taskRepository;
+ this.task = task;
+ this.attachmentAttribute = attachmentAttribute;
+ this.name = name;
+ }
+
+ public static IStorage create(ITaskAttachment attachment) throws CoreException {
+ Assert.isNotNull(attachment);
+ TaskAttribute taskAttribute = attachment.getTaskAttribute();
+ if (taskAttribute == null) {
+ throw new CoreException(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Failed to find attachment: "
+ + attachment.getUrl()));
+ }
+ return new TaskAttachmentStorage(attachment.getTaskRepository(), attachment.getTask(), taskAttribute,
+ getName(attachment));
+ }
+
+ private static String getName(ITaskAttachment attachment) {
+ String name = attachment.getFileName();
+ // if no filename is set, make one up with the proper extension so
+ // we can support opening in that filetype's default editor
+ if (name == null || "".equals(name)) {
+ String ctype = attachment.getContentType();
+ if (ctype.endsWith(CTYPE_HTML)) {
+ name = ATTACHMENT_DEFAULT_NAME + ".html";
+ } else if (ctype.startsWith(CTYPE_TEXT)) {
+ name = ATTACHMENT_DEFAULT_NAME + ".txt";
+ } else if (ctype.endsWith(CTYPE_OCTET_STREAM)) {
+ name = ATTACHMENT_DEFAULT_NAME;
+ } else if (ctype.endsWith(CTYPE_ZIP)) {
+ name = ATTACHMENT_DEFAULT_NAME + "." + CTYPE_ZIP;
+ } else {
+ name = ATTACHMENT_DEFAULT_NAME + "." + ctype.substring(ctype.indexOf("/") + 1);
+ }
+ }
+ // treat .patch files as text files
+ if (name.endsWith(".patch")) {
+ name += ".txt";
+ }
+ return name;
+ }
+
+ public InputStream getContents() throws CoreException {
+ AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector(
+ taskRepository.getConnectorKind());
+ AbstractTaskAttachmentHandler handler = connector.getTaskAttachmentHandler();
+ return handler.getContent(taskRepository, task, attachmentAttribute, new NullProgressMonitor());
+ }
+
+ public IPath getFullPath() {
+ // ignore
+ return null;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+} \ No newline at end of file
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 dc19d00da..5c7613ea1 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
@@ -13,6 +13,8 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
@@ -30,6 +32,7 @@ import org.eclipse.mylyn.internal.tasks.core.data.TextTaskAttachmentSource;
import org.eclipse.mylyn.internal.tasks.ui.actions.AttachAction;
import org.eclipse.mylyn.internal.tasks.ui.actions.AttachScreenshotAction;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
+import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus;
import org.eclipse.mylyn.internal.tasks.ui.wizards.NewAttachmentWizardDialog;
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode;
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
@@ -177,6 +180,11 @@ public class TaskEditorAttachmentPart extends AbstractTaskEditorPart {
menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
+ menuManager.addMenuListener(new IMenuListener() {
+ public void menuAboutToShow(IMenuManager manager) {
+ TasksUiMenus.fillTaskAttachmentMenu(manager);
+ }
+ });
getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer, false);
Menu menu = menuManager.createContextMenu(attachmentsTable);
attachmentsTable.setMenu(menu);
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskAttachmentPropertyTester.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskAttachmentPropertyTester.java
new file mode 100644
index 000000000..c5ab1ac71
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskAttachmentPropertyTester.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.util;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.mylyn.internal.tasks.ui.AttachmentUtil;
+import org.eclipse.mylyn.tasks.core.ITaskAttachment;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TaskAttachmentPropertyTester extends PropertyTester {
+
+ private static final String PROPERTY_IS_CONTEXT = "isContext";
+
+ private boolean equals(boolean value, Object expectedValue) {
+ return new Boolean(value).equals(expectedValue);
+ }
+
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (receiver instanceof ITaskAttachment) {
+ ITaskAttachment taskAttachment = (ITaskAttachment) receiver;
+ if (PROPERTY_IS_CONTEXT.equals(property)) {
+ return equals(AttachmentUtil.isContext(taskAttachment), expectedValue);
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiMenus.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiMenus.java
new file mode 100644
index 000000000..5c9daa2c3
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiMenus.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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.util;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.ui.IWorkbenchActionConstants;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TasksUiMenus {
+
+ public static void fillTaskAttachmentMenu(IMenuManager manager) {
+ manager.add(new Separator("group.open"));
+ manager.add(new Separator("group.save"));
+ manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ }
+
+}

Back to the top