From 28c493cbe79d4c22ecfdcbe959412ce709c165a2 Mon Sep 17 00:00:00 2001 From: Greg Watson Date: Fri, 31 Jan 2014 15:10:03 -0500 Subject: [PATCH] Add prefix to progress monitor task Signed-off-by: Greg Watson --- .../core/commands/AbstractRemoteCommand.java | 19 ++++++++++++++----- .../core/commands/GetInputStreamCommand.java | 4 +++- .../core/commands/GetOutputStreamCommand.java | 9 +++++++-- .../internal/jsch/core/messages/Messages.java | 4 ++++ .../jsch/core/messages/messages.properties | 2 ++ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/AbstractRemoteCommand.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/AbstractRemoteCommand.java index 613f3b81529..45105c2d1dc 100755 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/AbstractRemoteCommand.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/AbstractRemoteCommand.java @@ -50,11 +50,17 @@ public abstract class AbstractRemoteCommand { private Long fMaxWork; private String fMaxWorkSize; private long fWorkToDate; + private String fPrefix; public CommandProgressMonitor(IProgressMonitor monitor) { fMonitor = monitor; } + public CommandProgressMonitor(String prefix, IProgressMonitor monitor) { + fPrefix = prefix; + fMonitor = monitor; + } + @Override public boolean count(long count) { fWorkToDate += count; @@ -67,15 +73,18 @@ public abstract class AbstractRemoteCommand { size = "KB"; //$NON-NLS-1$ workToDate = fWorkToDate / 1024L; } - String subDesc; + StringBuffer taskName = new StringBuffer(); + if (fPrefix != null) { + taskName.append(fPrefix); + } if (fWorkPercentFactor < 0) { - subDesc = MessageFormat.format(Messages.AbstractRemoteCommand_format1, new Object[] { workToDate, size }); + taskName.append(MessageFormat.format(Messages.AbstractRemoteCommand_format1, new Object[] { workToDate, size })); } else { Double workPercent = new Double(fWorkPercentFactor * fWorkToDate); - subDesc = MessageFormat.format(Messages.AbstractRemoteCommand_format2, new Object[] { workToDate, size, fMaxWork, - fMaxWorkSize, workPercent }); + taskName.append(MessageFormat.format(Messages.AbstractRemoteCommand_format2, new Object[] { workToDate, size, + fMaxWork, fMaxWorkSize, workPercent })); } - fMonitor.subTask(subDesc); + fMonitor.subTask(taskName.toString()); fMonitor.worked((int) count); return !(fMonitor.isCanceled()); } diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/GetInputStreamCommand.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/GetInputStreamCommand.java index 25114ba540d..9c3743d3afa 100644 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/GetInputStreamCommand.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/GetInputStreamCommand.java @@ -6,8 +6,10 @@ import java.io.InputStream; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.osgi.util.NLS; import org.eclipse.remote.core.exception.RemoteConnectionException; import org.eclipse.remote.internal.jsch.core.JSchConnection; +import org.eclipse.remote.internal.jsch.core.messages.Messages; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.SftpException; @@ -28,7 +30,7 @@ public class GetInputStreamCommand extends AbstractRemoteCommand { public InputStream call() throws JSchException, SftpException, IOException { try { return getConnection().getSftpChannel().get(fRemotePath.toString(), - new CommandProgressMonitor(getProgressMonitor())); + new CommandProgressMonitor(NLS.bind(Messages.GetInputStreamCommand_Receiving, fRemotePath.toString()), getProgressMonitor())); } catch (RemoteConnectionException e) { throw new IOException(e.getMessage()); } diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/GetOutputStreamCommand.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/GetOutputStreamCommand.java index 2d8f56fc706..3102fe6ac40 100644 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/GetOutputStreamCommand.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/GetOutputStreamCommand.java @@ -11,8 +11,10 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.osgi.util.NLS; import org.eclipse.remote.core.exception.RemoteConnectionException; import org.eclipse.remote.internal.jsch.core.JSchConnection; +import org.eclipse.remote.internal.jsch.core.messages.Messages; import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.JSchException; @@ -48,8 +50,11 @@ public class GetOutputStreamCommand extends AbstractRemoteCommand if ((fOptions & EFS.APPEND) != 0) { mode = ChannelSftp.APPEND; } - getChannel().put(input, fRemotePath.toString(), - new CommandProgressMonitor(getProgressMonitor()), mode); + getChannel().put( + input, + fRemotePath.toString(), + new CommandProgressMonitor(NLS.bind(Messages.GetOutputStreamCommand_Sending, fRemotePath.toString()), + getProgressMonitor()), mode); input.close(); } finally { fIsClosed = true; diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/Messages.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/Messages.java index 4d75effcc54..8a42c09de63 100755 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/Messages.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/Messages.java @@ -22,6 +22,10 @@ public class Messages extends NLS { public static String AbstractRemoteCommand_Operation_cancelled_by_user; public static String AuthInfo_Authentication_message; public static String ExecCommand_Exec_command; + + public static String GetInputStreamCommand_Receiving; + + public static String GetOutputStreamCommand_Sending; public static String JSchConnection_Connection_was_cancelled; public static String JSchConnection_connectionNotOpen; public static String JSchConnection_Executing_command; diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/messages.properties b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/messages.properties index f36307c4bf3..40339a21517 100755 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/messages.properties +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/messages/messages.properties @@ -14,6 +14,8 @@ AbstractRemoteCommand_Get_symlink_target=Get symlink target AbstractRemoteCommand_Operation_cancelled_by_user=Operation cancelled by user AuthInfo_Authentication_message=Authentication Message ExecCommand_Exec_command=Executing command "{0}" +GetInputStreamCommand_Receiving=Receiving {0}: +GetOutputStreamCommand_Sending=Sending {0}: JSchConnection_Connection_was_cancelled=Connection was cancelled JSchConnection_connectionNotOpen=Connection is not open JSchConnection_Executing_command=Executing command "{0}"