Search in sources :

Example 61 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class AgentFileManager method refreshFileOrDirectory.

/**
 * Refresh file list
 */
private void refreshFileOrDirectory() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return;
    final Object[] objects = selection.toArray();
    new ConsoleJob("Reading remote directory", null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (int i = 0; i < objects.length; i++) {
                if (!((AgentFile) objects[i]).isDirectory())
                    objects[i] = ((AgentFile) objects[i]).getParent();
                final AgentFile sf = ((AgentFile) objects[i]);
                sf.setChildren(session.listAgentFiles(sf, sf.getFullName(), objectId));
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        viewer.refresh(sf);
                    }
                });
            }
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot read remote directory";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AgentFile(org.netxms.client.server.AgentFile) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 62 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class AgentFileManager method calculateFolderSize.

/**
 * Show file size
 */
private void calculateFolderSize() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return;
    final List<AgentFile> files = new ArrayList<AgentFile>(selection.size());
    for (Object o : selection.toList()) files.add((AgentFile) o);
    new ConsoleJob("Calculate folder size", this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (AgentFile f : files) {
                f.setFileInfo(session.getAgentFileInfo(f));
            }
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.update(files.toArray(), null);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot calculate folder size";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AgentFile(org.netxms.client.server.AgentFile) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 63 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class AgentFileManager method moveFile.

/**
 * Move selected file
 */
private void moveFile(final AgentFile target, final AgentFile object) {
    new ConsoleJob(Messages.get().AgentFileManager_MoveFile, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        @Override
        protected String getErrorMessage() {
            return Messages.get().AgentFileManager_MoveError;
        }

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            NestedVerifyOverwrite verify = new NestedVerifyOverwrite(object.getType(), object.getName(), true, true, false) {

                @Override
                public void executeAction() throws NXCException, IOException {
                    // $NON-NLS-1$
                    session.renameAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName(), false);
                }

                @Override
                public void executeSameFunctionWithOverwrite() throws IOException, NXCException {
                    // $NON-NLS-1$
                    session.renameAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName(), true);
                }
            };
            verify.run(viewer.getControl().getDisplay());
            if (verify.isOkPressed()) {
                target.setChildren(session.listAgentFiles(target, target.getFullName(), objectId));
                object.getParent().setChildren(session.listAgentFiles(object.getParent(), object.getParent().getFullName(), objectId));
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        viewer.refresh(object.getParent(), true);
                        object.setParent(target);
                        viewer.refresh(object.getParent(), true);
                    }
                });
            }
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) IOException(java.io.IOException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException)

Example 64 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class AgentFileManager method createFolder.

/**
 * Create new folder
 */
private void createFolder() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return;
    final Object[] objects = selection.toArray();
    final AgentFile parentFolder = ((AgentFile) objects[0]).isDirectory() ? ((AgentFile) objects[0]) : ((AgentFile) objects[0]).getParent();
    final CreateFolderDialog dlg = new CreateFolderDialog(getSite().getShell());
    if (dlg.open() != Window.OK)
        return;
    final String newFolder = dlg.getNewName();
    new ConsoleJob(Messages.get().AgentFileManager_CreatingFolder, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        @Override
        protected String getErrorMessage() {
            return Messages.get().AgentFileManager_FolderCreationError;
        }

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            NestedVerifyOverwrite verify = new NestedVerifyOverwrite(AgentFile.DIRECTORY, newFolder, true, true, false) {

                @Override
                public void executeAction() throws NXCException, IOException {
                    // $NON-NLS-1$
                    session.createFolderOnAgent(objectId, parentFolder.getFullName() + "/" + newFolder);
                }

                @Override
                public void executeSameFunctionWithOverwrite() throws IOException, NXCException {
                // do nothing
                }
            };
            verify.run(viewer.getControl().getDisplay());
            parentFolder.setChildren(session.listAgentFiles(parentFolder, parentFolder.getFullName(), objectId));
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.refresh(parentFolder, true);
                }
            });
        }
    }.start();
}
Also used : AgentFile(org.netxms.client.server.AgentFile) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) CreateFolderDialog(org.netxms.ui.eclipse.filemanager.dialogs.CreateFolderDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 65 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob in project netxms by netxms.

the class AgentFileManager method copyFile.

/**
 * Copy agent file
 *
 * @param target where the file will be moved
 * @param object file being moved
 */
private void copyFile(final AgentFile target, final AgentFile object) {
    new ConsoleJob("Copying file", this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        @Override
        protected String getErrorMessage() {
            return "Cannot copy file";
        }

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            NestedVerifyOverwrite verify = new NestedVerifyOverwrite(object.getType(), object.getName(), true, true, false) {

                @Override
                public void executeAction() throws NXCException, IOException {
                    // $NON-NLS-1$
                    session.copyAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName(), false);
                }

                @Override
                public void executeSameFunctionWithOverwrite() throws IOException, NXCException {
                    // $NON-NLS-1$
                    session.copyAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName(), true);
                }
            };
            verify.run(viewer.getControl().getDisplay());
            if (verify.isOkPressed()) {
                target.setChildren(session.listAgentFiles(target, target.getFullName(), objectId));
                object.getParent().setChildren(session.listAgentFiles(object.getParent(), object.getParent().getFullName(), objectId));
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        viewer.refresh(object.getParent(), true);
                        object.setParent(target);
                        viewer.refresh(target, true);
                    }
                });
            }
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) IOException(java.io.IOException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException)

Aggregations

ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)330 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)329 NXCSession (org.netxms.client.NXCSession)163 PartInitException (org.eclipse.ui.PartInitException)113 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)81 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)45 NXCException (org.netxms.client.NXCException)44 List (java.util.List)38 ArrayList (java.util.ArrayList)34 AbstractObject (org.netxms.client.objects.AbstractObject)33 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)28 IOException (java.io.IOException)27 CreateObjectDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog)16 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)13 File (java.io.File)12 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)10 Script (org.netxms.client.Script)10 Table (org.netxms.client.Table)10 CoreException (org.eclipse.core.runtime.CoreException)9 GridData (org.eclipse.swt.layout.GridData)9