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();
}
}
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();
}
}
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();
}
}
}
Aggregations