Search in sources :

Example 81 with NXCSession

use of org.netxms.client.NXCSession in project netxms by netxms.

the class ObjectToolExecutor method executeAgentAction.

/**
 * @param node
 * @param tool
 * @param inputValues
 */
private static void executeAgentAction(final ObjectContext node, final ObjectTool tool, final Map<String, String> inputValues) {
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    if ((tool.getFlags() & ObjectTool.GENERATES_OUTPUT) == 0) {
        new ConsoleJob(String.format(Messages.get().ObjectToolsDynamicMenu_ExecuteOnNode, node.object.getObjectName()), null, Activator.PLUGIN_ID, null) {

            @Override
            protected String getErrorMessage() {
                return String.format(Messages.get().ObjectToolsDynamicMenu_CannotExecuteOnNode, node.object.getObjectName());
            }

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                final String action = session.executeActionWithExpansion(node.object.getObjectId(), node.getAlarmId(), tool.getData(), inputValues);
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialogHelper.openInformation(null, Messages.get().ObjectToolsDynamicMenu_ToolExecution, String.format(Messages.get().ObjectToolsDynamicMenu_ExecSuccess, action, node.object.getObjectName()));
                    }
                });
            }
        }.start();
    } else {
        // $NON-NLS-1$
        final String secondaryId = Long.toString(node.object.getObjectId()) + "&" + Long.toString(tool.getId());
        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        try {
            AgentActionResults view = (AgentActionResults) window.getActivePage().showView(AgentActionResults.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
            view.executeAction(tool.getData(), node.getAlarmId(), inputValues);
        } catch (Exception e) {
            MessageDialogHelper.openError(window.getShell(), Messages.get().ObjectToolsDynamicMenu_Error, String.format(Messages.get().ObjectToolsDynamicMenu_ErrorOpeningView, e.getLocalizedMessage()));
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) AgentActionResults(org.netxms.ui.eclipse.objecttools.views.AgentActionResults) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Example 82 with NXCSession

use of org.netxms.client.NXCSession in project netxms by netxms.

the class RackPassiveElements method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected void applyChanges(final boolean isApply) {
    if (!isModified)
        // Nothing to apply
        return;
    if (isApply)
        setValid(false);
    final NXCObjectModificationData md = new NXCObjectModificationData(rack.getObjectId());
    try {
        md.setPassiveElements(passiveElements.createXml());
    } catch (Exception e) {
        MessageDialogHelper.openError(getShell(), "Rack attribute error", "Unable to save rack attribute configuration" + e.getMessage());
    }
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob("Update rack attributes", null, Activator.PLUGIN_ID, null) {

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

        @Override
        protected String getErrorMessage() {
            return "Rack attribute update error";
        }

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

                    @Override
                    public void run() {
                        isModified = true;
                    }
                });
            }
        }
    }.start();
}
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)

Example 83 with NXCSession

use of org.netxms.client.NXCSession in project netxms by netxms.

the class SNMP 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);
    md.setSnmpVersion(snmpIndexToVersion(snmpVersion.getSelectionIndex()));
    try {
        md.setSnmpPort(Integer.parseInt(snmpPort.getText(), 10));
    } catch (NumberFormatException e) {
        MessageDialog.openWarning(getShell(), Messages.get().Communication_Warning, Messages.get().Communication_WarningInvalidSNMPPort);
        if (isApply)
            setValid(true);
        return false;
    }
    md.setSnmpProxy(snmpProxy.getObjectId());
    md.setSnmpAuthMethod(snmpAuth.getSelectionIndex());
    md.setSnmpPrivMethod(snmpPriv.getSelectionIndex());
    md.setSnmpAuthName(snmpAuthName.getText());
    md.setSnmpAuthPassword(snmpAuthPassword.getText());
    md.setSnmpPrivPassword(snmpPrivPassword.getText());
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(String.format("Updating SNMP 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 SNMP settings for node %s", node.getObjectName());
        }

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

                    @Override
                    public void run() {
                        SNMP.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)

Example 84 with NXCSession

use of org.netxms.client.NXCSession in project netxms by netxms.

the class TrustedNodes method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected void applyChanges(final boolean isApply) {
    if (!isModified)
        // Nothing to apply
        return;
    if (isApply)
        setValid(false);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
    Set<Long> idList = trustedNodes.keySet();
    long[] nodes = new long[idList.size()];
    int i = 0;
    for (long id : idList) nodes[i++] = id;
    md.setTrustedNodes(nodes);
    new ConsoleJob(String.format(Messages.get().TrustedNodes_JobName, object.getObjectName()), null, Activator.PLUGIN_ID, null) {

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

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

                    @Override
                    public void run() {
                        TrustedNodes.this.setValid(true);
                    }
                });
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().TrustedNodes_JobError;
        }
    }.schedule();
}
Also used : NXCSession(org.netxms.client.NXCSession) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 85 with NXCSession

use of org.netxms.client.NXCSession in project netxms by netxms.

the class ZoneCommunications method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected boolean applyChanges(final boolean isApply) {
    if (isApply)
        setValid(false);
    final NXCObjectModificationData md = new NXCObjectModificationData(zone.getObjectId());
    md.setZoneProxy(agentProxy.getObjectId());
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(String.format(Messages.get().ZoneCommunications_JobName, zone.getObjectName()), null, Activator.PLUGIN_ID, null) {

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

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

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

                    @Override
                    public void run() {
                        ZoneCommunications.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

NXCSession (org.netxms.client.NXCSession)248 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)167 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)163 AbstractObject (org.netxms.client.objects.AbstractObject)54 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)45 PartInitException (org.eclipse.ui.PartInitException)31 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)28 List (java.util.List)26 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 NXCException (org.netxms.client.NXCException)22 ArrayList (java.util.ArrayList)19 GridData (org.eclipse.swt.layout.GridData)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 Composite (org.eclipse.swt.widgets.Composite)17 CreateObjectDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog)15 AbstractNode (org.netxms.client.objects.AbstractNode)14 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)13 IOException (java.io.IOException)11 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10