Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrelves2007-06-11 22:29:24 -0400
committerrelves2007-06-11 22:29:24 -0400
commit5b03021160c40962b52f7f57046c4ebab3a324ba (patch)
treeb706bc531f7ca9e99317fa45f27b45f243274034
parent66affe5ff637da0a46209458cce76d0292a24dab (diff)
downloadorg.eclipse.mylyn.tasks-5b03021160c40962b52f7f57046c4ebab3a324ba.tar.gz
org.eclipse.mylyn.tasks-5b03021160c40962b52f7f57046c4ebab3a324ba.tar.xz
org.eclipse.mylyn.tasks-5b03021160c40962b52f7f57046c4ebab3a324ba.zip
NEW - bug 190672: Run saving of attachments in job
https://bugs.eclipse.org/bugs/show_bug.cgi?id=190672
-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/AttachmentJobTest.java120
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskAttachmentActionsTest.java85
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttachmentHandler.java74
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java8
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockStatusHandler.java32
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/CopyAttachmentToClipboardJob.java7
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/DownloadAttachmentJob.java87
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/SaveRemoteFileAction.java69
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractRepositoryTaskEditor.java28
10 files changed, 334 insertions, 178 deletions
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 d285af10d..f89a80efe 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
@@ -45,7 +45,7 @@ public class AllTasksTests {
suite.addTestSuite(TaskDataExportTest.class);
suite.addTestSuite(TaskDataImportTest.class);
suite.addTestSuite(TaskActivityTest.class);
- suite.addTestSuite(TaskAttachmentActionsTest.class);
+ suite.addTestSuite(AttachmentJobTest.class);
suite.addTestSuite(RepositorySettingsPageTest.class);
suite.addTestSuite(TaskHistoryTest.class);
suite.addTestSuite(UrlConnectionUtilTest.class);
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AttachmentJobTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AttachmentJobTest.java
new file mode 100644
index 000000000..731a72b43
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AttachmentJobTest.java
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar 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.tasks.tests;
+
+import java.io.File;
+import java.io.RandomAccessFile;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.core.MylarStatusHandler;
+import org.eclipse.mylyn.internal.tasks.ui.actions.CopyAttachmentToClipboardJob;
+import org.eclipse.mylyn.internal.tasks.ui.actions.DownloadAttachmentJob;
+import org.eclipse.mylyn.tasks.core.RepositoryAttachment;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.TaskRepositoryManager;
+import org.eclipse.mylyn.tasks.tests.connector.MockAttachmentHandler;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+import org.eclipse.mylyn.tasks.tests.connector.MockStatusHandler;
+import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Test task attachment jobs.
+ *
+ * @author Steffen Pingel
+ */
+public class AttachmentJobTest extends TestCase {
+
+ private TaskRepositoryManager manager;
+
+ private MockRepositoryConnector connector;
+
+ private MockAttachmentHandler attachmentHandler;
+
+ private MockStatusHandler statusHandler;
+
+ private TaskRepository repository;
+
+ private RepositoryAttachment attachment;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ manager = TasksUiPlugin.getRepositoryManager();
+
+ repository = new TaskRepository(MockRepositoryConnector.REPOSITORY_KIND,
+ MockRepositoryConnector.REPOSITORY_URL);
+ manager.addRepository(repository, TasksUiPlugin.getDefault().getRepositoriesFilePath());
+
+ attachmentHandler = new MockAttachmentHandler();
+
+ connector = new MockRepositoryConnector();
+ connector.setAttachmentHandler(attachmentHandler);
+ manager.addRepositoryConnector(connector);
+
+ statusHandler = new MockStatusHandler();
+ MylarStatusHandler.addStatusHandler(statusHandler);
+
+ attachment = new RepositoryAttachment(null);
+ attachment.setRepositoryKind(repository.getKind());
+ attachment.setRepositoryUrl(repository.getUrl());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if (statusHandler != null) {
+ MylarStatusHandler.removeStatusHandler(statusHandler);
+ }
+ }
+
+ public void testCopyToClipboardAction() throws Exception {
+ String expected = "attachment content";
+ attachmentHandler.setAttachmentData(expected.getBytes());
+
+ CopyAttachmentToClipboardJob job = new CopyAttachmentToClipboardJob(attachment);
+ job.schedule();
+ job.join();
+
+ // wait for any scheduled SWT jobs to finish
+ while (PlatformUI.getWorkbench().getDisplay().readAndDispatch()) {
+ }
+
+ Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
+ assertEquals(expected, clipboard.getContents(TextTransfer.getInstance()));
+ }
+
+ public void testDownloadAttachmentJob() throws Exception {
+ File file = File.createTempFile("mylyn", null);
+ file.deleteOnExit();
+
+ String expected = "attachment\ncontent";
+ attachmentHandler.setAttachmentData(expected.getBytes());
+
+ DownloadAttachmentJob job = new DownloadAttachmentJob(attachment, file);
+ job.schedule();
+ job.join();
+
+ assertEquals(Status.OK_STATUS, job.getResult());
+ statusHandler.assertNoStatus();
+
+ RandomAccessFile raf = new RandomAccessFile(file, "r");
+ byte[] data = new byte[expected.getBytes().length];
+ try {
+ raf.readFully(data);
+ } finally {
+ raf.close();
+ }
+ assertEquals(expected, new String(data));
+ }
+}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskAttachmentActionsTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskAttachmentActionsTest.java
deleted file mode 100644
index 3503cd3a8..000000000
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskAttachmentActionsTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 - 2006 Mylar 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.tasks.tests;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.net.URL;
-import java.net.URLConnection;
-
-import junit.framework.TestCase;
-
-import org.eclipse.mylyn.internal.tasks.ui.actions.CopyAttachmentToClipboardJob;
-import org.eclipse.mylyn.internal.tasks.ui.actions.SaveRemoteFileAction;
-import org.eclipse.swt.dnd.Clipboard;
-import org.eclipse.swt.dnd.TextTransfer;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * Test task attachment actions.
- *
- * @author Jeff Pound
- */
-public class TaskAttachmentActionsTest extends TestCase {
-
- /**
- * Copy some text to the clipboard using the CopyToClipboardAction and
- * ensure the contents of the clipboard match.
- *
- * @throws Exception
- */
- public void testCopyToClipboardAction() throws Exception {
- String contents = "Sample clipboard text";
- CopyAttachmentToClipboardJob job = new CopyAttachmentToClipboardJob(null);
- job.copyToClipboard(contents);
-
- // wait for job to finish
- while (PlatformUI.getWorkbench().getDisplay().readAndDispatch()) {
- }
-
- Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
- assertEquals(contents, clipboard.getContents(TextTransfer.getInstance()));
- }
-
- /**
- * Save a file using the SaveRemoteFileAction and ensure it exists and the
- * contents are correct
- *
- * @throws Exception
- */
- public void testSaveRemoteFileAction() throws Exception {
- String localFile = "TaskAttachmentActionsTest.testfile";
- String url = "http://mylar.eclipse.org/bugs222/attachment.cgi?id=189";
- int lineCount = 11;
-
- SaveRemoteFileAction action = new SaveRemoteFileAction();
-
- URLConnection urlConnect;
- urlConnect = (new URL(url)).openConnection();
- urlConnect.connect();
-
- action.setInputStream(urlConnect.getInputStream());
- action.setDestinationFilePath(localFile);
- action.run();
-
- File file = new File(localFile);
- assertTrue(file.exists());
-
- BufferedReader reader = new BufferedReader(new FileReader(file));
- int lines = 0;
- while (reader.readLine() != null) {
- lines++;
- }
-
- assertEquals(lineCount, lines);
- file.delete();
- }
-
-}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttachmentHandler.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttachmentHandler.java
new file mode 100644
index 000000000..ea4c18f37
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttachmentHandler.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar 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.tasks.tests.connector;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryTask;
+import org.eclipse.mylyn.tasks.core.IAttachmentHandler;
+import org.eclipse.mylyn.tasks.core.ITaskAttachment;
+import org.eclipse.mylyn.tasks.core.RepositoryAttachment;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+
+/**
+ * @author Steffen Pingel
+ */
+public class MockAttachmentHandler implements IAttachmentHandler {
+
+ private byte[] data;
+
+ public boolean canDeprecate(TaskRepository repository, RepositoryAttachment attachment) {
+ // ignore
+ return false;
+ }
+
+ public boolean canDownloadAttachment(TaskRepository repository, AbstractRepositoryTask task) {
+ // ignore
+ return true;
+ }
+
+ public boolean canUploadAttachment(TaskRepository repository, AbstractRepositoryTask task) {
+ // ignore
+ return true;
+ }
+
+ public void downloadAttachment(TaskRepository repository, RepositoryAttachment attachment, OutputStream target,
+ IProgressMonitor monitor) throws CoreException {
+ try {
+ target.write(data);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public InputStream getAttachmentAsStream(TaskRepository repository, RepositoryAttachment attachment,
+ IProgressMonitor monitor) throws CoreException {
+ // ignore
+ return new ByteArrayInputStream(data);
+ }
+
+ public void updateAttachment(TaskRepository repository, RepositoryAttachment attachment) throws CoreException {
+ // ignore
+ }
+
+ public void uploadAttachment(TaskRepository repository, AbstractRepositoryTask task, ITaskAttachment attachment,
+ String comment, IProgressMonitor monitor) throws CoreException {
+ // ignore
+ }
+
+ public void setAttachmentData(byte[] data) {
+ this.data = data;
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java
index c03a4f756..08748b9b7 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java
@@ -37,6 +37,8 @@ public class MockRepositoryConnector extends AbstractRepositoryConnector {
public static final String REPOSITORY_URL = "http://mockrepository.test";
+ private IAttachmentHandler attachmentHandler;
+
@Override
public boolean canCreateNewTask(TaskRepository repository) {
// ignore
@@ -51,8 +53,7 @@ public class MockRepositoryConnector extends AbstractRepositoryConnector {
@Override
public IAttachmentHandler getAttachmentHandler() {
- // ignore
- return null;
+ return attachmentHandler;
}
@Override
@@ -157,4 +158,7 @@ public class MockRepositoryConnector extends AbstractRepositoryConnector {
return null;
}
+ public void setAttachmentHandler(IAttachmentHandler attachmentHandler) {
+ this.attachmentHandler = attachmentHandler;
+ }
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockStatusHandler.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockStatusHandler.java
new file mode 100644
index 000000000..d94f60281
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockStatusHandler.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar 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.tasks.tests.connector;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.mylyn.core.IStatusHandler;
+
+public class MockStatusHandler implements IStatusHandler {
+
+ private IStatus status;
+
+ public void displayStatus(String title, IStatus status) {
+ this.status = status;
+ }
+
+ public void fail(IStatus status, boolean informUser) {
+ this.status = status;
+ }
+
+ public void assertNoStatus() {
+ TestCase.assertNull("Unexpected error reported through MylarStatusHandler", status);
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/CopyAttachmentToClipboardJob.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/CopyAttachmentToClipboardJob.java
index d555ea1a7..05d97417d 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/CopyAttachmentToClipboardJob.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/CopyAttachmentToClipboardJob.java
@@ -37,6 +37,10 @@ public class CopyAttachmentToClipboardJob extends Job {
public CopyAttachmentToClipboardJob(RepositoryAttachment attachment) {
super("Copying Attachment to Clipboard");
+ if (attachment == null) {
+ throw new IllegalArgumentException("attachment may not be null");
+ }
+
this.attachment = attachment;
}
@@ -67,8 +71,7 @@ public class CopyAttachmentToClipboardJob extends Job {
return Status.OK_STATUS;
}
- /** For testing. */
- public void copyToClipboard(final String contents) {
+ private void copyToClipboard(final String contents) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/DownloadAttachmentJob.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/DownloadAttachmentJob.java
new file mode 100644
index 000000000..a8908a4ff
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/DownloadAttachmentJob.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar 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.actions;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.mylyn.core.MylarStatusHandler;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.IAttachmentHandler;
+import org.eclipse.mylyn.tasks.core.RepositoryAttachment;
+import org.eclipse.mylyn.tasks.core.RepositoryStatus;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
+
+/**
+ * @author Steffen Pingel
+ */
+public class DownloadAttachmentJob extends Job {
+
+ private final RepositoryAttachment attachment;
+
+ private final File targetFile;
+
+ public DownloadAttachmentJob(RepositoryAttachment attachment, File targetFile) {
+ super("Downloading Attachment");
+
+ if (attachment == null) {
+ throw new IllegalArgumentException("attachment must not be null");
+ }
+ if (targetFile == null) {
+ throw new IllegalArgumentException("target must not be null");
+ }
+
+ this.attachment = attachment;
+ this.targetFile = targetFile;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(attachment.getRepositoryKind(),
+ this.attachment.getRepositoryUrl());
+ AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector(
+ this.attachment.getRepositoryKind());
+ IAttachmentHandler handler = connector.getAttachmentHandler();
+ if (handler == null) {
+ return new RepositoryStatus(repository, IStatus.INFO, TasksUiPlugin.PLUGIN_ID, RepositoryStatus.ERROR_INTERNAL,
+ "The repository does not support attachments.");
+ }
+
+ FileOutputStream out = null;
+ try {
+ out = new FileOutputStream(this.targetFile);
+ handler.downloadAttachment(repository, attachment, out, monitor);
+ } catch (final CoreException e) {
+ MylarStatusHandler.displayStatus("Download Attachment", e.getStatus());
+ return Status.OK_STATUS;
+ } catch (IOException e) {
+ return new RepositoryStatus(repository, IStatus.WARNING, TasksUiPlugin.PLUGIN_ID, RepositoryStatus.ERROR_IO,
+ "Error while writing to attachment file.", e);
+ } finally {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ MylarStatusHandler.fail(e, "Could not close attachment file: " + this.targetFile.getAbsolutePath(),
+ false);
+ }
+ }
+ }
+
+ return Status.OK_STATUS;
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/SaveRemoteFileAction.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/SaveRemoteFileAction.java
deleted file mode 100644
index ba5653a04..000000000
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/SaveRemoteFileAction.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 - 2006 Mylar 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.actions;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.eclipse.jface.action.Action;
-
-/**
- * An <code>Action</code> which saves the given file contents to the given
- * file location on disk.
- *
- * @author Jeff Pound
- */
-public class SaveRemoteFileAction extends Action {
-
- public static final String TITLE = "Save...";
-
- private String destinationFilePath;
-
- private InputStream inStream;
-
- public SaveRemoteFileAction() {
- super(TITLE);
- }
-
- @Override
- public void run() {
- if (destinationFilePath == null || inStream == null) {
- return;
- }
-
- File outFile = new File(destinationFilePath);
- try {
- /* TODO jpound - Use FileWriter iff text? */
- FileOutputStream writer = new FileOutputStream(outFile);
- BufferedInputStream reader = new BufferedInputStream(inStream);
-
- int c;
- while ((c = reader.read()) != -1) {
- writer.write(c);
- }
-
- writer.close();
- reader.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- public void setDestinationFilePath(String destinationFilePath) {
- this.destinationFilePath = destinationFilePath;
- }
-
- public void setInputStream(InputStream inStream) {
- this.inStream = inStream;
- }
-}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractRepositoryTaskEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractRepositoryTaskEditor.java
index 8e1508351..b2a08a9c8 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractRepositoryTaskEditor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractRepositoryTaskEditor.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.mylyn.tasks.ui.editors;
+import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -68,7 +69,7 @@ import org.eclipse.mylyn.internal.tasks.ui.TaskListColorsAndFonts;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages;
import org.eclipse.mylyn.internal.tasks.ui.actions.AttachFileAction;
import org.eclipse.mylyn.internal.tasks.ui.actions.CopyAttachmentToClipboardJob;
-import org.eclipse.mylyn.internal.tasks.ui.actions.SaveRemoteFileAction;
+import org.eclipse.mylyn.internal.tasks.ui.actions.DownloadAttachmentJob;
import org.eclipse.mylyn.internal.tasks.ui.actions.SynchronizeEditorAction;
import org.eclipse.mylyn.internal.tasks.ui.editors.ContentOutlineTools;
import org.eclipse.mylyn.internal.tasks.ui.editors.IRepositoryTaskAttributeListener;
@@ -79,7 +80,6 @@ import org.eclipse.mylyn.monitor.core.DateUtil;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryTask;
import org.eclipse.mylyn.tasks.core.AbstractTaskContainer;
-import org.eclipse.mylyn.tasks.core.IAttachmentHandler;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.ITaskDataHandler;
import org.eclipse.mylyn.tasks.core.ITaskListChangeListener;
@@ -209,6 +209,8 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage {
private static final String LABEL_BUTTON_SUBMIT = "Submit";
private static final String LABEL_COPY_TO_CLIPBOARD = "Copy to Clipboard";
+
+ private static final String LABEL_SAVE = "Save...";
private RepositoryTaskEditorInput editorInput;
@@ -1199,7 +1201,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage {
}
};
- final Action saveAction = new Action(SaveRemoteFileAction.TITLE) {
+ final Action saveAction = new Action(LABEL_SAVE) {
public void run() {
RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer.getSelection()).getFirstElement());
/* Launch Browser */
@@ -1222,26 +1224,14 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage {
}
fileChooser.setFileName(fname);
String filePath = fileChooser.open();
-
- // Check if the dialog was canceled or an error occured
+ // Check if the dialog was canceled or an error occurred
if (filePath == null) {
return;
}
- // TODO: Use IAttachmentHandler instead
- AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager()
- .getRepositoryConnector(repository.getKind());
- IAttachmentHandler handler = connector.getAttachmentHandler();
-
- SaveRemoteFileAction save = new SaveRemoteFileAction();
- try {
- save.setInputStream(handler.getAttachmentAsStream(repository, attachment,
- new NullProgressMonitor()));
- save.setDestinationFilePath(filePath);
- save.run();
- } catch (CoreException e) {
- MylarStatusHandler.fail(e.getStatus().getException(), "Attachment save failed", false);
- }
+ DownloadAttachmentJob job = new DownloadAttachmentJob(attachment, new File(filePath));
+ job.setUser(true);
+ job.schedule();
}
};

Back to the top