@Override
 public Object getParentElement(final Object element) {
   NodeElement nodeElement = (NodeElement) element;
   return nodeElement.getForcedParent() != null
       ? nodeElement.getForcedParent()
       : myChild2Parent.get(nodeElement);
 }
    @Nullable
    private Node remove(final NodeElement name, boolean removeRefToParent) {
      final Iterator<Node> kids = myChildElements.iterator();
      Node removed = null;
      while (kids.hasNext()) {
        Node each = kids.next();
        if (name.equals(each.myElement)) {
          kids.remove();
          removed = each;
          break;
        }
      }

      if (removeRefToParent) {
        myStructure.myChild2Parent.remove(name);
      }

      return removed;
    }
  @Nullable
  private DefaultMutableTreeNode findNode(
      DefaultMutableTreeNode treeNode, NodeElement toFind, boolean shouldBeSelected) {
    final Object object = treeNode.getUserObject();
    Assert.assertNotNull(object);
    if (!(object instanceof NodeDescriptor)) return null;
    final NodeElement element = (NodeElement) ((NodeDescriptor) object).getElement();
    if (toFind.equals(element)) return treeNode;

    for (int i = 0; i < treeNode.getChildCount(); i++) {
      final DefaultMutableTreeNode result =
          findNode((DefaultMutableTreeNode) treeNode.getChildAt(i), toFind, shouldBeSelected);
      if (result != null) {
        if (shouldBeSelected) {
          final TreePath path = new TreePath(result.getPath());
          Assert.assertTrue("Path should be selected: " + path, myTree.isPathSelected(path));
        }
        return result;
      }
    }

    return null;
  }
Beispiel #4
0
  public static void printType(NodeType type) {
    if (type instanceof NodeSynonym) {
      System.out.println("NodeSynonym: " + ((NodeSynonym) type).getID());
    } // System.out.println("NodeSynonym: " + ((NodeSynonym)type).getType());
    else if (type instanceof NodePLType) {
      System.out.println("PLType: " + ((NodePLType) type).getType());
    } else if (type instanceof NodePointer) {
      System.out.println("Puntero a");
      System.out.print("  ");
      printType(((NodePointer) type).getType());
    } else if (type instanceof NodeArray) {
      System.out.print("Arreglo de tamaño " + ((NodeArray) type).getSize() + " de tipo: ");
      printType(((NodeArray) type).getType());
    } else if (type instanceof NodeStructure) {
      NodeStructure structure = (NodeStructure) type;
      // List<NodeElement>	elements =	record.getElements(); CHANGE
      List<NodeElement> elements = structure.getElements();
      Iterator<NodeElement> iter = elements.iterator();

      // System.out.println("Estructura: " + "Nombre: " + record.getName()); CHANGE
      System.out.println("Estructura: " + "Nombre: " + structure.getName());

      int i = 1;
      NodeElement element;

      while (iter.hasNext()) {
        element = iter.next();

        System.out.println("Campo " + i + ": ");
        i++;

        // System.out.println("Nombre: " + (element.getName())); CHANGE
        System.out.println("Nombre: " + (element.getID()));
        System.out.print("Tipo: ");
        printType(element.getType());
      }
    } else if (type instanceof NodeList) {
      NodeList list = (NodeList) type;
      // List<NodeField>		fields	=	list.getFields(); CHANGE
      List<NodeElement> fields = list.getFields();
      // Iterator<NodeField> iter	= fields.iterator(); CHANGE
      Iterator<NodeElement> iter = fields.iterator();

      System.out.println("Lista");
      System.out.println("Nombre: " + list.getName());
      System.out.println("LinkType: " + list.getLinkType());
      System.out.println("LinkNexName: " + list.getLinkNextName());

      if (list.getLinkPrevName() != null) {
        System.out.println("LinkPrevName: " + list.getLinkPrevName());
      }

      int i = 1;

      NodeElement field;
      while (iter.hasNext()) {
        field = iter.next();
        System.out.println("Campo " + i + ":");
        i++;
        // System.out.println("Nombre: " + (field.getName())); CHANGE
        System.out.println("Nombre: " + (field.getID()));
        System.out.print("Tipo: ");
        printType(field.getType());
      }
      // if (list.getMemalloc() != null ) CHANGE
      if (list.getMemAlloc() != null) {
        System.out.println("MemallocFunction: ");
        // System.out.println(list.getMemalloc()); CHANGE
        System.out.println(list.getMemAlloc());
      }
    } else if (type instanceof NodeFile) {
      NodeFile file = (NodeFile) type;

      System.out.println("Archivo");
      System.out.println("Nombre: " + file.getName());
      System.out.println("Ruta: " + file.getPath());
      System.out.println("Delimitador: " + file.getDelimiter());

      if (file.getEof() != null) {
        System.out.println("EOF: " + file.getEof());
      }
      if (file.getEol() != null) {
        System.out.println("EOL: " + file.getEol());
      }
      if (file.getStructure() != null) {
        System.out.println("Estructura: " + file.getStructure());
      }
    } else if (type instanceof NodeDB) {
      NodeDB db = (NodeDB) type;
      List<NodeDBColumn> regs = db.getColumns();
      Iterator<NodeDBColumn> iter = regs.iterator();

      System.out.println("Base de Datos");
      System.out.println("DBMS: " + db.getDBMSID());
      // System.out.println("connectionID "		+ db.getConnID()); CHANGE
      System.out.println("connectionID " + db.getConnectionID());

      // System.out.println("Table name: "		+ db.getTable()); CHANGE
      System.out.println("Table name: " + db.getTableName());
      System.out.println("Registros:");

      int i = 1;

      while (iter.hasNext()) {
        NodeDBColumn rec = iter.next();
        System.out.println(
            "Registro " + i + ": " + rec.getColType() + " tipo: " + rec.getColType());
        i++;
      }
    }
  }
    public void delete() {
      final NodeElement parent = (NodeElement) myStructure.getParentElement(myElement);
      Assert.assertNotNull(myElement.toString(), parent);

      myStructure.getNodeFor(parent).remove(myElement, true);
    }
 @Override
 public String toString() {
   return myElement.toString();
 }