diff options
-rwxr-xr-x | incubation/bundles/org.eclipse.ecf.mylyn.ui/src/org/eclipse/ecf/internal/mylyn/ui/SendContextContributionItem.java | 40 |
1 files changed, 8 insertions, 32 deletions
diff --git a/incubation/bundles/org.eclipse.ecf.mylyn.ui/src/org/eclipse/ecf/internal/mylyn/ui/SendContextContributionItem.java b/incubation/bundles/org.eclipse.ecf.mylyn.ui/src/org/eclipse/ecf/internal/mylyn/ui/SendContextContributionItem.java index e6b6bbb62..4923de781 100755 --- a/incubation/bundles/org.eclipse.ecf.mylyn.ui/src/org/eclipse/ecf/internal/mylyn/ui/SendContextContributionItem.java +++ b/incubation/bundles/org.eclipse.ecf.mylyn.ui/src/org/eclipse/ecf/internal/mylyn/ui/SendContextContributionItem.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. + * Copyright (c) 2007, 2008 IBM Corporation 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 @@ -10,8 +10,7 @@ *******************************************************************************/ package org.eclipse.ecf.internal.mylyn.ui; -import java.io.*; -import java.net.URLEncoder; +import java.io.ByteArrayOutputStream; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.*; @@ -26,7 +25,6 @@ import org.eclipse.ecf.presence.ui.menu.AbstractRosterMenuContributionItem; import org.eclipse.ecf.presence.ui.menu.AbstractRosterMenuHandler; import org.eclipse.jface.action.IContributionItem; import org.eclipse.jface.viewers.*; -import org.eclipse.mylyn.internal.tasks.ui.ITasksUiConstants; import org.eclipse.mylyn.tasks.core.AbstractTask; import org.eclipse.mylyn.tasks.ui.TasksUiPlugin; import org.eclipse.ui.IWorkbenchPart; @@ -40,14 +38,6 @@ public class SendContextContributionItem extends AbstractRosterMenuContributionI setTopMenuImageDescriptor(Activator.getDefault().getImageRegistry().getDescriptor("IMG_SHARED_TASK")); } - private String encodeName(AbstractTask task) { - try { - return URLEncoder.encode(task.getHandleIdentifier(), ITasksUiConstants.FILENAME_ENCODING); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } - protected IContributionItem[] createContributionItemsForPresenceContainer(IPresenceContainerAdapter presenceContainerAdapter) { // if this IPCA doesn't support the datashare APIs, we should not create any contribution items IChannelContainerAdapter channelAdapter = (IChannelContainerAdapter) presenceContainerAdapter.getAdapter(IChannelContainerAdapter.class); @@ -90,30 +80,16 @@ public class SendContextContributionItem extends AbstractRosterMenuContributionI final AbstractTask task = (AbstractTask) element; Job job = new Job("Send Task") { protected IStatus run(IProgressMonitor monitor) { - monitor.beginTask("Sending task...", 100); - File tmpDir = new File(System.getProperty("java.io.tmpdir")); //$NON-NLS-1$ - File outputFile = new File(tmpDir, encodeName(task)); - TasksUiPlugin.getTaskListManager().getTaskListWriter().writeTask(task, outputFile); - monitor.worked(30); - FileInputStream stream = null; + monitor.beginTask("Sending task...", 5); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + TasksUiPlugin.getTaskListManager().getTaskListWriter().writeTask(task, stream); + monitor.worked(2); try { - byte[] data = new byte[(int) outputFile.length()]; - stream = new FileInputStream(outputFile); - stream.read(data); - monitor.worked(30); - channel.sendMessage(getRosterEntry().getUser().getID(), data); - monitor.worked(40); + channel.sendMessage(getRosterEntry().getUser().getID(), stream.toByteArray()); + monitor.worked(3); } catch (Exception e) { return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "An error occurred while sending the task.", e); } finally { - try { - if (stream != null) { - stream.close(); - } - } catch (Exception e) { - // ignored - } - outputFile.delete(); monitor.done(); } return Status.OK_STATUS; |