mVmsUpdateLock.lock();
boolean nodeChanged = false;
if (vmsNode != null) {
for (final Info info : treeMenuController.nodesToInfos(vmsNode.children())) {
final DomainInfo domainInfo = (DomainInfo) info;
if (domainNames.contains(domainInfo.toString())) {
/* keeping */
currentVMSVDIs.add(domainInfo);
domainNames.remove(domainInfo.toString());
domainInfo.updateParameters(); /* update old */
} else {
if (!domainInfo.getResource().isNew()) {
/* remove not existing vms */
nodesToRemove.add(domainInfo.getNode());
domainInfo.setNode(null);
nodeChanged = true;
}
}
}
}
treeMenuController.removeFromParent(nodesToRemove);
if (vmsNode == null) {
mVmsUpdateLock.unlock();
return;
}
for (final String domainName : domainNames) {
int i = 0;
for (final Info info : treeMenuController.nodesToInfos(vmsNode.children())) {
final DomainInfo domainInfo = (DomainInfo) info;
final String name = domainInfo.getName();
if (domainName != null && name != null && domainName.compareTo(domainInfo.getName()) < 0) {
break;
}
i++;
}
/* add new vms nodes */
final DomainInfo domainInfo = domainInfoProvider.get();
domainInfo.init(domainName, this);
currentVMSVDIs.add(domainInfo);
treeMenuController.createMenuItem(vmsNode, domainInfo, i);
domainInfo.updateParameters();
nodeChanged = true;
}
mVmsUpdateLock.unlock();
if (nodeChanged) {
treeMenuController.reloadNode(vmsNode, false);
}
for (final ServiceInfo si : getExistingServiceList(null)) {
final DomainInfo vmsvdi = si.connectWithVMS();
if (vmsvdi != null) {
/* keep the not connected ones.*/
currentVMSVDIs.remove(vmsvdi);
}
}
for (final DomainInfo vmsvdi : currentVMSVDIs) {
vmsvdi.setUsedByCRM(false);
}
final VMListInfo vmsi = (VMListInfo) vmsNode.getUserObject();
if (vmsi != null) {
vmsi.updateTable(VMListInfo.MAIN_TABLE);
}