Search in sources :

Example 1 with CreateInterfaceDciDialog

use of org.netxms.ui.eclipse.datacollection.dialogs.CreateInterfaceDciDialog 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)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IViewReference (org.eclipse.ui.IViewReference)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 NXCException (org.netxms.client.NXCException)1 NXCSession (org.netxms.client.NXCSession)1 AbstractNode (org.netxms.client.objects.AbstractNode)1 Interface (org.netxms.client.objects.Interface)1 CreateInterfaceDciDialog (org.netxms.ui.eclipse.datacollection.dialogs.CreateInterfaceDciDialog)1 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)1