Search in sources :

Example 66 with ConsoleJob

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

the class AgentFileManager method doRename.

/**
 * Do actual rename
 *
 * @param AgentFile
 * @param newName
 */
private void doRename(final AgentFile agentFile, final String newName) {
    new ConsoleJob("Rename file", this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

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

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

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

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

                    @Override
                    public void run() {
                        if (verify.isOkPressed())
                            refreshFileOrDirectory();
                        agentFile.setName(newName);
                        viewer.refresh(agentFile, 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 67 with ConsoleJob

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

the class ServerFileManager method deleteFile.

/**
 * Delete selected file
 */
private void deleteFile() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return;
    if (!MessageDialogHelper.openConfirm(getSite().getShell(), Messages.get().ViewServerFile_DeleteConfirmation, Messages.get().ViewServerFile_DeletAck))
        return;
    final Object[] objects = selection.toArray();
    new ConsoleJob(Messages.get().ViewServerFile_DeletFileFromServerJob, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

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

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (int i = 0; i < objects.length; i++) {
                session.deleteServerFile(((ServerFile) objects[i]).getName());
            }
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ServerFile(org.netxms.client.server.ServerFile) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Example 68 with ConsoleJob

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

the class ServerFileManager method refreshFileList.

/**
 * Refresh file list
 */
private void refreshFileList() {
    final Display display = viewer.getControl().getDisplay();
    new ConsoleJob(Messages.get(display).SelectServerFileDialog_JobTitle, null, Activator.PLUGIN_ID, null, display) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            files = session.listServerFiles();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(files);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SelectServerFileDialog_JobError;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) Display(org.eclipse.swt.widgets.Display)

Example 69 with ConsoleJob

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

the class LogViewer method getMoreData.

/**
 * Get more data from server
 */
private void getMoreData() {
    if (noData)
        // we already know that there will be no more data
        return;
    new ConsoleJob(Messages.get().LogViewer_GetDataJob, this, Activator.PLUGIN_ID, JOB_FAMILY) {

        @Override
        protected String getErrorMessage() {
            return Messages.get().LogViewer_QueryError + logName;
        }

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final Table data = logHandle.retrieveData(resultSet.getRowCount(), PAGE_SIZE);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    resultSet.addAll(data);
                    viewer.setInput(resultSet.getAllRows());
                    noData = (data.getRowCount() < PAGE_SIZE);
                    actionGetMoreData.setEnabled(!noData);
                }
            });
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Table(org.netxms.client.Table) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Example 70 with ConsoleJob

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

the class ImageLibrary method editImage.

/**
 * @param galleryItem
 * @param name
 * @param category
 * @param fileName
 */
protected void editImage(final GalleryItem galleryItem, final String name, final String category, final String fileName) {
    final LibraryImage image = (LibraryImage) galleryItem.getData();
    new ConsoleJob(Messages.get().ImageLibrary_UpdateJob, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(final IProgressMonitor monitor) throws Exception {
            if (fileName != null) {
                verifyImageFile(fileName);
                FileInputStream stream = null;
                try {
                    final long fileSize = new File(fileName).length();
                    stream = new FileInputStream(fileName);
                    byte[] imageData = new byte[(int) fileSize];
                    stream.read(imageData);
                    image.setBinaryData(imageData);
                } finally {
                    if (stream != null)
                        stream.close();
                }
            }
            if (!image.isProtected()) {
                image.setName(name);
                image.setCategory(category);
            }
            session.modifyImage(image, new ProgressListener() {

                private long prevDone = 0;

                @Override
                public void setTotalWorkAmount(long workTotal) {
                    monitor.beginTask(Messages.get(getDisplay()).ImageLibrary_UpdateImage, (int) workTotal);
                }

                @Override
                public void markProgress(long workDone) {
                    monitor.worked((int) (workDone - prevDone));
                    prevDone = workDone;
                }
            });
            ImageProvider.getInstance(display).syncMetaData();
            refreshImages();
            /* TODO: update single element */
            monitor.done();
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().ImageLibrary_UpdateError;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressListener(org.netxms.client.ProgressListener) LibraryImage(org.netxms.client.LibraryImage) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) File(java.io.File) SWTException(org.eclipse.swt.SWTException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) FileInputStream(java.io.FileInputStream)

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