/**
   * Builds up the tree showing the layers
   *
   * @param mapModel The mapModel containing the layerTree
   */
  private void buildTree(MapModel mapModel) {
    treeGrid.setWidth100();
    treeGrid.setHeight100();
    treeGrid.setShowHeader(false);
    tree = new RefreshableTree();
    final TreeNode nodeRoot = new TreeNode("ROOT");
    tree.setRoot(nodeRoot); // invisible ROOT node (ROOT node is required)

    ClientLayerTreeInfo layerTreeInfo = mapModel.getMapInfo().getLayerTree();
    if (layerTreeInfo != null) {
      ClientLayerTreeNodeInfo treeNode = layerTreeInfo.getTreeNode();
      processNode(treeNode, nodeRoot, tree, mapModel, false);
    }

    treeGrid.setData(tree);
    treeGrid.addLeafClickHandler(this);
    treeGrid.addFolderClickHandler(this);

    // -- add event listeners to layers
    for (Layer<?> layer : mapModel.getLayers()) {
      registrations.add(
          layer.addLayerChangedHandler(
              new LayerChangedHandler() {
                public void onLabelChange(LayerLabeledEvent event) {}

                public void onVisibleChange(LayerShownEvent event) {
                  for (TreeNode node : tree.getAllNodes()) {
                    if (node.getName().equals(event.getLayer().getLabel())) {
                      if (node instanceof LayerTreeTreeNode) {
                        ((LayerTreeTreeNode) node).updateIcon();
                      }
                    }
                  }
                }
              }));
    }
  }
 /**
  * Constructor creates a TreeNode with layer.getLabel as label.
  *
  * @param tree tree for node
  * @param layer The layer object
  */
 public LayerTreeTreeNode(RefreshableTree tree, Layer<?> layer) {
   super(layer.getLabel());
   this.layer = layer;
   this.tree = tree;
   updateIcon();
 }