/*
   * (non-Javadoc)
   * @see org.ow2.proactive_grid_cloud_portal.rm.client.Listeners.NodeSelectedListener#nodeSelected(org.ow2.proactive_grid_cloud_portal.rm.client.NodeSource.Host.Node)
   */
  public void nodeSelected(Node node) {
    DetailViewerRecord dv = new DetailViewerRecord();

    dv.setAttribute("nodeUrl", node.getNodeUrl());
    dv.setAttribute(
        "nodeState",
        node.getNodeState().toString() + " since " + JSUtil.getTime(node.getTimeStamp()));
    dv.setAttribute("nodeProvider", node.getNodeProvider());
    dv.setAttribute("nodeOwner", node.getNodeOwner());
    dv.setAttribute("hostName", node.getHostName());
    dv.setAttribute("sourceName", node.getSourceName());
    dv.setAttribute("vmName", node.getVmName());
    dv.setAttribute("description", "<pre>" + node.getDescription() + "</pre>");

    this.nodeDetails.setData(new DetailViewerRecord[] {dv});
    this.nodeLabel.setIcon(node.getNodeState().getIcon());

    this.label.hide();
    this.nsCanvas.hide();
    this.hostCanvas.hide();
    this.nodeCanvas.show();

    this.selNode = node;
    this.selHost = null;
    this.selNS = null;
  }
  public void nodesUpdated(Map<String, NodeSource> nodes) {
    if (selNode != null) {
      for (NodeSource ns : nodes.values()) {
        if (selNode.getSourceName().equals(ns.getSourceName())) {

          Node depl = ns.getDeploying().get(selNode.getNodeUrl());
          if (depl != null) {
            nodeSelected(depl);
            return;
          }

          for (Host h : ns.getHosts().values()) {
            if (selNode.getHostName().equals(h.getHostName())) {

              for (Node n : h.getNodes().values()) {
                if (n.getNodeUrl().equals(selNode.getNodeUrl())) {
                  nodeSelected(n);
                  return;
                }
              }
            }
          }
        }
      }
    } else if (selHost != null) {
      for (NodeSource ns : nodes.values()) {
        if (ns.getSourceName().equals(selHost.getSourceName())) {

          for (Host h : ns.getHosts().values()) {
            if (selHost.getHostName().equals(h.getHostName())) {
              hostSelected(h);
              return;
            }
          }
        }
      }
    } else if (selNS != null) {
      for (NodeSource ns : nodes.values()) {
        if (ns.getSourceName().equals(selNS.getSourceName())) {
          nodeSourceSelected(ns);
          return;
        }
      }
    }

    nodeUnselected();
  }
  /*
   * (non-Javadoc)
   * @see org.ow2.proactive_grid_cloud_portal.rm.client.Listeners.NodeSelectedListener#nodeSelected(org.ow2.proactive_grid_cloud_portal.rm.client.NodeSource.Host.Node)
   */
  public void nodeSelected(Node node) {

    this.nodeLabel.setIcon(node.getNodeState().getIcon());

    this.label.hide();
    this.hostCanvas.hide();

    this.nodeLabel.setContents("<h3>" + node.getNodeUrl() + "</h3>");
    this.hostMonitoring.close();
    this.nodeMonitoring.close();
    this.nodeMonitoring.init(node);
    this.nodeCanvas.show();
  }