Search in sources :

Example 11 with ProgressListener

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();
        }
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ProgressListener(org.netxms.client.ProgressListener) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) File(java.io.File) StartClientToServerFileUploadDialog(org.netxms.ui.eclipse.filemanager.dialogs.StartClientToServerFileUploadDialog)

Aggregations

ProgressListener (org.netxms.client.ProgressListener)11 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)9 File (java.io.File)6 AgentFileData (org.netxms.client.AgentFileData)6 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)5 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)4 PartInitException (org.eclipse.ui.PartInitException)4 NXCException (org.netxms.client.NXCException)4 NXCSession (org.netxms.client.NXCSession)4 ConsoleJobCallingServerJob (org.netxms.ui.eclipse.jobs.ConsoleJobCallingServerJob)4 AgentFile (org.netxms.client.server.AgentFile)3 SWTException (org.eclipse.swt.SWTException)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 LibraryImage (org.netxms.client.LibraryImage)2 StartClientToServerFileUploadDialog (org.netxms.ui.eclipse.filemanager.dialogs.StartClientToServerFileUploadDialog)2 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 List (java.util.List)1