Search in sources :

Example 21 with ConsoleJob

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

the class CreateInterfraceDci method run.

/**
 * @see IActionDelegate#run(IAction)
 */
public void run(IAction action) {
    final CreateInterfaceDciDialog dlg = new CreateInterfaceDciDialog(shell, (objects.size() == 1) ? objects.get(0) : null);
    if (dlg.open() == Window.OK) {
        final List<Interface> ifaces = new ArrayList<Interface>(objects);
        // Get set of nodes
        final Set<AbstractNode> nodes = new HashSet<AbstractNode>();
        for (Interface iface : ifaces) {
            AbstractNode node = iface.getParentNode();
            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)));
        }
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob(Messages.get().CreateInterfraceDci_JobTitle, viewPart, Activator.PLUGIN_ID, null) {

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

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                InterfaceDciInfo[] dciInfo = dlg.getDciInfo();
                monitor.beginTask(Messages.get(getDisplay()).CreateInterfraceDci_TaskName, ifaces.size() * dciInfo.length);
                for (int i = 0; i < ifaces.size(); i++) {
                    for (int j = 0; j < dciInfo.length; j++) {
                        if (dciInfo[j].enabled) {
                            createInterfaceDci(session, ifaces.get(i), j, dciInfo[j], dlg.getPollingInterval(), dlg.getRetentionTime(), ifaces.size() > 1, 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) CreateInterfaceDciDialog(org.netxms.ui.eclipse.datacollection.dialogs.CreateInterfaceDciDialog) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) Interface(org.netxms.client.objects.Interface) HashSet(java.util.HashSet)

Example 22 with ConsoleJob

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

the class RemoveTemplate method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
public void run(IAction action) {
    final ChildObjectListDialog dlg = new ChildObjectListDialog(shell, parentId, null);
    if (dlg.open() == Window.OK) {
        final DciRemoveConfirmationDialog dlg2 = new DciRemoveConfirmationDialog(shell);
        if (dlg2.open() == Window.OK) {
            final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
            new ConsoleJob(Messages.get().RemoveTemplate_JobTitle, viewPart, Activator.PLUGIN_ID, null) {

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

                @Override
                protected void runInternal(IProgressMonitor monitor) throws Exception {
                    List<AbstractObject> objects = dlg.getSelectedObjects();
                    for (int i = 0; i < objects.size(); i++) session.removeTemplate(parentId, objects.get(i).getObjectId(), dlg2.getRemoveFlag());
                }
            }.start();
        }
    }
}
Also used : DciRemoveConfirmationDialog(org.netxms.ui.eclipse.datacollection.dialogs.DciRemoveConfirmationDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ChildObjectListDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ChildObjectListDialog) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 23 with ConsoleJob

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

the class StartDataRecalculation 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;
    if (!MessageDialogHelper.openQuestion(part.getSite().getShell(), "Start Data Recalculation", "Collected values will be re-calculated using stored raw values and current transformation settings. Continue?"))
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final Set<DCI> dciToProcess = objects;
    new ConsoleJob("Start DCI data recalculation", part, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            monitor.beginTask("Start DCI data recalculation", dciToProcess.size());
            for (DCI d : dciToProcess) {
                session.recalculateDCIValues(d.nodeId, d.dciId);
                monitor.worked(1);
            }
            monitor.done();
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot initiate data recalculation";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 24 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob 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 25 with ConsoleJob

use of org.netxms.ui.eclipse.jobs.ConsoleJob 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)

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