Search in sources :

Example 11 with AgentFile

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();
    }
}
Also used : StartClientToAgentFolderUploadDialog(org.netxms.ui.eclipse.filemanager.dialogs.StartClientToAgentFolderUploadDialog) AgentFile(org.netxms.client.server.AgentFile) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 12 with AgentFile

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");
        }
    });
}
Also used : Item(org.eclipse.swt.widgets.Item) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) AgentFile(org.netxms.client.server.AgentFile) ICellModifier(org.eclipse.jface.viewers.ICellModifier) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 13 with AgentFile

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);
    }
}
Also used : AgentFile(org.netxms.client.server.AgentFile) GroupMarker(org.eclipse.jface.action.GroupMarker) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Separator(org.eclipse.jface.action.Separator)

Example 14 with AgentFile

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();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) AgentFile(org.netxms.client.server.AgentFile) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AgentFileData(org.netxms.client.AgentFileData) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) ConsoleJobCallingServerJob(org.netxms.ui.eclipse.jobs.ConsoleJobCallingServerJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressListener(org.netxms.client.ProgressListener)

Example 15 with AgentFile

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();
    }
}
Also used : ConsoleJobCallingServerJob(org.netxms.ui.eclipse.jobs.ConsoleJobCallingServerJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AgentFile(org.netxms.client.server.AgentFile) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AgentFile(org.netxms.client.server.AgentFile) File(java.io.File) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Aggregations

AgentFile (org.netxms.client.server.AgentFile)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 IOException (java.io.IOException)7 PartInitException (org.eclipse.ui.PartInitException)7 NXCException (org.netxms.client.NXCException)7 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)7 File (java.io.File)4 ArrayList (java.util.ArrayList)3 AgentFileData (org.netxms.client.AgentFileData)3 ProgressListener (org.netxms.client.ProgressListener)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 ConsoleJobCallingServerJob (org.netxms.ui.eclipse.jobs.ConsoleJobCallingServerJob)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 List (java.util.List)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 GroupMarker (org.eclipse.jface.action.GroupMarker)1