/*
  * (non-Javadoc)
  *
  * @see
  * com.intel.stl.ui.monitor.tree.FastTreeUpater#compare(com.intel.stl.ui
  * .monitor.FVResourceNode, java.lang.Object)
  */
 @Override
 protected int compare(FVResourceNode node, Integer element) {
   String name1 = node.getName();
   NodeRecordBean node2 = nodeMap.get(element);
   String name2 = node2 == null ? null : node2.getNodeDesc();
   return TreeNodeFactory.comapreNodeName(name1, name2);
 }
  /*
   * (non-Javadoc)
   *
   * @see
   * com.intel.stl.ui.monitor.tree.TreeUpater#updateNode(com.intel.stl.ui.
   * monitor.FVResourceNode, com.intel.stl.ui.monitor.FVResourceNode,
   * com.intel.stl.ui.monitor.FVTreeModel)
   */
  @Override
  protected void updateNode(
      FVResourceNode node,
      FVResourceNode parent,
      List<ITreeMonitor> monitors,
      IProgressObserver observer) {
    NodeRecordBean bean = nodeMap.get(node.getId());
    if (bean == null) {
      log.warn("Couldn't update tree because no node " + node.getId() + " found");
      return;
    }

    Map<Integer, FVResourceNode> updated = new HashMap<Integer, FVResourceNode>();
    boolean hasStructureChange = false;
    int numPorts = bean.getNodeInfo().getNumPorts();
    if (node.getType() == TreeNodeType.SWITCH) {
      numPorts += 1; // count in internal port
    }
    int toUpdate = Math.min(numPorts, node.getModelChildCount());
    for (int i = 0; i < toUpdate; i++) {
      // update ports
      FVResourceNode port = node.getModelChildAt(i);
      boolean statusChanged = setPortStatus(node, port);
      if (statusChanged) {
        updated.put(i, port);
      }
    }
    if (toUpdate < node.getModelChildCount()) {
      // remove ports
      while (node.getModelChildCount() > toUpdate) {
        node.removeChild(toUpdate);
        if (!hasStructureChange) {
          hasStructureChange = true;
        }
      }
    } else if (toUpdate < numPorts) {
      // add ports
      if (node.getType() == TreeNodeType.SWITCH) {
        numPorts -= 1;
        toUpdate -= 1;
      }
      for (int i = toUpdate + 1; i <= numPorts; i++) {
        FVResourceNode port = new FVResourceNode(Integer.toString(i), TreeNodeType.ACTIVE_PORT, i);

        // If the port is in the hash set, make it active
        // otherwise make it inactive
        setPortStatus(node, port);
        node.addChild(port);
        if (!hasStructureChange) {
          hasStructureChange = true;
        }
      }
    }

    if (monitors == null) {
      return;
    }

    if (hasStructureChange) {
      fireStructureChanged(monitors, node);
    } else if (!updated.isEmpty()) {
      for (Integer childIndex : updated.keySet()) {
        int viewIndex = node.getViewIndex(childIndex);
        fireNodesUpdated(monitors, node, viewIndex, updated.get(childIndex));
      }
    }
  }