use of org.netxms.client.server.AgentFile in project netxms by netxms.
the class AgentFileManager method uploadFolder.
/**
* Upload local folder to agent
*/
private void uploadFolder() {
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 StartClientToAgentFolderUploadDialog dlg = new StartClientToAgentFolderUploadDialog(getSite().getShell());
if (dlg.open() == Window.OK) {
ConsoleJob job = new UploadConsoleJob(Messages.get().AgentFileManager_UploadFolderJobTitle, null, Activator.PLUGIN_ID, null, dlg.getLocalFile(), upladFolder, dlg.getRemoteFileName());
job.start();
}
}
use of org.netxms.client.server.AgentFile in project netxms by netxms.
the class AgentFileManager method enableInPlaceRename.
/**
* Enable in-place renames
*/
private void enableInPlaceRename() {
TreeViewerEditor.create(viewer, new ColumnViewerEditorActivationStrategy(viewer) {
@Override
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
}, ColumnViewerEditor.DEFAULT);
viewer.setCellEditors(new CellEditor[] { new TextCellEditor(viewer.getTree()) });
// $NON-NLS-1$
viewer.setColumnProperties(new String[] { "name" });
viewer.setCellModifier(new ICellModifier() {
@Override
public void modify(Object element, String property, Object value) {
if (element instanceof Item)
element = ((Item) element).getData();
if (// $NON-NLS-1$
property.equals("name")) {
if (element instanceof AgentFile) {
doRename((AgentFile) element, value.toString());
}
}
}
@Override
public Object getValue(Object element, String property) {
if (// $NON-NLS-1$
property.equals("name")) {
if (element instanceof AgentFile) {
return ((AgentFile) element).getName();
}
}
return null;
}
@Override
public boolean canModify(Object element, String property) {
// $NON-NLS-1$
return property.equals("name");
}
});
}
use of org.netxms.client.server.AgentFile in project netxms by netxms.
the class AgentFileManager method fillContextMenu.
/**
* Fill context menu
*
* @param mgr Menu manager
*/
protected void fillContextMenu(final IMenuManager mgr) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.isEmpty())
return;
if (selection.size() == 1) {
if (((AgentFile) selection.getFirstElement()).isDirectory()) {
mgr.add(actionUploadFile);
} else {
mgr.add(actionTailFile);
mgr.add(actionShowFile);
}
}
mgr.add(actionDownloadFile);
if (isFolderOnlySelection(selection))
mgr.add(actionCalculateFolderSize);
mgr.add(new Separator());
if (selection.size() == 1) {
if (((AgentFile) selection.getFirstElement()).isDirectory()) {
mgr.add(actionCreateDirectory);
}
mgr.add(actionRename);
}
mgr.add(actionDelete);
mgr.add(new Separator());
if (selection.size() == 1) {
mgr.add(actionCopyFileName);
mgr.add(actionCopyFilePath);
}
mgr.add(new Separator());
mgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
if ((selection.size() == 1) && ((AgentFile) selection.getFirstElement()).isDirectory()) {
mgr.add(new Separator());
mgr.add(actionRefreshDirectory);
}
}
use of org.netxms.client.server.AgentFile in project netxms by netxms.
the class AgentFileManager method tailFile.
/**
* Starts file tail
*/
private void tailFile(final boolean followChanges, final int offset) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.isEmpty())
return;
final Object[] objects = selection.toArray();
if (((AgentFile) objects[0]).isDirectory())
return;
final AgentFile sf = ((AgentFile) objects[0]);
ConsoleJobCallingServerJob job = new ConsoleJobCallingServerJob(Messages.get().AgentFileManager_DownloadJobTitle, null, Activator.PLUGIN_ID, null) {
@Override
protected String getErrorMessage() {
return String.format(Messages.get().AgentFileManager_DownloadJobError, sf.getFullName(), objectId);
}
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
final AgentFileData file = session.downloadFileFromAgent(objectId, sf.getFullName(), offset, followChanges, new ProgressListener() {
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask("Download file " + sf.getFullName(), (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) workDone);
}
}, this);
runInUIThread(new Runnable() {
@Override
public void run() {
try {
// $NON-NLS-1$ //$NON-NLS-2$
String secondaryId = Long.toString(objectId) + "&" + URLEncoder.encode(sf.getName(), "UTF-8");
AgentFileViewer.createView(secondaryId, objectId, file, followChanges);
} catch (Exception e) {
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
MessageDialogHelper.openError(window.getShell(), Messages.get().AgentFileManager_Error, String.format(Messages.get().AgentFileManager_OpenViewError, e.getLocalizedMessage()));
Activator.logError("Exception in AgentFileManager.tailFile", e);
}
}
});
}
};
job.start();
}
use of org.netxms.client.server.AgentFile in project netxms by netxms.
the class AgentFileManager method startDownload.
/**
* Download file from agent
*/
private void startDownload() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.size() != 1)
return;
final AgentFile sf = (AgentFile) selection.getFirstElement();
if (!sf.isDirectory()) {
downloadFile(sf.getFullName());
} else {
ConsoleJobCallingServerJob job = new ConsoleJobCallingServerJob("Download from agent", null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
// create zip from download folder wile download
long dirSize = -1;
try {
dirSize = session.getAgentFileInfo(sf).getSize();
} catch (Exception e) {
}
monitor.beginTask(String.format("Downloading directory %s", sf.getName()), (int) dirSize);
final File zipFile = File.createTempFile("download_", ".zip");
FileOutputStream fos = new FileOutputStream(zipFile);
ZipOutputStream zos = new ZipOutputStream(fos);
downloadDir(sf, sf.getName(), zos, monitor, this);
zos.close();
fos.close();
if (!isCanceled()) {
DownloadServiceHandler.addDownload(zipFile.getName(), sf.getName() + ".zip", zipFile, "application/octet-stream");
runInUIThread(new Runnable() {
@Override
public void run() {
DownloadServiceHandler.startDownload(zipFile.getName());
}
});
}
monitor.done();
}
@Override
protected String getErrorMessage() {
return Messages.get().AgentFileManager_DirectoryReadError;
}
};
job.start();
}
}
Aggregations