Search in sources :

Example 1 with StartClientToServerFileUploadDialog

use of org.netxms.ui.eclipse.filemanager.dialogs.StartClientToServerFileUploadDialog in project netxms by netxms.

the class AgentFileManager method uploadFile.

/**
 * Upload local file to agent
 */
private void uploadFile(final boolean overvrite) {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return;
    final Object[] objects = selection.toArray();
    final AgentFile upladFolder = ((AgentFile) objects[0]).isDirectory() ? ((AgentFile) objects[0]) : ((AgentFile) objects[0]).getParent();
    final StartClientToServerFileUploadDialog dlg = new StartClientToServerFileUploadDialog(getSite().getShell());
    if (dlg.open() == Window.OK) {
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob(Messages.get().AgentFileManager_UploadFileJobTitle, null, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(final IProgressMonitor monitor) throws Exception {
                List<File> fileList = dlg.getLocalFiles();
                for (int i = 0; i < fileList.size(); i++) {
                    final File localFile = fileList.get(i);
                    String remoteFile = fileList.get(i).getName();
                    if (fileList.size() == 1)
                        remoteFile = dlg.getRemoteFileName();
                    final String rFileName = remoteFile;
                    new NestedVerifyOverwrite(localFile.isDirectory() ? AgentFile.DIRECTORY : AgentFile.FILE, localFile.getName(), true, true, false) {

                        @Override
                        public void executeAction() throws NXCException, IOException {
                            session.uploadLocalFileToAgent(objectId, localFile, upladFolder.getFullName() + "/" + rFileName, overvrite, new // $NON-NLS-1$
                            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
                        public void executeSameFunctionWithOverwrite() throws IOException, NXCException {
                            session.uploadLocalFileToAgent(objectId, localFile, upladFolder.getFullName() + "/" + rFileName, true, new // $NON-NLS-1$
                            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();
                        }
                    }.run(viewer.getControl().getDisplay());
                }
                upladFolder.setChildren(session.listAgentFiles(upladFolder, upladFolder.getFullName(), objectId));
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        viewer.refresh(upladFolder, true);
                    }
                });
            }

            @Override
            protected String getErrorMessage() {
                return "Cannot upload file to remote agent";
            }
        }.start();
    }
}
Also used : NXCSession(org.netxms.client.NXCSession) AgentFile(org.netxms.client.server.AgentFile) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StartClientToServerFileUploadDialog(org.netxms.ui.eclipse.filemanager.dialogs.StartClientToServerFileUploadDialog) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) ArrayList(java.util.ArrayList) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) AgentFile(org.netxms.client.server.AgentFile) File(java.io.File)

Example 2 with StartClientToServerFileUploadDialog

use of org.netxms.ui.eclipse.filemanager.dialogs.StartClientToServerFileUploadDialog in project netxms by netxms.

the class ServerFileManager method createFile.

/**
 * Create new file
 */
private void createFile() {
    final StartClientToServerFileUploadDialog dlg = new StartClientToServerFileUploadDialog(getSite().getShell());
    if (dlg.open() == Window.OK) {
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob(Messages.get().UploadFileToServer_JobTitle, null, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(final IProgressMonitor monitor) throws Exception {
                List<File> fileList = dlg.getLocalFiles();
                for (int i = 0; i < fileList.size(); i++) {
                    final File localFile = fileList.get(i);
                    String remoteFile = fileList.get(i).getName();
                    if (fileList.size() == 1)
                        remoteFile = dlg.getRemoteFileName();
                    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) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) ServerFile(org.netxms.client.server.ServerFile) File(java.io.File) StartClientToServerFileUploadDialog(org.netxms.ui.eclipse.filemanager.dialogs.StartClientToServerFileUploadDialog) PartInitException(org.eclipse.ui.PartInitException)

Example 3 with StartClientToServerFileUploadDialog

use of org.netxms.ui.eclipse.filemanager.dialogs.StartClientToServerFileUploadDialog 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

File (java.io.File)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 NXCSession (org.netxms.client.NXCSession)3 StartClientToServerFileUploadDialog (org.netxms.ui.eclipse.filemanager.dialogs.StartClientToServerFileUploadDialog)3 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)3 List (java.util.List)2 PartInitException (org.eclipse.ui.PartInitException)2 ProgressListener (org.netxms.client.ProgressListener)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 NXCException (org.netxms.client.NXCException)1 AgentFile (org.netxms.client.server.AgentFile)1 ServerFile (org.netxms.client.server.ServerFile)1