use of org.netxms.client.ProgressListener in project netxms by netxms.
the class UploadFileToServer method run.
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
@Override
public void run(IAction action) {
final StartClientToServerFileUploadDialog dlg = new StartClientToServerFileUploadDialog(window.getShell());
if (dlg.open() == Window.OK) {
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
List<File> fileList = dlg.getLocalFiles();
for (int i = 0; i < fileList.size(); i++) {
final File localFile = fileList.get(i);
String tmp;
tmp = fileList.get(i).getName();
if (fileList.size() == 1)
tmp = dlg.getRemoteFileName();
final String remoteFile = tmp;
new ConsoleJob(Messages.get().UploadFileToServer_JobTitle, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
session.uploadFileToServer(localFile, remoteFile, new ProgressListener() {
private long prevWorkDone = 0;
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask(Messages.get(getDisplay()).UploadFileToServer_TaskNamePrefix + localFile.getAbsolutePath(), (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) (workDone - prevWorkDone));
prevWorkDone = workDone;
}
});
monitor.done();
}
@Override
protected String getErrorMessage() {
return Messages.get().UploadFileToServer_JobError;
}
}.start();
}
}
}
Aggregations