/** * follows the root by all its children to wrap the all up with all the extra info needed and adds * the tree to the matrix. * * @param currRoot - root to go over tree from * @param entitiesList - entities available * @param relationshipsList - relationship between the given entities * @param currRow - the current row in the matrix we are working on * @param rows - the matrix. */ private void builtTreeFromRoot( GXMoreThanNode currRoot, List<InternalNode> entitiesList, List<InternalRelationship> relationshipsList, List<GXMoreThanNode> currRow, List<List<GXMoreThanNode>> rows) { // this is the first node that comes from the currRoot // we'll use the mark to know where to continue laying out from GXMoreThanNode mark = null; List<InternalRelationship> relationshipsListCopy = new ArrayList<InternalRelationship>(relationshipsList); // Orders the children of the currRoot in the given row (the row under it) for (InternalRelationship rel : relationshipsListCopy) { if (currRoot.getNode().equals(rel.getSource())) { InternalNode destNode = rel.getDestination(); // if the destination node hasn't been laid out yet if (entitiesList.contains(destNode)) { // place it in the row (as in lay it out) GXMoreThanNode currNode = new GXMoreThanNode(destNode, currRoot.getNode()); currRoot.addChild(currNode); currRow.add(currNode); currNode.addedToRow(currRow); entitiesList.remove(destNode); // if this is the first node, save it as a mark. if (mark == null) { mark = currNode; } // remove the relationship since both of its ends have been laid out. relationshipsList.remove(rel); } } } // if new children have been added if (mark != null) { // Create a next row if necessary if (rows.size() - 1 <= rows.indexOf(currRow)) { rows.add(new ArrayList<GXMoreThanNode>()); } List<GXMoreThanNode> nextRow = rows.get(rows.indexOf(currRow) + 1); for (int i = currRow.indexOf(mark); i < currRow.size(); i++) { builtTreeFromRoot(currRow.get(i), entitiesList, relationshipsList, nextRow, rows); } } }