use of org.netxms.ui.eclipse.filemanager.dialogs.StartServerToAgentFileUploadDialog in project netxms by netxms.
the class UploadFileToAgent method run.
/**
* @see IActionDelegate#run(IAction)
*/
public void run(IAction action) {
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
boolean canScheduleFileUpload = (session.getUserSystemRights() & UserAccessRights.SYSTEM_ACCESS_SCHEDULE_FILE_UPLOAD) > 0;
final StartServerToAgentFileUploadDialog dlg = new StartServerToAgentFileUploadDialog(shell, canScheduleFileUpload);
if (dlg.open() == Window.OK) {
final Long[] nodeIdList = nodes.toArray(new Long[nodes.size()]);
new ConsoleJob(Messages.get().UploadFileToAgent_JobTitle, viewPart, Activator.PLUGIN_ID, null) {
@Override
protected String getErrorMessage() {
return Messages.get().UploadFileToAgent_JobError;
}
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
boolean multipleFiles = dlg.getServerFiles().size() > 1;
for (ServerFile sf : dlg.getServerFiles()) {
String remoteFileName = dlg.getRemoteFileName();
if (!remoteFileName.isEmpty()) {
if (// $NON-NLS-1$ //$NON-NLS-2$
remoteFileName.endsWith("/") || remoteFileName.endsWith("\\")) {
remoteFileName += sf.getName();
} else if (multipleFiles) {
remoteFileName += "/" + sf.getName();
}
} else {
if (!dlg.isScheduled())
remoteFileName = null;
}
for (int i = 0; i < nodeIdList.length; i++) {
if (dlg.isScheduled()) {
ScheduledTask task = dlg.getScheduledTask();
// $NON-NLS-1$
String parameters = sf.getName() + "," + remoteFileName;
task.setParameters(parameters);
task.setObjectId(nodeIdList[i]);
session.addSchedule(task);
} else {
session.uploadFileToAgent(nodeIdList[i], sf.getName(), remoteFileName, dlg.isCreateJobOnHold());
}
}
}
}
}.start();
}
}
Aggregations