Search in sources :

Example 41 with ConsoleJob

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

the class PackageManager method installPackage.

/**
 * Install new package
 */
private void installPackage() {
    FileDialog fd = new FileDialog(getSite().getShell(), SWT.OPEN);
    fd.setText(Messages.get().PackageManager_SelectFile);
    String npiName = fd.open();
    if (npiName != null) {
        try {
            final File npiFile = new File(npiName);
            final PackageInfo p = new PackageInfo(npiFile);
            final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
            new ConsoleJob(Messages.get().PackageManager_InstallPackage, this, Activator.PLUGIN_ID, null) {

                @Override
                protected void runInternal(final IProgressMonitor monitor) throws Exception {
                    final long id = session.installPackage(p, new File(npiFile.getParent(), p.getFileName()), new ProgressListener() {

                        long prevAmount = 0;

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

                        @Override
                        public void markProgress(long amount) {
                            monitor.worked((int) (amount - prevAmount));
                            prevAmount = amount;
                        }
                    });
                    p.setId(id);
                    runInUIThread(new Runnable() {

                        @Override
                        public void run() {
                            packageList.add(p);
                            viewer.setInput(packageList.toArray());
                        }
                    });
                }

                @Override
                protected String getErrorMessage() {
                    return Messages.get().PackageManager_InstallError;
                }
            }.start();
        } catch (IOException e) {
            MessageDialogHelper.openError(getSite().getShell(), Messages.get().PackageManager_Error, Messages.get().PackageManager_PkgFileOpenError + e.getLocalizedMessage());
        }
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ProgressListener(org.netxms.client.ProgressListener) PackageInfo(org.netxms.client.packages.PackageInfo) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) IOException(java.io.IOException) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 42 with ConsoleJob

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

the class PackageManager method deployPackage.

/**
 * Deploy package on managed nodes
 */
private void deployPackage() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    final PackageInfo pkg = (PackageInfo) selection.getFirstElement();
    ObjectSelectionDialog dlg = new ObjectSelectionDialog(getSite().getShell(), null, ObjectSelectionDialog.createNodeSelectionFilter(false));
    dlg.enableMultiSelection(true);
    if (dlg.open() != Window.OK)
        return;
    final Set<Long> objects = new HashSet<Long>();
    for (AbstractObject o : dlg.getSelectedObjects()) {
        objects.add(o.getObjectId());
    }
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    ConsoleJob job = new ConsoleJob(Messages.get().PackageManager_DeployAgentPackage, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.deployPackage(pkg.getId(), objects.toArray(new Long[objects.size()]), new PackageDeploymentListener() {

                private PackageDeploymentMonitor monitor = null;

                @Override
                public void statusUpdate(long nodeId, int status, String message) {
                    if (monitor != null)
                        monitor.viewStatusUpdate(nodeId, status, message);
                }

                @Override
                public void deploymentStarted() {
                    final Object sync = new Object();
                    synchronized (sync) {
                        runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    monitor = (PackageDeploymentMonitor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(PackageDeploymentMonitor.ID, toString(), IWorkbenchPage.VIEW_ACTIVATE);
                                    monitor.setPackageId(pkg.getId());
                                } catch (PartInitException e) {
                                    MessageDialogHelper.openError(getSite().getShell(), Messages.get().PackageManager_Error, Messages.get().PackageManager_ErrorOpenView + e.getLocalizedMessage());
                                }
                                synchronized (sync) {
                                    sync.notify();
                                }
                            }
                        });
                        try {
                            sync.wait();
                        } catch (InterruptedException e) {
                        }
                    }
                }

                @Override
                public void deploymentComplete() {
                    runInUIThread(new Runnable() {

                        @Override
                        public void run() {
                            MessageDialogHelper.openInformation(getSite().getShell(), Messages.get().PackageManager_Information, Messages.get().PackageManager_PkgDepCompleted);
                        }
                    });
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().PackageManager_DepStartError;
        }
    };
    job.setUser(false);
    job.start();
}
Also used : NXCSession(org.netxms.client.NXCSession) PackageInfo(org.netxms.client.packages.PackageInfo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PackageDeploymentListener(org.netxms.client.packages.PackageDeploymentListener) ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractObject(org.netxms.client.objects.AbstractObject) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) HashSet(java.util.HashSet)

Example 43 with ConsoleJob

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

the class ServerStoredAgentConfigEditorView method onSelectionChange.

/**
 * @param event
 */
private void onSelectionChange(SelectionChangedEvent event) {
    if (reselection) {
        reselection = false;
        return;
    }
    if (modified) {
        SaveStoredConfigDialog dlg = new SaveStoredConfigDialog(getSite().getShell());
        int rc = dlg.open();
        if (rc == SaveStoredConfigDialog.SAVE_ID) {
            intermediateSave();
            modified = false;
            firePropertyChange(PROP_DIRTY);
            actionSave.setEnabled(false);
            return;
        }
        if (rc == SaveStoredConfigDialog.CANCEL) {
            reselection = true;
            configList.setSelection(previousSelection);
            return;
        }
    }
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    previousSelection = selection;
    if (selection == null)
        return;
    final ConfigListElement element = (ConfigListElement) selection.getFirstElement();
    new ConsoleJob(Messages.get().ServerStoredAgentConfigEditorView_JobTitle_GetContent, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            if (element != null) {
                content = session.getConfigContent(element.getId());
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        updateContent();
                    }
                });
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().ServerStoredAgentConfigEditorView_JobError_GetContent;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SaveStoredConfigDialog(org.netxms.ui.eclipse.agentmanager.dialogs.SaveStoredConfigDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConfigListElement(org.netxms.client.agent.config.ConfigListElement) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Example 44 with ConsoleJob

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

the class ServerStoredAgentConfigEditorView method intermediateSave.

/**
 */
public void intermediateSave() {
    if (content == null)
        return;
    content.setConfig(configEditor.getText());
    content.setFilter(filterEditor.getText());
    content.setName(nameField.getText());
    new ConsoleJob(Messages.get().ServerStoredAgentConfigEditorView_JobSave, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.saveAgentConfig(content);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    getConfigList();
                }
            });
        }

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

Example 45 with ConsoleJob

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

the class ServerStoredAgentConfigEditorView method moveDown.

/**
 * Move selected item down
 */
private void moveDown() {
    IStructuredSelection selection = (IStructuredSelection) configList.getSelection();
    if (selection == null)
        return;
    final ConfigListElement element1 = (ConfigListElement) selection.getFirstElement();
    int index = elements.indexOf(element1);
    if (index >= (elements.size() - 1))
        return;
    final ConfigListElement elemen2 = elements.get(index + 1);
    new ConsoleJob(Messages.get().ServerStoredAgentConfigEditorView_JobMoveDown, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.swapAgentConfigs(element1.getId(), elemen2.getId());
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    getConfigList();
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().ServerStoredAgentConfigEditorView_JobError_MoveDown;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConfigListElement(org.netxms.client.agent.config.ConfigListElement) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

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