Search in sources :

Example 26 with NXCSession

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

the class SelectAgentParamDlg method fillParameterList.

/*
    * (non-Javadoc)
    * 
    * @see org.netxms.ui.eclipse.datacollection.dialogs.AbstractSelectParamDlg#fillParameterList()
    */
@Override
protected void fillParameterList() {
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().SelectAgentParamDlg_JobTitle + object.getObjectName(), null, Activator.PLUGIN_ID, null) {

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

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            if (selectTables) {
                final List<AgentTable> tables = session.getSupportedTables(object.getObjectId());
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        viewer.setInput(tables.toArray());
                    }
                });
            } else {
                final List<AgentParameter> parameters = session.getSupportedParameters(object.getObjectId(), origin);
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        viewer.setInput(parameters.toArray());
                    }
                });
            }
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 27 with NXCSession

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

the class TestTransformationDlg method runScript.

/**
 * Run script
 */
private void runScript() {
    getButton(RUN).setEnabled(false);
    final String input = inputValue.getText();
    inputValue.getTextControl().setEditable(false);
    status.setText(Messages.get().TestTransformationDlg_Running);
    status.setImage(imageWaiting);
    // $NON-NLS-1$
    result.setText("");
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().TestTransformationDlg_JobTitle, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final TransformationTestResult r = session.testTransformationScript(nodeId, script, input);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    if ((getShell() == null) || getShell().isDisposed())
                        return;
                    if (r.success) {
                        status.setText(Messages.get().TestTransformationDlg_Success);
                        status.setImage(StatusDisplayInfo.getStatusImage(Severity.NORMAL));
                    } else {
                        status.setText(Messages.get().TestTransformationDlg_Failure);
                        status.setImage(StatusDisplayInfo.getStatusImage(Severity.CRITICAL));
                    }
                    result.setText(r.result);
                }
            });
        }

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

        /* (non-Javadoc)
			 * @see org.netxms.ui.eclipse.jobs.ConsoleJob#jobFinalize()
			 */
        @Override
        protected void jobFinalize() {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    if ((getShell() == null) || getShell().isDisposed())
                        return;
                    getButton(RUN).setEnabled(true);
                    inputValue.getTextControl().setEditable(true);
                    inputValue.getTextControl().setFocus();
                }
            });
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) TransformationTestResult(org.netxms.client.datacollection.TransformationTestResult)

Example 28 with NXCSession

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

the class ForceDciPoll method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    if (objects == null)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final Set<DCI> dciToPoll = objects;
    new ConsoleJob(Messages.get().ForceDciPoll_TaskName, part, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            monitor.beginTask(Messages.get(getDisplay()).ForceDciPoll_TaskName, dciToPoll.size());
            for (DCI d : dciToPoll) {
                session.forceDCIPoll(d.nodeId, d.dciId);
                monitor.worked(1);
            }
            monitor.done();
        }

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

Example 29 with NXCSession

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

the class DataCollectionObjectPropertyTester method test.

/* (non-Javadoc)
	 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
	 */
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if (!(receiver instanceof DataCollectionObject))
        return false;
    if (// $NON-NLS-1$
    property.equals("isClusterObject")) {
        NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        AbstractObject owner = session.findObjectById(((DataCollectionObject) receiver).getNodeId());
        if (owner instanceof Cluster)
            return true;
        if (owner instanceof AbstractNode) {
            for (AbstractObject o : owner.getParentsAsArray()) {
                if (o instanceof Cluster)
                    return true;
            }
        }
        return false;
    }
    if (// $NON-NLS-1$
    property.equals("isTemplateObject")) {
        NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        AbstractObject owner = session.findObjectById(((DataCollectionObject) receiver).getNodeId());
        return (owner instanceof Template);
    }
    return false;
}
Also used : NXCSession(org.netxms.client.NXCSession) AbstractNode(org.netxms.client.objects.AbstractNode) DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) AbstractObject(org.netxms.client.objects.AbstractObject) Cluster(org.netxms.client.objects.Cluster) Template(org.netxms.client.objects.Template)

Example 30 with NXCSession

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

the class CreateSnmpDci method run.

/**
 * @see IActionDelegate#run(IAction)
 */
public void run(IAction action) {
    if (objects.size() == 0)
        return;
    MibObject mibObject = MibCache.findObject(objects.get(0).getName(), false);
    String description = (mibObject != null) ? mibObject.getName() : objects.get(0).getName();
    if (objects.size() > 1)
        // $NON-NLS-1$
        description += " @@instance@@";
    final CreateSnmpDciDialog dlg = new CreateSnmpDciDialog(shell, description);
    if (dlg.open() != Window.OK)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final List<SnmpValue> values = new ArrayList<SnmpValue>(objects);
    // Get set of nodes
    final Set<AbstractNode> nodes = new HashSet<AbstractNode>();
    for (SnmpValue v : values) {
        AbstractNode node = (AbstractNode) session.findObjectById(v.getNodeId(), AbstractNode.class);
        if (node != null) {
            nodes.add(node);
        }
    }
    // Check what nodes requires DCI list lock
    final Map<Long, Boolean> lockRequired = new HashMap<Long, Boolean>(nodes.size());
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    for (AbstractNode n : nodes) {
        IViewReference ref = page.findViewReference(DataCollectionEditor.ID, Long.toString(n.getObjectId()));
        lockRequired.put(n.getObjectId(), !((ref != null) && (ref.getView(false) != null)));
    }
    new ConsoleJob(Messages.get().CreateSnmpDci_JobTitle, viewPart, Activator.PLUGIN_ID, null) {

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

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            monitor.beginTask(Messages.get(getDisplay()).CreateSnmpDci_TaskTitle, values.size());
            for (SnmpValue v : values) {
                // $NON-NLS-1$
                final String description = dlg.getDescription().replaceAll("@@instance@@", Long.toString(v.getObjectId().getIdFromPos(v.getObjectId().getLength() - 1)));
                createDci(session, v, description, dlg.getPollingInterval(), dlg.getRetentionTime(), dlg.getDeltaCalculation(), lockRequired);
                monitor.worked(1);
            }
            monitor.done();
        }
    }.start();
}
Also used : NXCSession(org.netxms.client.NXCSession) AbstractNode(org.netxms.client.objects.AbstractNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SnmpValue(org.netxms.client.snmp.SnmpValue) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) MibObject(org.netxms.client.snmp.MibObject) CreateSnmpDciDialog(org.netxms.ui.eclipse.datacollection.dialogs.CreateSnmpDciDialog) HashSet(java.util.HashSet)

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