Esempio n. 1
0
  private void compactNodes(T node) {
    for (int i = 0; i < node.getChildCount(); i++) {
      MPSTreeNode child = (MPSTreeNode) node.getChildAt(i);
      if (myBuilder.isNamespaceNode(child)) {
        compactNodes((T) child);
      }
    }

    if (node.getParent() != null
        && // skip root
        node.getChildCount() == 1
        && myBuilder.isNamespaceNode((MPSTreeNode) node.getChildAt(0))) {
      T child = (T) node.getChildAt(0);
      myBuilder.setName(node, myBuilder.getName(node) + "." + myBuilder.getName(child));

      Enumeration children = child.children();
      List<MPSTreeNode> oldChildren = new ArrayList<MPSTreeNode>();
      while (children.hasMoreElements()) {
        oldChildren.add((MPSTreeNode) children.nextElement());
      }
      for (MPSTreeNode c : oldChildren) {
        child.remove(c);
        node.add(c);
      }

      node.remove(child);
    }
  }
Esempio n. 2
0
  public void fillNode(MPSTreeNode root) {
    sortTree(myRootNamespace);
    compactNodes(myRootNamespace);

    Enumeration children = myRootNamespace.children();
    List<MPSTreeNode> oldChildren = new ArrayList<MPSTreeNode>();
    while (children.hasMoreElements()) {
      oldChildren.add((MPSTreeNode) children.nextElement());
    }
    for (MPSTreeNode node : oldChildren) {
      myRootNamespace.remove(node);
      root.add(node);
    }
  }