Search in sources :

Example 96 with ConsoleJob

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

the class DeleteObject method execute.

/* (non-Javadoc)
    * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
    */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    ISelection selection = window.getActivePage().getSelection();
    if ((selection == null) || !(selection instanceof IStructuredSelection) || selection.isEmpty())
        return null;
    String question;
    if (((IStructuredSelection) selection).size() == 1) {
        question = String.format(Messages.get().DeleteObject_ConfirmQuestionSingular, ((AbstractObject) ((IStructuredSelection) selection).getFirstElement()).getObjectName());
    } else {
        question = Messages.get().DeleteObject_ConfirmQuestionPlural;
    }
    boolean confirmed = MessageDialogHelper.openConfirm(window.getShell(), Messages.get().DeleteObject_ConfirmDelete, question);
    if (confirmed) {
        if (((IStructuredSelection) selection).getFirstElement() instanceof AbstractObject) {
            final Object[] objects = ((IStructuredSelection) selection).toArray();
            Arrays.sort(objects, new Comparator<Object>() {

                @Override
                public int compare(Object arg0, Object arg1) {
                    if (arg0 instanceof AbstractObject && arg1 instanceof AbstractObject)
                        if (((AbstractObject) arg0).isChildOf(((AbstractObject) arg1).getObjectId()))
                            return -1;
                    return 1;
                }
            });
            final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
            new ConsoleJob(Messages.get().DeleteObject_JobName, null, Activator.PLUGIN_ID, null) {

                @Override
                protected void runInternal(IProgressMonitor monitor) throws Exception {
                    for (Object o : objects) {
                        if (o instanceof AbstractObject)
                            session.deleteObject(((AbstractObject) o).getObjectId());
                    }
                }

                @Override
                protected String getErrorMessage() {
                    return Messages.get().DeleteObject_JobError;
                }
            }.start();
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) NXCSession(org.netxms.client.NXCSession) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExecutionException(org.eclipse.core.commands.ExecutionException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractObject(org.netxms.client.objects.AbstractObject) ISelection(org.eclipse.jface.viewers.ISelection) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 97 with ConsoleJob

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

the class CreateNode method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    CreateNodeDialog dlg = null;
    do {
        dlg = new CreateNodeDialog(window.getShell(), dlg);
        if (dlg.open() != Window.OK)
            return;
        final NXCObjectCreationData cd = new NXCObjectCreationData(AbstractObject.OBJECT_NODE, dlg.getObjectName(), parentId);
        cd.setCreationFlags(dlg.getCreationFlags());
        cd.setPrimaryName(dlg.getHostName());
        cd.setAgentPort(dlg.getAgentPort());
        cd.setSnmpPort(dlg.getSnmpPort());
        cd.setAgentProxyId(dlg.getAgentProxy());
        cd.setSnmpProxyId(dlg.getSnmpProxy());
        cd.setIcmpProxyId(dlg.getIcmpProxy());
        cd.setSshProxyId(dlg.getSshProxy());
        cd.setZoneUIN(dlg.getZoneUIN());
        cd.setSshLogin(dlg.getSshLogin());
        cd.setSshPassword(dlg.getSshPassword());
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob(Messages.get().CreateNode_JobTitle, part, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                session.createObject(cd);
            }

            @Override
            protected String getErrorMessage() {
                return String.format(Messages.get().CreateNode_JobError, cd.getName());
            }
        }.start();
    } while (dlg.isShowAgain());
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectCreationData(org.netxms.client.NXCObjectCreationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) CreateNodeDialog(org.netxms.ui.eclipse.objectmanager.dialogs.CreateNodeDialog)

Example 98 with ConsoleJob

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

the class CreateSensor method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    // Create wizard - first page with overall information and communication type, second page with communication details
    final CreateSensorWizard creationWizard = new CreateSensorWizard(parentId);
    WizardDialog dlg = new WizardDialog(window.getShell(), creationWizard);
    if (dlg.open() != Window.OK)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob("Create Sensor", part, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.createObject(creationWizard.getCreationData());
        }

        @Override
        protected String getErrorMessage() {
            return String.format("Create sensor %s", creationWizard.getCreationData().getName());
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CreateSensorWizard(org.netxms.ui.eclipse.objectmanager.wizards.CreateSensorWizard) NXCSession(org.netxms.client.NXCSession) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 99 with ConsoleJob

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

the class CreateZone method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    final CreateZoneDialog dlg = new CreateZoneDialog(window.getShell());
    if (dlg.open() != Window.OK)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().CreateZone_JobTitle, part, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            NXCObjectCreationData cd = new NXCObjectCreationData(AbstractObject.OBJECT_ZONE, dlg.getName(), parentId);
            cd.setZoneUIN(dlg.getZoneUIN());
            session.createObject(cd);
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().CreateZone_JobError, dlg.getName());
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) CreateZoneDialog(org.netxms.ui.eclipse.objectmanager.dialogs.CreateZoneDialog) NXCObjectCreationData(org.netxms.client.NXCObjectCreationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 100 with ConsoleJob

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

the class Agent method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected boolean applyChanges(final boolean isApply) {
    final NXCObjectModificationData md = new NXCObjectModificationData(node.getObjectId());
    if (isApply)
        setValid(false);
    try {
        md.setAgentPort(Integer.parseInt(agentPort.getText(), 10));
    } catch (NumberFormatException e) {
        MessageDialog.openWarning(getShell(), Messages.get().Communication_Warning, Messages.get().Communication_WarningInvalidAgentPort);
        if (isApply)
            setValid(true);
        return false;
    }
    md.setAgentProxy(agentProxy.getObjectId());
    md.setAgentAuthMethod(agentAuthMethod.getSelectionIndex());
    md.setAgentSecret(agentSharedSecret.getText());
    md.setAgentCompressionMode(collectAgentCompressionMode());
    md.setObjectFlags(agentForceEncryption.getSelection() ? AbstractNode.NF_FORCE_ENCRYPTION : 0, AbstractNode.NF_FORCE_ENCRYPTION);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(String.format("Updating agent communication settings for node %s", node.getObjectName()), null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.modifyObject(md);
        }

        @Override
        protected String getErrorMessage() {
            return String.format("Cannot update communication settings for node %s", node.getObjectName());
        }

        @Override
        protected void jobFinalize() {
            if (isApply) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        Agent.this.setValid(true);
                    }
                });
            }
        }
    }.start();
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

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