use of org.netxms.ui.eclipse.datacollection.dialogs.CreateSnmpDciDialog 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();
}
Aggregations